From 9f46d8f0be058f4b2a1ae8f65ca805e0174e312c Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 30 May 2020 09:51:57 +0200 Subject: [PATCH] [ui] add convenience functions --- emigui/src/examples/app.rs | 20 ++++++++++---------- emigui/src/lib.rs | 3 ++- emigui/src/ui.rs | 28 +++++++++++++++++++++------- example_wasm/src/lib.rs | 16 ++++++++-------- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/emigui/src/examples/app.rs b/emigui/src/examples/app.rs index 89383899..3681004f 100644 --- a/emigui/src/examples/app.rs +++ b/emigui/src/examples/app.rs @@ -199,8 +199,8 @@ impl ExampleWindow { )); ui.horizontal(|ui| { - ui.add_label("Project home page:"); - ui.add_hyperlink("https://github.com/emilk/emigui/"); + ui.label("Project home page:"); + ui.hyperlink("https://github.com/emilk/emigui/"); }); }); @@ -236,7 +236,7 @@ impl ExampleWindow { .default_open(false) .show(ui, |ui| { ScrollArea::default().show(ui, |ui| { - ui.add_label(LOREM_IPSUM); + ui.label(LOREM_IPSUM); }); }); @@ -258,23 +258,23 @@ impl ExampleWindow { }); ui.collapsing("Name clash example", |ui| { - ui.add_label("\ + ui.label("\ Widgets that store state require unique identifiers so we can track their state between frames. \ Identifiers are normally derived from the titles of the widget."); - ui.add_label("\ + ui.label("\ For instance, collapsable headers 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, an error message is printed on screen:"); ui.collapsing("Collapsing header", |ui| { - ui.add_label("Contents of first folddable ui"); + ui.label("Contents of first folddable ui"); }); ui.collapsing("Collapsing header", |ui| { - ui.add_label("Contents of second folddable ui"); + ui.label("Contents of second folddable ui"); }); - ui.add_label("\ + ui.label("\ Most widgets don't need unique names, but are tracked \ based on their position on screen. For instance, buttons:"); ui.add(Button::new("Button")); @@ -423,7 +423,7 @@ struct Painting { impl Painting { pub fn ui(&mut self, ui: &mut Ui) { - ui.add_label("Draw with your mouse to paint"); + ui.label("Draw with your mouse to paint"); if ui.add(Button::new("Clear")).clicked { self.lines.clear(); } @@ -599,7 +599,7 @@ impl Tree { }) .collect(); - if ui.button("+") { + if ui.button("+").clicked { self.0.push(Tree::default()); } diff --git a/emigui/src/lib.rs b/emigui/src/lib.rs index 43a3fa43..ad017970 100644 --- a/emigui/src/lib.rs +++ b/emigui/src/lib.rs @@ -52,5 +52,6 @@ pub use { style::Style, types::*, ui::Ui, - widgets::Widget, + widgets::*, + containers::*, }; diff --git a/emigui/src/ui.rs b/emigui/src/ui.rs index b16a2b63..3ff5deba 100644 --- a/emigui/src/ui.rs +++ b/emigui/src/ui.rs @@ -496,18 +496,32 @@ impl Ui { // Convenience functions: - pub fn add_label(&mut self, text: impl Into) -> GuiResponse { - self.add(Label::new(text)) + pub fn label(&mut self, label: impl Into