[refactor] rename 'example' to 'demo', and add simple example_glium

This commit is contained in:
Emil Ernerfeldt
2020-07-23 12:18:19 +02:00
parent bf19eb2ec5
commit 61cdec8fca
20 changed files with 235 additions and 148 deletions
+3 -3
View File
@@ -1,7 +1,7 @@
use criterion::{criterion_group, criterion_main, Criterion};
pub fn criterion_benchmark(c: &mut Criterion) {
let mut example_app = egui::examples::ExampleApp::default();
let mut demo_app = egui::demos::DemoApp::default();
let mut ctx = egui::Context::new();
let raw_input = egui::RawInput {
@@ -9,10 +9,10 @@ pub fn criterion_benchmark(c: &mut Criterion) {
..Default::default()
};
c.bench_function("example_app", |b| {
c.bench_function("demo_app", |b| {
b.iter(|| {
let mut ui = ctx.begin_frame(raw_input.clone());
example_app.ui(&mut ui, "");
demo_app.ui(&mut ui, "");
ctx.end_frame()
})
});
+1 -1
View File
@@ -2,6 +2,6 @@ mod app;
mod fractal_clock;
pub use {
app::{ExampleApp, ExampleWindow},
app::{DemoApp, DemoWindow},
fractal_clock::FractalClock,
};
@@ -1,22 +1,20 @@
use std::sync::Arc;
use crate::{color::*, containers::*, examples::FractalClock, widgets::*, *};
use crate::{color::*, containers::*, demos::FractalClock, widgets::*, *};
// ----------------------------------------------------------------------------
#[derive(Default)]
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "with_serde", serde(default))]
pub struct ExampleApp {
pub struct DemoApp {
previous_web_location_hash: String,
open_windows: OpenWindows,
// TODO: group the following together as ExampleWindows
example_window: ExampleWindow,
demo_window: DemoWindow,
fractal_clock: FractalClock,
}
impl ExampleApp {
impl DemoApp {
/// `web_location_hash`: for web demo only. e.g. "#fragmet".
pub fn ui(&mut self, ui: &mut Ui, web_location_hash: &str) {
if self.previous_web_location_hash != web_location_hash {
@@ -36,17 +34,17 @@ impl ExampleApp {
}
pub fn windows(&mut self, ctx: &Arc<Context>) {
let ExampleApp {
let DemoApp {
open_windows,
example_window,
demo_window,
fractal_clock,
..
} = self;
Window::new("Examples")
.open(&mut open_windows.examples)
Window::new("Demo")
.open(&mut open_windows.demo)
.show(ctx, |ui| {
example_window.ui(ui);
demo_window.ui(ui);
});
Window::new("Settings")
@@ -76,8 +74,7 @@ impl ExampleApp {
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
struct OpenWindows {
// examples:
examples: bool,
demo: bool,
fractal_clock: bool,
// egui stuff:
@@ -89,7 +86,7 @@ struct OpenWindows {
impl Default for OpenWindows {
fn default() -> Self {
Self {
examples: true,
demo: true,
..OpenWindows::none()
}
}
@@ -98,7 +95,7 @@ impl Default for OpenWindows {
impl OpenWindows {
fn none() -> Self {
Self {
examples: false,
demo: false,
fractal_clock: false,
settings: false,
@@ -116,7 +113,7 @@ fn show_menu_bar(ui: &mut Ui, windows: &mut OpenWindows) {
}
});
menu::menu(ui, "Windows", |ui| {
ui.add(Checkbox::new(&mut windows.examples, "Examples"));
ui.add(Checkbox::new(&mut windows.demo, "Demo"));
ui.add(Checkbox::new(&mut windows.fractal_clock, "Fractal Clock"));
ui.add(Separator::new());
ui.add(Checkbox::new(&mut windows.settings, "Settings"));
@@ -152,31 +149,31 @@ fn show_menu_bar(ui: &mut Ui, windows: &mut OpenWindows) {
/// Showcase some ui code
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
pub struct ExampleWindow {
pub struct DemoWindow {
num_columns: usize,
widgets: Widgets,
layout: LayoutExample,
layout: LayoutDemo,
tree: Tree,
box_painting: BoxPainting,
painting: Painting,
}
impl Default for ExampleWindow {
fn default() -> ExampleWindow {
ExampleWindow {
impl Default for DemoWindow {
fn default() -> DemoWindow {
DemoWindow {
num_columns: 2,
widgets: Default::default(),
layout: Default::default(),
tree: Tree::example(),
tree: Tree::demo(),
box_painting: Default::default(),
painting: Default::default(),
}
}
}
impl ExampleWindow {
impl DemoWindow {
pub fn ui(&mut self, ui: &mut Ui) {
ui.collapsing("About Egui", |ui| {
ui.add(label!(
@@ -238,7 +235,7 @@ impl ExampleWindow {
});
});
ui.collapsing("Name clash example", |ui| {
ui.collapsing("Name clash demo", |ui| {
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.");
@@ -466,13 +463,13 @@ use crate::layout::*;
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "with_serde", serde(default))]
struct LayoutExample {
struct LayoutDemo {
dir: Direction,
align: Option<Align>, // None == jusitifed
reversed: bool,
}
impl Default for LayoutExample {
impl Default for LayoutDemo {
fn default() -> Self {
Self {
dir: Direction::Vertical,
@@ -482,7 +479,7 @@ impl Default for LayoutExample {
}
}
impl LayoutExample {
impl LayoutDemo {
pub fn ui(&mut self, ui: &mut Ui) {
Resize::default()
.default_size([200.0, 100.0])
@@ -555,7 +552,7 @@ enum Action {
struct Tree(Vec<Tree>);
impl Tree {
pub fn example() -> Self {
pub fn demo() -> Self {
Self(vec![
Tree(vec![Tree::default(); 4]),
Tree(vec![Tree(vec![Tree::default(); 2]); 3]),
+2 -2
View File
@@ -28,7 +28,7 @@ pub struct RawInput {
/// Time in seconds. Relative to whatever. Used for animation.
pub time: f64,
/// Local time. Only used for the clock in the example app.
/// Local time. Only used for the clock in the demo app.
pub seconds_since_midnight: Option<f64>,
/// In-order events received this frame
@@ -78,7 +78,7 @@ pub struct InputState {
/// Can be used to fast-forward to next frame for instance feedback. hacky.
pub predicted_dt: f32,
/// Local time. Only used for the clock in the example app.
/// Local time. Only used for the clock in the demo app.
pub seconds_since_midnight: Option<f64>,
/// In-order events received this frame
+2 -2
View File
@@ -24,7 +24,7 @@
pub mod containers;
mod context;
pub mod examples;
pub mod demos;
mod id;
mod input;
mod introspection;
@@ -42,7 +42,7 @@ pub mod widgets;
pub use {
containers::*,
context::Context,
examples::ExampleApp,
demos::DemoApp,
id::Id,
input::*,
layers::*,