mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
Misc cleanup (#3935)
* Improve docstring * Nicer welcome gif in README * Misc cleanup
This commit is contained in:
@@ -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}"));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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()]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user