Create region.add_label shortcut
This commit is contained in:
parent
c7efd72a75
commit
335b22d38d
4 changed files with 20 additions and 16 deletions
|
@ -97,7 +97,7 @@ impl Emigui {
|
||||||
if let Some(mouse_pos) = region.input().mouse_pos {
|
if let Some(mouse_pos) = region.input().mouse_pos {
|
||||||
region.add(label!("mouse_pos: {} x {}", mouse_pos.x, mouse_pos.y,));
|
region.add(label!("mouse_pos: {} x {}", mouse_pos.x, mouse_pos.y,));
|
||||||
} else {
|
} else {
|
||||||
region.add(label!("mouse_pos: None"));
|
region.add_label("mouse_pos: None");
|
||||||
}
|
}
|
||||||
region.add(label!(
|
region.add(label!(
|
||||||
"region cursor: {} x {}",
|
"region cursor: {} x {}",
|
||||||
|
|
|
@ -127,23 +127,25 @@ impl ExampleApp {
|
||||||
});
|
});
|
||||||
|
|
||||||
region.foldable("Name clash example", |region| {
|
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. \
|
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. \
|
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. \
|
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.foldable("Foldable", |region| {
|
||||||
region.add(label!("Contents of first folddable region"));
|
region.add_label("Contents of first folddable region");
|
||||||
});
|
});
|
||||||
region.foldable("Foldable", |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"));
|
||||||
region.add(Button::new("Button"));
|
region.add(Button::new("Button"));
|
||||||
});
|
});
|
||||||
|
|
|
@ -348,6 +348,12 @@ impl Region {
|
||||||
widget.add_to(self)
|
widget.add_to(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convenience functions:
|
||||||
|
|
||||||
|
pub fn add_label(&mut self, text: impl Into<String>) -> GuiResponse {
|
||||||
|
self.add(Label::new(text))
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
pub fn reserve_space(&mut self, size: Vec2, interaction_id: Option<Id>) -> InteractInfo {
|
pub fn reserve_space(&mut self, size: Vec2, interaction_id: Option<Id>) -> InteractInfo {
|
||||||
|
|
|
@ -93,19 +93,15 @@ fn main() {
|
||||||
|
|
||||||
// TODO: Make it even simpler to show a window
|
// TODO: Make it even simpler to show a window
|
||||||
Window::new("Test window").show(region.ctx(), |region| {
|
Window::new("Test window").show(region.ctx(), |region| {
|
||||||
region.add(label!("Grab the window and move it around!"));
|
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!(
|
|
||||||
"This window can be reisized, but not smaller than the contents."
|
|
||||||
));
|
|
||||||
});
|
});
|
||||||
Window::new("Resize me!")
|
Window::new("Resize me!")
|
||||||
.default_pos(pos2(400.0, 100.0))
|
.default_pos(pos2(400.0, 100.0))
|
||||||
.expand_to_fit_content(false)
|
.expand_to_fit_content(false)
|
||||||
.show(region.ctx(), |region| {
|
.show(region.ctx(), |region| {
|
||||||
region.add(label!(
|
region
|
||||||
"This window may shrink so small that its contents no longer fit."
|
.add_label("This window may shrink so small that its contents no longer fit.");
|
||||||
));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let mesh = emigui.paint();
|
let mesh = emigui.paint();
|
||||||
|
|
Loading…
Reference in a new issue