2021-01-11 19:58:36 +00:00
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
|
|
|
|
enum Enum {
|
|
|
|
First,
|
|
|
|
Second,
|
|
|
|
Third,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
|
|
|
|
pub struct WidgetGallery {
|
2021-02-07 09:55:45 +00:00
|
|
|
enabled: bool,
|
2021-01-11 19:58:36 +00:00
|
|
|
boolean: bool,
|
|
|
|
radio: Enum,
|
|
|
|
scalar: f32,
|
|
|
|
string: String,
|
|
|
|
color: egui::Color32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for WidgetGallery {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2021-02-07 09:55:45 +00:00
|
|
|
enabled: true,
|
2021-01-11 19:58:36 +00:00
|
|
|
boolean: false,
|
|
|
|
radio: Enum::First,
|
|
|
|
scalar: 42.0,
|
2021-02-03 20:05:50 +00:00
|
|
|
string: Default::default(),
|
2021-01-19 23:30:07 +00:00
|
|
|
color: egui::Color32::LIGHT_BLUE.linear_multiply(0.5),
|
2021-01-11 19:58:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl super::Demo for WidgetGallery {
|
2021-02-20 08:18:23 +00:00
|
|
|
fn name(&self) -> &'static str {
|
2021-01-11 19:58:36 +00:00
|
|
|
"🗄 Widget Gallery"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn show(&mut self, ctx: &egui::CtxRef, open: &mut bool) {
|
2021-01-14 22:25:51 +00:00
|
|
|
egui::Window::new(self.name())
|
|
|
|
.open(open)
|
|
|
|
.resizable(false)
|
|
|
|
.show(ctx, |ui| {
|
|
|
|
use super::View;
|
|
|
|
self.ui(ui);
|
|
|
|
});
|
2021-01-11 19:58:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl super::View for WidgetGallery {
|
|
|
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
|
|
|
let Self {
|
2021-02-07 09:55:45 +00:00
|
|
|
enabled,
|
2021-01-11 19:58:36 +00:00
|
|
|
boolean,
|
|
|
|
radio,
|
|
|
|
scalar,
|
|
|
|
string,
|
|
|
|
color,
|
|
|
|
} = self;
|
|
|
|
|
2021-02-07 09:55:45 +00:00
|
|
|
ui.horizontal(|ui| {
|
|
|
|
ui.radio_value(enabled, true, "Enabled");
|
|
|
|
ui.radio_value(enabled, false, "Disabled");
|
|
|
|
});
|
|
|
|
ui.set_enabled(*enabled);
|
|
|
|
|
2021-02-07 12:48:55 +00:00
|
|
|
ui.separator();
|
|
|
|
|
2021-01-15 18:47:58 +00:00
|
|
|
let grid = egui::Grid::new("my_grid")
|
|
|
|
.striped(true)
|
|
|
|
.spacing([40.0, 4.0]);
|
2021-01-14 22:36:23 +00:00
|
|
|
grid.show(ui, |ui| {
|
2021-01-11 19:58:36 +00:00
|
|
|
ui.label("Label:");
|
|
|
|
ui.label("Welcome to the widget gallery!");
|
|
|
|
ui.end_row();
|
|
|
|
|
2021-01-11 20:07:17 +00:00
|
|
|
ui.label("Hyperlink:");
|
2021-01-17 13:48:59 +00:00
|
|
|
ui.add(egui::Hyperlink::new("https://github.com/emilk/egui").text(" egui home page"));
|
2021-01-11 20:07:17 +00:00
|
|
|
ui.end_row();
|
|
|
|
|
2021-02-07 09:55:45 +00:00
|
|
|
ui.label("TextEdit:");
|
2021-02-03 20:05:50 +00:00
|
|
|
ui.add(egui::TextEdit::singleline(string).hint_text("Write something here"));
|
2021-01-11 19:58:36 +00:00
|
|
|
ui.end_row();
|
|
|
|
|
|
|
|
ui.label("Checkbox:");
|
|
|
|
ui.checkbox(boolean, "Checkbox");
|
|
|
|
ui.end_row();
|
|
|
|
|
2021-02-07 09:55:45 +00:00
|
|
|
ui.label("RadioButton:");
|
2021-01-11 19:58:36 +00:00
|
|
|
ui.horizontal(|ui| {
|
|
|
|
ui.radio_value(radio, Enum::First, "First");
|
|
|
|
ui.radio_value(radio, Enum::Second, "Second");
|
|
|
|
ui.radio_value(radio, Enum::Third, "Third");
|
|
|
|
});
|
|
|
|
ui.end_row();
|
|
|
|
|
2021-01-11 20:07:17 +00:00
|
|
|
ui.label("SelectableLabel:");
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
ui.selectable_value(radio, Enum::First, "First");
|
|
|
|
ui.selectable_value(radio, Enum::Second, "Second");
|
|
|
|
ui.selectable_value(radio, Enum::Third, "Third");
|
|
|
|
});
|
|
|
|
ui.end_row();
|
|
|
|
|
2021-01-11 19:58:36 +00:00
|
|
|
ui.label("ComboBox:");
|
|
|
|
egui::combo_box_with_label(ui, "Take your pick", format!("{:?}", radio), |ui| {
|
|
|
|
ui.selectable_value(radio, Enum::First, "First");
|
|
|
|
ui.selectable_value(radio, Enum::Second, "Second");
|
|
|
|
ui.selectable_value(radio, Enum::Third, "Third");
|
|
|
|
});
|
|
|
|
ui.end_row();
|
|
|
|
|
|
|
|
ui.label("Slider:");
|
|
|
|
ui.add(egui::Slider::f32(scalar, 0.0..=100.0).text("value"));
|
|
|
|
ui.end_row();
|
|
|
|
|
|
|
|
ui.label("DragValue:");
|
|
|
|
ui.add(egui::DragValue::f32(scalar).speed(1.0));
|
|
|
|
ui.end_row();
|
|
|
|
|
|
|
|
ui.label("Color picker:");
|
|
|
|
ui.color_edit_button_srgba(color);
|
|
|
|
ui.end_row();
|
|
|
|
|
|
|
|
ui.label("Image:");
|
|
|
|
ui.image(egui::TextureId::Egui, [24.0, 16.0])
|
|
|
|
.on_hover_text("The font texture");
|
|
|
|
ui.end_row();
|
|
|
|
|
|
|
|
ui.label("Button:");
|
2021-01-25 17:50:19 +00:00
|
|
|
if ui.button("Toggle boolean").clicked() {
|
2021-01-11 19:58:36 +00:00
|
|
|
*boolean = !*boolean;
|
|
|
|
}
|
|
|
|
ui.end_row();
|
|
|
|
|
|
|
|
ui.label("ImageButton:");
|
|
|
|
if ui
|
|
|
|
.add(egui::ImageButton::new(egui::TextureId::Egui, [24.0, 16.0]))
|
2021-01-25 17:50:19 +00:00
|
|
|
.clicked()
|
2021-01-11 19:58:36 +00:00
|
|
|
{
|
|
|
|
*boolean = !*boolean;
|
|
|
|
}
|
|
|
|
ui.end_row();
|
2021-01-11 20:07:17 +00:00
|
|
|
|
|
|
|
ui.label("Separator:");
|
2021-01-16 10:34:59 +00:00
|
|
|
ui.separator();
|
2021-01-11 20:07:17 +00:00
|
|
|
ui.end_row();
|
2021-01-14 22:25:51 +00:00
|
|
|
|
|
|
|
ui.label("CollapsingHeader:");
|
|
|
|
ui.collapsing("Click to see what is hidden!", |ui| {
|
|
|
|
ui.horizontal_wrapped_for_text(egui::TextStyle::Body, |ui| {
|
|
|
|
ui.label(
|
2021-01-15 18:47:58 +00:00
|
|
|
"Not much, as it turns out - but here is a gold star for you for checking:",
|
2021-01-14 22:25:51 +00:00
|
|
|
);
|
|
|
|
ui.colored_label(egui::Color32::GOLD, "☆");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
ui.end_row();
|
2021-02-07 09:55:45 +00:00
|
|
|
|
2021-02-18 17:59:59 +00:00
|
|
|
ui.label("Custom widget:");
|
2021-02-20 10:58:08 +00:00
|
|
|
ui.add(super::toggle_switch::toggle(boolean)).on_hover_text(
|
|
|
|
"It's easy to create your own widgets!\n\
|
|
|
|
This toggle switch is just 15 lines of code.",
|
|
|
|
);
|
2021-02-07 09:55:45 +00:00
|
|
|
ui.end_row();
|
2021-02-18 17:59:59 +00:00
|
|
|
|
|
|
|
ui.label("Plot:");
|
|
|
|
let n = 512;
|
|
|
|
let curve = egui::plot::Curve::from_values_iter((0..=n).map(|i| {
|
|
|
|
use std::f64::consts::TAU;
|
|
|
|
let x = egui::remap(i as f64, 0.0..=(n as f64), -TAU..=TAU);
|
|
|
|
egui::plot::Value::new(x, x.sin())
|
|
|
|
}));
|
|
|
|
ui.add(
|
|
|
|
egui::plot::Plot::default()
|
|
|
|
.curve(curve)
|
|
|
|
.height(32.0)
|
|
|
|
.data_aspect(1.0),
|
|
|
|
);
|
|
|
|
ui.end_row();
|
2021-01-11 19:58:36 +00:00
|
|
|
});
|
|
|
|
|
2021-01-14 22:25:51 +00:00
|
|
|
ui.separator();
|
2021-01-11 22:50:50 +00:00
|
|
|
ui.vertical_centered(|ui| {
|
|
|
|
ui.add(crate::__egui_github_link_file!());
|
|
|
|
});
|
2021-01-11 19:58:36 +00:00
|
|
|
}
|
|
|
|
}
|