Misc cleanup (#3935)

* Improve docstring
* Nicer welcome gif in README
* Misc cleanup
This commit is contained in:
Emil Ernerfeldt 2024-02-01 17:09:35 +01:00 committed by GitHub
parent 1db291721f
commit 67b796faee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 32 additions and 33 deletions

View File

@ -36,7 +36,7 @@ ui.horizontal(|ui| {
ui.text_edit_singleline(&mut name);
});
ui.add(egui::Slider::new(&mut age, 0..=120).text("age"));
if ui.button("Click each year").clicked() {
if ui.button("Increment").clicked() {
age += 1;
}
ui.label(format!("Hello '{name}', age {age}"));
@ -376,21 +376,21 @@ The library was originally called "Emigui", but was renamed to "egui" in 2020.
## Credits
egui author and maintainer: Emil Ernerfeldt [(@emilk](https://github.com/emilk)).
egui author and maintainer: Emil Ernerfeldt ([@emilk](https://github.com/emilk)).
Notable contributions by:
* [@n2](https://github.com/n2): [Mobile web input and IME support](https://github.com/emilk/egui/pull/253).
* [@optozorax](https://github.com/optozorax): [Arbitrary widget data storage](https://github.com/emilk/egui/pull/257).
* [@quadruple-output](https://github.com/quadruple-output): [Multitouch](https://github.com/emilk/egui/pull/306).
* [@EmbersArc](https://github.com/EmbersArc): [Plots](https://github.com/emilk/egui/pulls?q=+is%3Apr+author%3AEmbersArc).
* [@AsmPrgmC3](https://github.com/AsmPrgmC3): [Proper sRGBA blending for web](https://github.com/emilk/egui/pull/650).
* [@AlexApps99](https://github.com/AlexApps99): [`egui_glow`](https://github.com/emilk/egui/pull/685).
* [@mankinskin](https://github.com/mankinskin): [Context menus](https://github.com/emilk/egui/pull/543).
* [@t18b219k](https://github.com/t18b219k): [Port glow painter to web](https://github.com/emilk/egui/pull/868).
* [@danielkeller](https://github.com/danielkeller): [`Context` refactor](https://github.com/emilk/egui/pull/1050).
* [@MaximOsipenko](https://github.com/MaximOsipenko): [`Context` lock refactor](https://github.com/emilk/egui/pull/2625).
* [@mwcampbell](https://github.com/mwcampbell): [AccessKit](https://github.com/AccessKit/accesskit) [integration](https://github.com/emilk/egui/pull/2294).
* [@n2](https://github.com/n2): [Mobile web input and IME support](https://github.com/emilk/egui/pull/253)
* [@optozorax](https://github.com/optozorax): [Arbitrary widget data storage](https://github.com/emilk/egui/pull/257)
* [@quadruple-output](https://github.com/quadruple-output): [Multitouch](https://github.com/emilk/egui/pull/306)
* [@EmbersArc](https://github.com/EmbersArc): [Plots](https://github.com/emilk/egui/pulls?q=+is%3Apr+author%3AEmbersArc)
* [@AsmPrgmC3](https://github.com/AsmPrgmC3): [Proper sRGBA blending for web](https://github.com/emilk/egui/pull/650)
* [@AlexApps99](https://github.com/AlexApps99): [`egui_glow`](https://github.com/emilk/egui/pull/685)
* [@mankinskin](https://github.com/mankinskin): [Context menus](https://github.com/emilk/egui/pull/543)
* [@t18b219k](https://github.com/t18b219k): [Port glow painter to web](https://github.com/emilk/egui/pull/868)
* [@danielkeller](https://github.com/danielkeller): [`Context` refactor](https://github.com/emilk/egui/pull/1050)
* [@MaximOsipenko](https://github.com/MaximOsipenko): [`Context` lock refactor](https://github.com/emilk/egui/pull/2625)
* [@mwcampbell](https://github.com/mwcampbell): [AccessKit](https://github.com/AccessKit/accesskit) [integration](https://github.com/emilk/egui/pull/2294)
* [@hasenbanck](https://github.com/hasenbanck), [@s-nie](https://github.com/s-nie), [@Wumpf](https://github.com/Wumpf): [`egui-wgpu`](https://github.com/emilk/egui/tree/master/crates/egui-wgpu)
* [@jprochazk](https://github.com/jprochazk): [egui image API](https://github.com/emilk/egui/issues/3291)
* And [many more](https://github.com/emilk/egui/graphs/contributors?type=a).

View File

@ -293,7 +293,7 @@ pub fn run_native(
/// .labelled_by(name_label.id);
/// });
/// ui.add(egui::Slider::new(&mut age, 0..=120).text("age"));
/// if ui.button("Click each year").clicked() {
/// if ui.button("Increment").clicked() {
/// age += 1;
/// }
/// ui.label(format!("Hello '{name}', age {age}"));

View File

@ -814,7 +814,7 @@ impl Renderer {
};
if index_count > 0 {
crate::profile_scope!("indices");
crate::profile_scope!("indices", index_count.to_string());
self.index_buffer.slices.clear();
let required_index_buffer_size = (std::mem::size_of::<u32>() * index_count) as u64;
@ -848,7 +848,7 @@ impl Renderer {
}
}
if vertex_count > 0 {
crate::profile_scope!("vertices");
crate::profile_scope!("vertices", vertex_count.to_string());
self.vertex_buffer.slices.clear();
let required_vertex_buffer_size = (std::mem::size_of::<Vertex>() * vertex_count) as u64;

View File

@ -455,7 +455,7 @@ impl ScrollStyle {
pub fn thin() -> Self {
Self {
floating: true,
bar_width: 12.0,
bar_width: 10.0,
floating_allocated_width: 6.0,
foreground_color: false,
@ -479,7 +479,7 @@ impl ScrollStyle {
pub fn floating() -> Self {
Self {
floating: true,
bar_width: 12.0,
bar_width: 10.0,
foreground_color: true,
floating_allocated_width: 0.0,
dormant_background_opacity: 0.0,

View File

@ -30,6 +30,7 @@ use crate::{
/// ```
pub struct Ui {
/// ID of this ui.
///
/// Generated based on id of parent ui together with
/// another source of child identity (e.g. window title).
/// Acts like a namespace for child uis.
@ -38,6 +39,7 @@ pub struct Ui {
id: Id,
/// This is used to create a unique interact ID for some widgets.
///
/// This value is based on where in the hierarchy of widgets this Ui is in,
/// and the value is increment with each added child widget.
/// This works as an Id source only as long as new widgets aren't added or removed.
@ -99,7 +101,6 @@ impl Ui {
crate::egui_assert!(!max_rect.any_nan());
let next_auto_id_source = Id::new(self.next_auto_id_source).with("child").value();
self.next_auto_id_source = self.next_auto_id_source.wrapping_add(1);
let menu_state = self.menu_state();
Ui {
id: self.id.with(id_source),
next_auto_id_source,
@ -107,7 +108,7 @@ impl Ui {
style: self.style.clone(),
placer: Placer::new(max_rect, layout),
enabled: self.enabled,
menu_state,
menu_state: self.menu_state.clone(),
}
}
@ -2232,10 +2233,6 @@ impl Ui {
self.menu_state = None;
}
pub(crate) fn menu_state(&self) -> Option<Arc<RwLock<MenuState>>> {
self.menu_state.clone()
}
pub(crate) fn set_menu_state(&mut self, menu_state: Option<Arc<RwLock<MenuState>>>) {
self.menu_state = menu_state;
}

View File

@ -79,6 +79,8 @@ impl<'a> DragValue<'a> {
}
/// How much the value changes when dragged one point (logical pixel).
///
/// Should be finite and greater than zero.
#[inline]
pub fn speed(mut self, speed: impl Into<f64>) -> Self {
self.speed = speed.into();

View File

@ -45,11 +45,11 @@ impl CodeExample {
show_code(
ui,
r#"
if ui.button("Click each year").clicked() {
if ui.button("Increment").clicked() {
self.age += 1;
}"#,
);
if ui.button("Click each year").clicked() {
if ui.button("Increment").clicked() {
self.age += 1;
}
ui.end_row();

View File

@ -359,22 +359,22 @@ impl PlotTransform {
rect
}
/// delta position / delta value
/// delta position / delta value = how many ui points per step in the X axis in "plot space"
pub fn dpos_dvalue_x(&self) -> f64 {
self.frame.width() as f64 / self.bounds.width()
}
/// delta position / delta value
/// delta position / delta value = how many ui points per step in the Y axis in "plot space"
pub fn dpos_dvalue_y(&self) -> f64 {
-self.frame.height() as f64 / self.bounds.height() // negated y axis!
}
/// delta position / delta value
/// delta position / delta value = how many ui points per step in "plot space"
pub fn dpos_dvalue(&self) -> [f64; 2] {
[self.dpos_dvalue_x(), self.dpos_dvalue_y()]
}
/// delta value / delta position
/// delta value / delta position = how much ground do we cover in "plot space" per ui point?
pub fn dvalue_dpos(&self) -> [f64; 2] {
[1.0 / self.dpos_dvalue_x(), 1.0 / self.dpos_dvalue_y()]
}

View File

@ -44,7 +44,7 @@ impl eframe::App for MyApp {
.labelled_by(name_label.id);
});
ui.add(egui::Slider::new(&mut self.age, 0..=120).text("age"));
if ui.button("Click each year").clicked() {
if ui.button("Increment").clicked() {
self.age += 1;
}
ui.label(format!("Hello '{}', age {}", self.name, self.age));

View File

@ -49,7 +49,7 @@ impl ThreadState {
ui.text_edit_singleline(&mut self.name);
});
ui.add(egui::Slider::new(&mut self.age, 0..=120).text("age"));
if ui.button("Click each year").clicked() {
if ui.button("Increment").clicked() {
self.age += 1;
}
ui.label(format!("Hello '{}', age {}", self.name, self.age));

View File

@ -23,7 +23,7 @@ fn main() -> Result<(), eframe::Error> {
.labelled_by(name_label.id);
});
ui.add(egui::Slider::new(&mut age, 0..=120).text("age"));
if ui.button("Click each year").clicked() {
if ui.button("Increment").clicked() {
age += 1;
}
ui.label(format!("Hello '{name}', age {age}"));

Binary file not shown.

Before

Width:  |  Height:  |  Size: 123 KiB

After

Width:  |  Height:  |  Size: 92 KiB