2018-12-30 20:08:29 +00:00
|
|
|
use emgui::{math::*, types::*, Layout};
|
2018-12-26 22:08:50 +00:00
|
|
|
|
|
|
|
pub trait GuiSettings {
|
|
|
|
fn show_gui(&mut self, gui: &mut Layout);
|
|
|
|
}
|
2018-12-26 09:46:23 +00:00
|
|
|
|
|
|
|
pub struct App {
|
2018-12-26 21:17:33 +00:00
|
|
|
checked: bool,
|
2018-12-26 09:46:23 +00:00
|
|
|
count: i32,
|
2018-12-26 21:26:15 +00:00
|
|
|
selected_alternative: i32,
|
2018-12-26 16:32:58 +00:00
|
|
|
|
|
|
|
width: f32,
|
|
|
|
height: f32,
|
|
|
|
corner_radius: f32,
|
|
|
|
stroke_width: f32,
|
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,
|
2018-12-26 21:26:15 +00:00
|
|
|
selected_alternative: 0,
|
2018-12-26 16:32:58 +00:00
|
|
|
count: 0,
|
|
|
|
width: 100.0,
|
|
|
|
height: 50.0,
|
|
|
|
corner_radius: 5.0,
|
|
|
|
stroke_width: 2.0,
|
|
|
|
}
|
|
|
|
}
|
2018-12-26 21:17:33 +00:00
|
|
|
}
|
2018-12-26 16:32:58 +00:00
|
|
|
|
2018-12-26 22:08:50 +00:00
|
|
|
impl GuiSettings for App {
|
|
|
|
fn show_gui(&mut self, gui: &mut Layout) {
|
2018-12-27 23:51:40 +00:00
|
|
|
gui.label(format!(
|
|
|
|
"Screen size: {} x {}",
|
|
|
|
gui.input().screen_size.x,
|
|
|
|
gui.input().screen_size.y,
|
|
|
|
));
|
|
|
|
|
2018-12-28 22:53:15 +00:00
|
|
|
gui.label("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.",
|
|
|
|
);
|
|
|
|
|
|
|
|
gui.checkbox("checkbox", &mut self.checked);
|
2018-12-26 21:17:33 +00:00
|
|
|
|
2018-12-28 09:39:08 +00:00
|
|
|
gui.horizontal(|gui| {
|
|
|
|
if gui.radio("First", self.selected_alternative == 0).clicked {
|
|
|
|
self.selected_alternative = 0;
|
|
|
|
}
|
|
|
|
if gui.radio("Second", self.selected_alternative == 1).clicked {
|
|
|
|
self.selected_alternative = 1;
|
|
|
|
}
|
|
|
|
if gui.radio("Final", self.selected_alternative == 2).clicked {
|
|
|
|
self.selected_alternative = 2;
|
|
|
|
}
|
|
|
|
});
|
2018-12-26 21:26:15 +00:00
|
|
|
|
2018-12-28 22:53:15 +00:00
|
|
|
if gui
|
|
|
|
.button("Click me")
|
|
|
|
.tooltip_text("This will just increase a counter.")
|
|
|
|
.clicked
|
|
|
|
{
|
2018-12-26 09:46:23 +00:00
|
|
|
self.count += 1;
|
|
|
|
}
|
|
|
|
|
2018-12-27 22:55:16 +00:00
|
|
|
gui.label(format!("This is a multiline label.\nThe button have been clicked {} times.\nBelow are more options.", self.count));
|
2018-12-26 16:01:46 +00:00
|
|
|
|
2018-12-27 18:30:31 +00:00
|
|
|
gui.foldable("Box rendering options", |gui| {
|
|
|
|
gui.slider_f32("width", &mut self.width, 0.0, 500.0);
|
|
|
|
gui.slider_f32("height", &mut self.height, 0.0, 500.0);
|
|
|
|
gui.slider_f32("corner_radius", &mut self.corner_radius, 0.0, 50.0);
|
|
|
|
gui.slider_f32("stroke_width", &mut self.stroke_width, 0.0, 10.0);
|
|
|
|
});
|
2018-12-26 16:32:58 +00:00
|
|
|
|
2018-12-28 22:29:24 +00:00
|
|
|
gui.add_paint_command(GuiCmd::PaintCommands(vec![PaintCmd::Rect {
|
|
|
|
corner_radius: self.corner_radius,
|
|
|
|
fill_color: Some(srgba(136, 136, 136, 255)),
|
|
|
|
pos: vec2(300.0, 100.0),
|
|
|
|
size: vec2(self.width, self.height),
|
|
|
|
outline: Some(Outline {
|
|
|
|
width: self.stroke_width,
|
|
|
|
color: srgba(255, 255, 255, 255),
|
|
|
|
}),
|
|
|
|
}]));
|
2018-12-26 09:46:23 +00:00
|
|
|
|
2018-12-27 18:08:43 +00:00
|
|
|
gui.foldable("LayoutOptions", |gui| {
|
2018-12-28 22:29:24 +00:00
|
|
|
let mut options = gui.options().clone();
|
2018-12-27 22:55:16 +00:00
|
|
|
options.show_gui(gui);
|
2018-12-28 22:29:24 +00:00
|
|
|
gui.set_options(options);
|
2018-12-27 18:08:43 +00:00
|
|
|
});
|
2018-12-26 22:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-30 20:08:29 +00:00
|
|
|
impl GuiSettings for emgui::LayoutOptions {
|
2018-12-26 22:08:50 +00:00
|
|
|
fn show_gui(&mut self, gui: &mut Layout) {
|
|
|
|
if gui.button("Reset LayoutOptions").clicked {
|
|
|
|
*self = Default::default();
|
|
|
|
}
|
|
|
|
gui.slider_f32("item_spacing.x", &mut self.item_spacing.x, 0.0, 10.0);
|
|
|
|
gui.slider_f32("item_spacing.y", &mut self.item_spacing.y, 0.0, 10.0);
|
2018-12-28 22:29:24 +00:00
|
|
|
gui.slider_f32("window_padding.x", &mut self.window_padding.x, 0.0, 10.0);
|
|
|
|
gui.slider_f32("window_padding.y", &mut self.window_padding.y, 0.0, 10.0);
|
2018-12-27 22:55:16 +00:00
|
|
|
gui.slider_f32("indent", &mut self.indent, 0.0, 100.0);
|
2018-12-26 22:08:50 +00:00
|
|
|
gui.slider_f32("width", &mut self.width, 0.0, 1000.0);
|
2018-12-27 22:26:05 +00:00
|
|
|
gui.slider_f32("button_padding.x", &mut self.button_padding.x, 0.0, 20.0);
|
|
|
|
gui.slider_f32("button_padding.y", &mut self.button_padding.y, 0.0, 20.0);
|
2018-12-27 22:55:16 +00:00
|
|
|
gui.slider_f32("start_icon_width", &mut self.start_icon_width, 0.0, 60.0);
|
2018-12-26 09:46:23 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-27 17:19:06 +00:00
|
|
|
|
2018-12-30 20:08:29 +00:00
|
|
|
impl GuiSettings for emgui::Style {
|
2018-12-27 17:19:06 +00:00
|
|
|
fn show_gui(&mut self, gui: &mut Layout) {
|
|
|
|
if gui.button("Reset Style").clicked {
|
|
|
|
*self = Default::default();
|
|
|
|
}
|
|
|
|
gui.checkbox("debug_rects", &mut self.debug_rects);
|
|
|
|
gui.slider_f32("line_width", &mut self.line_width, 0.0, 10.0);
|
|
|
|
gui.slider_f32("font_size", &mut self.font_size, 5.0, 32.0);
|
|
|
|
}
|
|
|
|
}
|