From 4b9db0cc55192f9399010ce7ae6e8d9744fe3463 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 2 Apr 2021 10:08:29 +0200 Subject: [PATCH] Rename ui.advance_cursor to ui.add_space --- CHANGELOG.md | 1 + egui/src/containers/window.rs | 4 ++-- egui/src/context.rs | 4 ++-- egui/src/introspection.rs | 6 ++--- egui/src/style.rs | 7 +++++- egui/src/ui.rs | 30 +++++++++++++----------- egui_demo_lib/src/apps/demo/plot_demo.rs | 2 +- egui_demo_lib/src/apps/demo/sliders.rs | 8 +++---- egui_demo_lib/src/wrap_app.rs | 2 +- 9 files changed, 36 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e82ad09..8bb700f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ NOTE: `eframe`, `egui_web` and `egui_glium` has their own changelogs! * Add `TextEdit::password` to hide input characters. ### Changed 🔧 +* `ui.advance_cursor` is now called `ui.add_space`. * `kb_focus` is now just called `focus`. ### Fixed 🐛 diff --git a/egui/src/containers/window.rs b/egui/src/containers/window.rs index 1512f0ed..117f8154 100644 --- a/egui/src/containers/window.rs +++ b/egui/src/containers/window.rs @@ -331,7 +331,7 @@ impl<'open> Window<'open> { .add_contents(&mut frame.content_ui, collapsing_id, |ui| { resize.show(ui, |ui| { if title_bar.is_some() { - ui.advance_cursor(title_content_spacing); + ui.add_space(title_content_spacing); } if let Some(scroll) = scroll { @@ -698,7 +698,7 @@ fn show_title_bar( let pad = (height - button_size.y) / 2.0; // calculated so that the icon is on the diagonal (if window padding is symmetrical) if collapsible { - ui.advance_cursor(pad); + ui.add_space(pad); let (_id, rect) = ui.allocate_space(button_size); let collapse_button_response = ui.interact(rect, collapsing_id, Sense::click()); diff --git a/egui/src/context.rs b/egui/src/context.rs index 229dd1ac..cd37e9eb 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -791,14 +791,14 @@ impl Context { .unwrap_or_default() )) .on_hover_text("Is egui currently listening for text input?"); - ui.advance_cursor(16.0); + ui.add_space(16.0); ui.label(format!( "There are {} text galleys in the layout cache", self.fonts().num_galleys_in_cache() )) .on_hover_text("This is approximately the number of text strings on screen"); - ui.advance_cursor(16.0); + ui.add_space(16.0); CollapsingHeader::new("📥 Input") .default_open(false) diff --git a/egui/src/introspection.rs b/egui/src/introspection.rs index 70464d8d..8c490bb4 100644 --- a/egui/src/introspection.rs +++ b/egui/src/introspection.rs @@ -79,7 +79,7 @@ impl Widget for &epaint::stats::PaintStats { "egui generates intermediate level shapes like circles and text. \ These are later tessellated into triangles.", ); - ui.advance_cursor(10.0); + ui.add_space(10.0); ui.style_mut().body_text_style = TextStyle::Monospace; @@ -100,14 +100,14 @@ impl Widget for &epaint::stats::PaintStats { label(ui, shape_path, "paths"); label(ui, shape_mesh, "nested meshes"); label(ui, shape_vec, "nested shapes"); - ui.advance_cursor(10.0); + ui.add_space(10.0); ui.label("Tessellated:"); label(ui, clipped_meshes, "clipped_meshes") .on_hover_text("Number of separate clip rectangles"); label(ui, vertices, "vertices"); label(ui, indices, "indices").on_hover_text("Three 32-bit indices per triangles"); - ui.advance_cursor(10.0); + ui.add_space(10.0); // ui.label("Total:"); // ui.label(self.total().format("")); diff --git a/egui/src/style.rs b/egui/src/style.rs index 2bec3fe2..7f8c7dfa 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -62,7 +62,12 @@ impl Style { #[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "persistence", serde(default))] pub struct Spacing { - /// Horizontal and vertical spacing between widgets + /// Horizontal and vertical spacing between widgets. + /// + /// To add extra space between widgets, use [`Ui::add_space`]. + /// + /// `item_spacing` is inserted _after_ adding a widget, so to increase the spacing between + /// widgets `A` and `B` you need to change `item_spacing` before adding `A`. pub item_spacing: Vec2, /// Horizontal and vertical padding within a window frame. diff --git a/egui/src/ui.rs b/egui/src/ui.rs index 1db73f4f..48c6ab33 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -510,19 +510,6 @@ impl Ui { pub fn hovered(&self, rect: Rect) -> bool { self.interact(rect, self.id, Sense::hover()).hovered } - - // ------------------------------------------------------------------------ - // Stuff that moves the cursor, i.e. allocates space in this ui! - - /// Advance the cursor (where the next widget is put) by this many points. - /// - /// The direction is dependent on the layout. - /// This is useful for creating some extra space between widgets. - /// - /// [`Self::min_rect`] will expand to contain the cursor. - pub fn advance_cursor(&mut self, amount: f32) { - self.placer.advance_cursor(amount); - } } /// # Allocating space: where do I put my widgets? @@ -833,6 +820,21 @@ impl Ui { .inner } + /// Add extra space before the next widget. + /// + /// The direction is dependent on the layout. + /// This will be in addition to the [`Spacing::item_spacing`}. + /// + /// [`Self::min_rect`] will expand to contain the space. + pub fn add_space(&mut self, amount: f32) { + self.placer.advance_cursor(amount); + } + + #[deprecated = "Use add_space instead"] + pub fn advance_cursor(&mut self, amount: f32) { + self.add_space(amount); + } + /// Shortcut for `add(Label::new(text))` /// /// See also [`Label`]. @@ -1214,7 +1216,7 @@ impl Ui { let end_with_horizontal_line = true; if end_with_horizontal_line { - child_ui.advance_cursor(4.0); + child_ui.add_space(4.0); } // draw a faint line on the left to mark the indented section diff --git a/egui_demo_lib/src/apps/demo/plot_demo.rs b/egui_demo_lib/src/apps/demo/plot_demo.rs index b9cc6b73..1cb8a3b5 100644 --- a/egui_demo_lib/src/apps/demo/plot_demo.rs +++ b/egui_demo_lib/src/apps/demo/plot_demo.rs @@ -91,7 +91,7 @@ impl PlotDemo { ui.vertical(|ui| { ui.style_mut().wrap = Some(false); ui.checkbox(animate, "animate"); - ui.advance_cursor(8.0); + ui.add_space(8.0); ui.checkbox(square, "square view"); ui.checkbox(proportional, "proportional data axes"); }); diff --git a/egui_demo_lib/src/apps/demo/sliders.rs b/egui_demo_lib/src/apps/demo/sliders.rs index e0722615..195a45ea 100644 --- a/egui_demo_lib/src/apps/demo/sliders.rs +++ b/egui_demo_lib/src/apps/demo/sliders.rs @@ -122,21 +122,21 @@ impl super::View for Sliders { ui.radio_value(integer, false, "f64"); }); ui.label("(f32, usize etc are also possible)"); - ui.advance_cursor(8.0); + ui.add_space(8.0); ui.checkbox(logarithmic, "Logarithmic"); ui.label("Logarithmic sliders are great for when you want to span a huge range, i.e. from zero to a million."); ui.label("Logarithmic sliders can include infinity and zero."); - ui.advance_cursor(8.0); + ui.add_space(8.0); ui.checkbox(clamp_to_range, "Clamp to range"); ui.label("If true, the slider will clamp incoming and outgoing values to the given range."); ui.label("If false, the slider can shows values outside its range, and you can manually enter values outside the range."); - ui.advance_cursor(8.0); + ui.add_space(8.0); ui.checkbox(smart_aim, "Smart Aim"); ui.label("Smart Aim will guide you towards round values when you drag the slider so you you are more likely to hit 250 than 247.23"); - ui.advance_cursor(8.0); + ui.add_space(8.0); ui.vertical_centered(|ui| { egui::reset_button(ui, self); diff --git a/egui_demo_lib/src/wrap_app.rs b/egui_demo_lib/src/wrap_app.rs index d9d8f3af..93b28bdd 100644 --- a/egui_demo_lib/src/wrap_app.rs +++ b/egui_demo_lib/src/wrap_app.rs @@ -327,7 +327,7 @@ impl BackendPanel { These are emitted when you switch selected widget with tab, \ and can be hooked up to a screen reader on supported platforms.", ); - ui.advance_cursor(8.0); + ui.add_space(8.0); for event in &self.output_event_history { ui.label(format!("{:?}", event)); }