2019-01-21 07:48:32 +00:00
|
|
|
use emigui::{label, math::*, types::*, widgets::*, Align, Region, TextStyle};
|
2018-12-26 09:46:23 +00:00
|
|
|
|
2019-03-11 12:32:54 +00:00
|
|
|
pub fn show_value_gui(value: &mut usize, gui: &mut Region) {
|
|
|
|
gui.add(Slider::usize(value, 1, 1000));
|
|
|
|
if *value < 500 {
|
|
|
|
if gui.add(Button::new("Double it")).clicked {
|
|
|
|
*value *= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gui.add(label!("Value: {}", value));
|
|
|
|
}
|
|
|
|
|
2018-12-26 09:46:23 +00:00
|
|
|
pub struct App {
|
2018-12-26 21:17:33 +00:00
|
|
|
checked: bool,
|
2019-03-11 12:32:44 +00:00
|
|
|
count: usize,
|
|
|
|
radio: usize,
|
2018-12-26 16:32:58 +00:00
|
|
|
|
2019-01-06 23:03:29 +00:00
|
|
|
size: Vec2,
|
2018-12-26 16:32:58 +00:00
|
|
|
corner_radius: f32,
|
|
|
|
stroke_width: f32,
|
2019-03-11 12:32:44 +00:00
|
|
|
num_boxes: usize,
|
|
|
|
|
|
|
|
num_columns: usize,
|
2019-03-11 12:32:54 +00:00
|
|
|
|
|
|
|
slider_value: usize,
|
2018-12-26 09:46:23 +00:00
|
|
|
}
|
|
|
|
|
2018-12-26 21:17:33 +00:00
|
|
|
impl Default for App {
|
|
|
|
fn default() -> App {
|
2018-12-26 16:32:58 +00:00
|
|
|
App {
|
2019-01-05 15:23:40 +00:00
|
|
|
checked: true,
|
2019-01-16 15:28:43 +00:00
|
|
|
radio: 0,
|
2018-12-26 16:32:58 +00:00
|
|
|
count: 0,
|
2019-01-06 23:03:29 +00:00
|
|
|
size: vec2(100.0, 50.0),
|
2018-12-26 16:32:58 +00:00
|
|
|
corner_radius: 5.0,
|
|
|
|
stroke_width: 2.0,
|
2019-02-10 15:10:08 +00:00
|
|
|
num_boxes: 1,
|
2019-03-11 12:32:44 +00:00
|
|
|
|
|
|
|
num_columns: 2,
|
2019-03-11 12:32:54 +00:00
|
|
|
|
|
|
|
slider_value: 100,
|
2018-12-26 16:32:58 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-26 21:17:33 +00:00
|
|
|
}
|
2018-12-26 16:32:58 +00:00
|
|
|
|
2019-01-12 22:07:30 +00:00
|
|
|
impl App {
|
|
|
|
pub fn show_gui(&mut self, gui: &mut Region) {
|
2019-02-09 22:00:07 +00:00
|
|
|
gui.add(label!("Emigui!").text_style(TextStyle::Heading));
|
2019-01-21 07:48:32 +00:00
|
|
|
gui.add(label!("Emigui is an Immediate mode GUI written in Rust, compiled to WebAssembly, rendered with WebGL."));
|
2019-01-13 18:15:11 +00:00
|
|
|
gui.add(Separator::new());
|
2019-01-12 22:07:30 +00:00
|
|
|
|
2019-01-21 07:48:32 +00:00
|
|
|
gui.foldable("Widget examples", |gui| {
|
|
|
|
gui.horizontal(Align::Min, |gui| {
|
|
|
|
gui.add(label!("Text can have").text_color(srgba(110, 255, 110, 255)));
|
|
|
|
gui.add(label!("color").text_color(srgba(128, 140, 255, 255)));
|
|
|
|
gui.add(label!("and tooltips (hover me)")).tooltip_text(
|
|
|
|
"This is a multiline tooltip that demonstrates that you can easily add tooltips to any element.\nThis is the second line.\nThis is the third.",
|
|
|
|
);
|
|
|
|
});
|
2018-12-27 23:51:40 +00:00
|
|
|
|
2019-01-21 07:48:32 +00:00
|
|
|
gui.add(Checkbox::new(&mut self.checked, "checkbox"));
|
2018-12-28 22:53:15 +00:00
|
|
|
|
2019-01-21 07:48:32 +00:00
|
|
|
gui.horizontal(Align::Min, |gui| {
|
|
|
|
if gui.add(radio(self.radio == 0, "First")).clicked {
|
|
|
|
self.radio = 0;
|
|
|
|
}
|
|
|
|
if gui.add(radio(self.radio == 1, "Second")).clicked {
|
|
|
|
self.radio = 1;
|
|
|
|
}
|
|
|
|
if gui.add(radio(self.radio == 2, "Final")).clicked {
|
|
|
|
self.radio = 2;
|
|
|
|
}
|
|
|
|
});
|
2019-01-16 15:28:43 +00:00
|
|
|
|
2019-01-21 07:48:32 +00:00
|
|
|
gui.horizontal(Align::Min, |gui| {
|
|
|
|
if gui
|
|
|
|
.add(Button::new("Click me"))
|
|
|
|
.tooltip_text("This will just increase a counter.")
|
|
|
|
.clicked
|
|
|
|
{
|
|
|
|
self.count += 1;
|
|
|
|
}
|
|
|
|
gui.add(label!(
|
|
|
|
"The button have been clicked {} times",
|
|
|
|
self.count
|
|
|
|
));
|
|
|
|
});
|
2018-12-28 09:39:08 +00:00
|
|
|
});
|
2018-12-26 21:26:15 +00:00
|
|
|
|
2019-03-11 12:32:44 +00:00
|
|
|
gui.foldable("Layouts", |gui| {
|
|
|
|
gui.add(Slider::usize(&mut self.num_columns, 1, 10).text("Columns"));
|
|
|
|
gui.columns(self.num_columns, |cols| {
|
|
|
|
for (i, col) in cols.iter_mut().enumerate() {
|
|
|
|
col.add(label!("Column {} out of {}", i + 1, self.num_columns));
|
|
|
|
if i + 1 == self.num_columns {
|
|
|
|
if col.add(Button::new("Delete this")).clicked {
|
|
|
|
self.num_columns -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-01-06 23:03:29 +00:00
|
|
|
gui.foldable("Test box rendering", |gui| {
|
2019-02-10 15:10:08 +00:00
|
|
|
gui.add(Slider::f32(&mut self.size.x, 0.0, 500.0).text("width"));
|
|
|
|
gui.add(Slider::f32(&mut self.size.y, 0.0, 500.0).text("height"));
|
|
|
|
gui.add(Slider::f32(&mut self.corner_radius, 0.0, 50.0).text("corner_radius"));
|
|
|
|
gui.add(Slider::f32(&mut self.stroke_width, 0.0, 10.0).text("stroke_width"));
|
2019-03-11 12:32:44 +00:00
|
|
|
gui.add(Slider::usize(&mut self.num_boxes, 0, 5).text("num_boxes"));
|
2018-12-26 16:32:58 +00:00
|
|
|
|
2019-02-10 15:10:08 +00:00
|
|
|
let pos = gui
|
|
|
|
.reserve_space(
|
|
|
|
vec2(self.size.x * (self.num_boxes as f32), self.size.y),
|
|
|
|
None,
|
|
|
|
)
|
|
|
|
.rect
|
|
|
|
.min();
|
|
|
|
|
2019-02-10 19:56:59 +00:00
|
|
|
let mut cmds = vec![];
|
2019-02-10 15:10:08 +00:00
|
|
|
for i in 0..self.num_boxes {
|
2019-02-10 19:56:59 +00:00
|
|
|
cmds.push(PaintCmd::Rect {
|
2019-02-10 15:10:08 +00:00
|
|
|
corner_radius: self.corner_radius,
|
|
|
|
fill_color: Some(srgba(136, 136, 136, 255)),
|
|
|
|
rect: Rect::from_min_size(
|
|
|
|
vec2(pos.x + (i as f32) * self.size.x, pos.y),
|
|
|
|
self.size,
|
|
|
|
),
|
|
|
|
outline: Some(Outline {
|
|
|
|
width: self.stroke_width,
|
|
|
|
color: srgba(255, 255, 255, 255),
|
|
|
|
}),
|
2019-02-10 19:56:59 +00:00
|
|
|
});
|
2019-02-10 15:10:08 +00:00
|
|
|
}
|
2019-02-10 19:56:59 +00:00
|
|
|
gui.add_graphic(GuiCmd::PaintCommands(cmds));
|
2019-01-06 23:03:29 +00:00
|
|
|
});
|
2019-03-11 12:32:54 +00:00
|
|
|
|
|
|
|
gui.foldable("Slider example", |gui| {
|
|
|
|
show_value_gui(&mut self.slider_value, gui);
|
|
|
|
});
|
2018-12-26 22:08:50 +00:00
|
|
|
}
|
|
|
|
}
|