From 335b22d38d70832464753e7416d575779640c81d Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 20 Apr 2020 23:42:11 +0200 Subject: [PATCH] Create region.add_label shortcut --- emigui/src/emigui.rs | 2 +- emigui/src/example_app.rs | 16 +++++++++------- emigui/src/region.rs | 6 ++++++ example_glium/src/main.rs | 12 ++++-------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/emigui/src/emigui.rs b/emigui/src/emigui.rs index 91f1b8c8..ebe63e5c 100644 --- a/emigui/src/emigui.rs +++ b/emigui/src/emigui.rs @@ -97,7 +97,7 @@ impl Emigui { if let Some(mouse_pos) = region.input().mouse_pos { region.add(label!("mouse_pos: {} x {}", mouse_pos.x, mouse_pos.y,)); } else { - region.add(label!("mouse_pos: None")); + region.add_label("mouse_pos: None"); } region.add(label!( "region cursor: {} x {}", diff --git a/emigui/src/example_app.rs b/emigui/src/example_app.rs index c872b13a..906df0e7 100644 --- a/emigui/src/example_app.rs +++ b/emigui/src/example_app.rs @@ -127,23 +127,25 @@ impl ExampleApp { }); region.foldable("Name clash example", |region| { - region.add(label!("\ + region.add_label("\ Regions that store state require unique identifiers so we can track their state between frames. \ - Identifiers are normally derived from the titles of the widget.")); + Identifiers are normally derived from the titles of the widget."); - region.add(label!("\ + region.add_label("\ For instance, foldable regions needs to store wether or not they are open. \ If you fail to give them unique names then clicking one will open both. \ - To help you debug this, a error message is printed on screen:")); + To help you debug this, a error message is printed on screen:"); region.foldable("Foldable", |region| { - region.add(label!("Contents of first folddable region")); + region.add_label("Contents of first folddable region"); }); region.foldable("Foldable", |region| { - region.add(label!("Contents of second folddable region")); + region.add_label("Contents of second folddable region"); }); - region.add(label!("Most widgets don't need unique names, but are tracked based on their position on screen. For instance, buttons:")); + region.add_label("\ + Most widgets don't need unique names, but are tracked \ + based on their position on screen. For instance, buttons:"); region.add(Button::new("Button")); region.add(Button::new("Button")); }); diff --git a/emigui/src/region.rs b/emigui/src/region.rs index debd3f3a..a58de0bc 100644 --- a/emigui/src/region.rs +++ b/emigui/src/region.rs @@ -348,6 +348,12 @@ impl Region { widget.add_to(self) } + // Convenience functions: + + pub fn add_label(&mut self, text: impl Into) -> GuiResponse { + self.add(Label::new(text)) + } + // ------------------------------------------------------------------------ pub fn reserve_space(&mut self, size: Vec2, interaction_id: Option) -> InteractInfo { diff --git a/example_glium/src/main.rs b/example_glium/src/main.rs index b6d46477..62efd173 100644 --- a/example_glium/src/main.rs +++ b/example_glium/src/main.rs @@ -93,19 +93,15 @@ fn main() { // TODO: Make it even simpler to show a window Window::new("Test window").show(region.ctx(), |region| { - region.add(label!("Grab the window and move it around!")); - - region.add(label!( - "This window can be reisized, but not smaller than the contents." - )); + region.add_label("Grab the window and move it around!"); + region.add_label("This window can be reisized, but not smaller than the contents."); }); Window::new("Resize me!") .default_pos(pos2(400.0, 100.0)) .expand_to_fit_content(false) .show(region.ctx(), |region| { - region.add(label!( - "This window may shrink so small that its contents no longer fit." - )); + region + .add_label("This window may shrink so small that its contents no longer fit."); }); let mesh = emigui.paint();