[ui] add convenience functions
This commit is contained in:
parent
3de20d033e
commit
9f46d8f0be
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,5 +52,6 @@ pub use {
|
|||
style::Style,
|
||||
types::*,
|
||||
ui::Ui,
|
||||
widgets::Widget,
|
||||
widgets::*,
|
||||
containers::*,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -496,18 +496,32 @@ impl Ui {
|
|||
|
||||
// Convenience functions:
|
||||
|
||||
pub fn add_label(&mut self, text: impl Into<String>) -> GuiResponse {
|
||||
self.add(Label::new(text))
|
||||
pub fn label(&mut self, label: impl Into<Label>) -> GuiResponse {
|
||||
self.add(label.into())
|
||||
}
|
||||
|
||||
pub fn button(&mut self, text: impl Into<String>) -> bool {
|
||||
self.add(Button::new(text)).clicked
|
||||
}
|
||||
|
||||
pub fn add_hyperlink(&mut self, url: impl Into<String>) -> GuiResponse {
|
||||
pub fn hyperlink(&mut self, url: impl Into<String>) -> GuiResponse {
|
||||
self.add(Hyperlink::new(url))
|
||||
}
|
||||
|
||||
pub fn button(&mut self, text: impl Into<String>) -> GuiResponse {
|
||||
self.add(Button::new(text))
|
||||
}
|
||||
|
||||
// TODO: argument order?
|
||||
pub fn checkbox(&mut self, text: impl Into<String>, checked: &mut bool) -> GuiResponse {
|
||||
self.add(Checkbox::new(checked, text))
|
||||
}
|
||||
|
||||
// TODO: argument order?
|
||||
pub fn radio(&mut self, text: impl Into<String>, checked: bool) -> GuiResponse {
|
||||
self.add(RadioButton::new(checked, text))
|
||||
}
|
||||
|
||||
pub fn separator(&mut self) -> GuiResponse {
|
||||
self.add(Separator::new())
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Addding Containers / Sub-uis:
|
||||
|
||||
|
|
|
|||
|
|
@ -59,21 +59,21 @@ impl State {
|
|||
let mut ui = ui.centered_column(ui.available().width().min(480.0));
|
||||
ui.set_layout(Layout::vertical(Align::Min));
|
||||
ui.add(label!("Emigui!").text_style(TextStyle::Heading));
|
||||
ui.add_label("Emigui is an immediate mode GUI written in Rust, compiled to WebAssembly, rendered with WebGL.");
|
||||
ui.add_label(
|
||||
ui.label("Emigui is an immediate mode GUI written in Rust, compiled to WebAssembly, rendered with WebGL.");
|
||||
ui.label(
|
||||
"Everything you see is rendered as textured triangles. There is no DOM. There are no HTML elements."
|
||||
);
|
||||
ui.add_label("This is not JavaScript. This is Rust, running at 60 FPS. This is the web page, reinvented with game tech.");
|
||||
ui.add_label("This is also work in progress, and not ready for production... yet :)");
|
||||
ui.label("This is not JavaScript. This is Rust, running at 60 FPS. This is the web page, reinvented with game tech.");
|
||||
ui.label("This is also work in progress, and not ready for production... yet :)");
|
||||
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/");
|
||||
});
|
||||
ui.add(Separator::new());
|
||||
|
||||
ui.add_label("WebGl painter info:");
|
||||
ui.label("WebGl painter info:");
|
||||
ui.indent("webgl region id", |ui| {
|
||||
ui.add_label(self.webgl_painter.debug_info());
|
||||
ui.label(self.webgl_painter.debug_info());
|
||||
});
|
||||
|
||||
ui.add(
|
||||
|
|
|
|||
Loading…
Reference in New Issue