Browse Source

Small improvements to the demo (add source code links etc)

pull/213/head
Emil Ernerfeldt 4 years ago
parent
commit
d6233de9dc
  1. 2
      egui_demo_lib/src/apps/demo/demo_windows.rs
  2. 42
      egui_demo_lib/src/apps/demo/plot_demo.rs
  3. 14
      egui_demo_lib/src/apps/demo/tests.rs
  4. 2
      egui_demo_lib/src/apps/demo/widget_gallery.rs

2
egui_demo_lib/src/apps/demo/demo_windows.rs

@ -91,7 +91,7 @@ impl DemoWindows {
/// Show the app ui (menu bar and windows). /// Show the app ui (menu bar and windows).
/// `sidebar_ui` can be used to optionally show some things in the sidebar /// `sidebar_ui` can be used to optionally show some things in the sidebar
pub fn ui(&mut self, ctx: &CtxRef) { pub fn ui(&mut self, ctx: &CtxRef) {
egui::SidePanel::left("side_panel", 185.0).show(ctx, |ui| { egui::SidePanel::left("side_panel", 190.0).show(ctx, |ui| {
ui.heading("✒ egui demos"); ui.heading("✒ egui demos");
ui.separator(); ui.separator();

42
egui_demo_lib/src/apps/demo/plot_demo.rs

@ -34,7 +34,7 @@ impl super::Demo for PlotDemo {
use super::View; use super::View;
Window::new(self.name()) Window::new(self.name())
.open(open) .open(open)
.default_size(vec2(512.0, 512.0)) .default_size(vec2(400.0, 400.0))
.scroll(false) .scroll(false)
.show(ctx, |ui| self.ui(ui)); .show(ctx, |ui| self.ui(ui));
} }
@ -62,23 +62,29 @@ impl PlotDemo {
ui.vertical(|ui| { ui.vertical(|ui| {
ui.label("Circle:"); ui.label("Circle:");
ui.add( ui.add(
egui::Slider::f32(circle_radius, 1e-4..=1e4) egui::DragValue::f32(circle_radius)
.logarithmic(true) .speed(0.1)
.smallest_positive(1e-2) .clamp_range(0.0..=f32::INFINITY)
.text("radius"), // .logarithmic(true)
); // .smallest_positive(1e-2)
ui.add( .prefix("r: "),
egui::Slider::f32(&mut circle_center.x, -1e4..=1e4)
.logarithmic(true)
.smallest_positive(1e-2)
.text("center x"),
);
ui.add(
egui::Slider::f32(&mut circle_center.y, -1e4..=1e4)
.logarithmic(true)
.smallest_positive(1e-2)
.text("center y"),
); );
ui.horizontal(|ui| {
ui.add(
egui::DragValue::f32(&mut circle_center.x)
.speed(0.1)
// .logarithmic(true)
// .smallest_positive(1e-2)
.prefix("x: "),
);
ui.add(
egui::DragValue::f32(&mut circle_center.y)
.speed(1.0)
// .logarithmic(true)
// .smallest_positive(1e-2)
.prefix("y: "),
);
});
}); });
}); });
@ -143,7 +149,7 @@ impl super::View for PlotDemo {
.curve(self.circle()) .curve(self.circle())
.curve(self.sin()) .curve(self.sin())
.curve(self.thingy()) .curve(self.thingy())
.min_size(Vec2::new(400.0, 300.0)); .min_size(Vec2::new(256.0, 200.0));
if self.square { if self.square {
plot = plot.view_aspect(1.0); plot = plot.view_aspect(1.0);
} }

14
egui_demo_lib/src/apps/demo/tests.rs

@ -94,6 +94,7 @@ impl super::Demo for ManualLayoutTest {
impl super::View for ManualLayoutTest { impl super::View for ManualLayoutTest {
fn ui(&mut self, ui: &mut egui::Ui) { fn ui(&mut self, ui: &mut egui::Ui) {
egui::reset_button(ui, self); egui::reset_button(ui, self);
let Self { let Self {
widget_offset, widget_offset,
widget_size, widget_size,
@ -117,9 +118,12 @@ impl super::View for ManualLayoutTest {
ui.add(egui::Slider::f32(&mut widget_size.y, 0.0..=400.0)); ui.add(egui::Slider::f32(&mut widget_size.y, 0.0..=400.0));
ui.end_row(); ui.end_row();
}); });
let widget_rect = let widget_rect =
egui::Rect::from_min_size(ui.min_rect().min + *widget_offset, *widget_size); egui::Rect::from_min_size(ui.min_rect().min + *widget_offset, *widget_size);
ui.add(crate::__egui_github_link_file!());
// Showing how to place a widget anywhere in the `Ui`: // Showing how to place a widget anywhere in the `Ui`:
match *widget_type { match *widget_type {
WidgetType::Button => { WidgetType::Button => {
@ -137,6 +141,7 @@ impl super::View for ManualLayoutTest {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#[derive(PartialEq)]
pub struct TableTest { pub struct TableTest {
num_cols: usize, num_cols: usize,
num_rows: usize, num_rows: usize,
@ -209,6 +214,11 @@ impl super::View for TableTest {
ui.end_row(); ui.end_row();
} }
}); });
ui.vertical_centered(|ui| {
egui::reset_button(ui, self);
ui.add(crate::__egui_github_link_file!());
});
} }
} }
@ -238,6 +248,10 @@ impl super::Demo for InputTest {
impl super::View for InputTest { impl super::View for InputTest {
fn ui(&mut self, ui: &mut egui::Ui) { fn ui(&mut self, ui: &mut egui::Ui) {
ui.vertical_centered(|ui| {
ui.add(crate::__egui_github_link_file!());
});
let response = ui.add( let response = ui.add(
egui::Button::new("Click, double-click or drag me with any mouse button") egui::Button::new("Click, double-click or drag me with any mouse button")
.sense(egui::Sense::click_and_drag()), .sense(egui::Sense::click_and_drag()),

2
egui_demo_lib/src/apps/demo/widget_gallery.rs

@ -125,7 +125,7 @@ impl WidgetGallery {
ui.end_row(); ui.end_row();
ui.add(doc_link_label( ui.add(doc_link_label(
"SelectableLabel:", "SelectableLabel",
"selectable_value,SelectableLabel", "selectable_value,SelectableLabel",
)); ));
ui.horizontal(|ui| { ui.horizontal(|ui| {

Loading…
Cancel
Save