Rename ui.advance_cursor to ui.add_space

This commit is contained in:
Emil Ernerfeldt 2021-04-02 10:08:29 +02:00
parent d848b2a664
commit 4b9db0cc55
9 changed files with 36 additions and 28 deletions

View file

@ -22,6 +22,7 @@ NOTE: `eframe`, `egui_web` and `egui_glium` has their own changelogs!
* Add `TextEdit::password` to hide input characters. * Add `TextEdit::password` to hide input characters.
### Changed 🔧 ### Changed 🔧
* `ui.advance_cursor` is now called `ui.add_space`.
* `kb_focus` is now just called `focus`. * `kb_focus` is now just called `focus`.
### Fixed 🐛 ### Fixed 🐛

View file

@ -331,7 +331,7 @@ impl<'open> Window<'open> {
.add_contents(&mut frame.content_ui, collapsing_id, |ui| { .add_contents(&mut frame.content_ui, collapsing_id, |ui| {
resize.show(ui, |ui| { resize.show(ui, |ui| {
if title_bar.is_some() { if title_bar.is_some() {
ui.advance_cursor(title_content_spacing); ui.add_space(title_content_spacing);
} }
if let Some(scroll) = scroll { 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) let pad = (height - button_size.y) / 2.0; // calculated so that the icon is on the diagonal (if window padding is symmetrical)
if collapsible { if collapsible {
ui.advance_cursor(pad); ui.add_space(pad);
let (_id, rect) = ui.allocate_space(button_size); let (_id, rect) = ui.allocate_space(button_size);
let collapse_button_response = ui.interact(rect, collapsing_id, Sense::click()); let collapse_button_response = ui.interact(rect, collapsing_id, Sense::click());

View file

@ -791,14 +791,14 @@ impl Context {
.unwrap_or_default() .unwrap_or_default()
)) ))
.on_hover_text("Is egui currently listening for text input?"); .on_hover_text("Is egui currently listening for text input?");
ui.advance_cursor(16.0); ui.add_space(16.0);
ui.label(format!( ui.label(format!(
"There are {} text galleys in the layout cache", "There are {} text galleys in the layout cache",
self.fonts().num_galleys_in_cache() self.fonts().num_galleys_in_cache()
)) ))
.on_hover_text("This is approximately the number of text strings on screen"); .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") CollapsingHeader::new("📥 Input")
.default_open(false) .default_open(false)

View file

@ -79,7 +79,7 @@ impl Widget for &epaint::stats::PaintStats {
"egui generates intermediate level shapes like circles and text. \ "egui generates intermediate level shapes like circles and text. \
These are later tessellated into triangles.", These are later tessellated into triangles.",
); );
ui.advance_cursor(10.0); ui.add_space(10.0);
ui.style_mut().body_text_style = TextStyle::Monospace; 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_path, "paths");
label(ui, shape_mesh, "nested meshes"); label(ui, shape_mesh, "nested meshes");
label(ui, shape_vec, "nested shapes"); label(ui, shape_vec, "nested shapes");
ui.advance_cursor(10.0); ui.add_space(10.0);
ui.label("Tessellated:"); ui.label("Tessellated:");
label(ui, clipped_meshes, "clipped_meshes") label(ui, clipped_meshes, "clipped_meshes")
.on_hover_text("Number of separate clip rectangles"); .on_hover_text("Number of separate clip rectangles");
label(ui, vertices, "vertices"); label(ui, vertices, "vertices");
label(ui, indices, "indices").on_hover_text("Three 32-bit indices per triangles"); 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("Total:");
// ui.label(self.total().format("")); // ui.label(self.total().format(""));

View file

@ -62,7 +62,12 @@ impl Style {
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "persistence", serde(default))] #[cfg_attr(feature = "persistence", serde(default))]
pub struct Spacing { 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, pub item_spacing: Vec2,
/// Horizontal and vertical padding within a window frame. /// Horizontal and vertical padding within a window frame.

View file

@ -510,19 +510,6 @@ impl Ui {
pub fn hovered(&self, rect: Rect) -> bool { pub fn hovered(&self, rect: Rect) -> bool {
self.interact(rect, self.id, Sense::hover()).hovered 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? /// # Allocating space: where do I put my widgets?
@ -833,6 +820,21 @@ impl Ui {
.inner .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))` /// Shortcut for `add(Label::new(text))`
/// ///
/// See also [`Label`]. /// See also [`Label`].
@ -1214,7 +1216,7 @@ impl Ui {
let end_with_horizontal_line = true; let end_with_horizontal_line = true;
if end_with_horizontal_line { 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 // draw a faint line on the left to mark the indented section

View file

@ -91,7 +91,7 @@ impl PlotDemo {
ui.vertical(|ui| { ui.vertical(|ui| {
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
ui.checkbox(animate, "animate"); ui.checkbox(animate, "animate");
ui.advance_cursor(8.0); ui.add_space(8.0);
ui.checkbox(square, "square view"); ui.checkbox(square, "square view");
ui.checkbox(proportional, "proportional data axes"); ui.checkbox(proportional, "proportional data axes");
}); });

View file

@ -122,21 +122,21 @@ impl super::View for Sliders {
ui.radio_value(integer, false, "f64"); ui.radio_value(integer, false, "f64");
}); });
ui.label("(f32, usize etc are also possible)"); ui.label("(f32, usize etc are also possible)");
ui.advance_cursor(8.0); ui.add_space(8.0);
ui.checkbox(logarithmic, "Logarithmic"); 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 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.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.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 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.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.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.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| { ui.vertical_centered(|ui| {
egui::reset_button(ui, self); egui::reset_button(ui, self);

View file

@ -327,7 +327,7 @@ impl BackendPanel {
These are emitted when you switch selected widget with tab, \ These are emitted when you switch selected widget with tab, \
and can be hooked up to a screen reader on supported platforms.", 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 { for event in &self.output_event_history {
ui.label(format!("{:?}", event)); ui.label(format!("{:?}", event));
} }