From 9c2beabd33fec26d0803fa1b4d964519556d930e Mon Sep 17 00:00:00 2001 From: Ralf Zerres Date: Sat, 27 Jun 2020 22:26:09 +0200 Subject: [PATCH] frontend: examples: remove old orbtk examples maintained upstream Signed-off-by: Ralf Zerres --- frontend/examples/README.md | 20 - frontend/examples/calculator-dark.css | 32 -- frontend/examples/calculator-light.css | 15 - frontend/examples/calculator.rs | 317 ------------ frontend/examples/canvas.rs | 279 ---------- frontend/examples/clear.rs | 67 --- frontend/examples/counter.rs-0.3.1-alpha1 | 111 ---- frontend/examples/csv-import/csv_import.rs | 58 --- .../examples/csv-import/csv_import_bak.rs | 94 ---- .../examples/csv-import/locales/main.json | 78 --- frontend/examples/csv-import/main.rs | 117 ----- frontend/examples/csv-import/parse_args.rs | 151 ------ frontend/examples/grid.css | 25 - frontend/examples/grid.rs | 108 ---- frontend/examples/grid.rs-0.3.1-alpha1 | 154 ------ frontend/examples/image.rs | 21 - frontend/examples/image.rs-0.3.1-alpha1 | 27 - frontend/examples/messages.rs | 86 ---- frontend/examples/minimal.rs | 17 - frontend/examples/minimal.rs-0.3.1-alpha1 | 17 - frontend/examples/multi_window.rs | 97 ---- frontend/examples/numeric_box.rs | 43 -- frontend/examples/overlay.rs | 68 --- frontend/examples/progress_bar.rs | 120 ----- frontend/examples/settings.rs | 162 ------ frontend/examples/stack.rs | 112 ---- frontend/examples/todo/main.rs | 68 --- frontend/examples/todo/state.rs | 92 ---- frontend/examples/widget.rs | 15 - frontend/examples/widgets.rs | 478 ------------------ frontend/examples/widgets.rs-0.3.1-alpha1 | 415 --------------- 31 files changed, 3464 deletions(-) delete mode 100644 frontend/examples/README.md delete mode 100644 frontend/examples/calculator-dark.css delete mode 100644 frontend/examples/calculator-light.css delete mode 100644 frontend/examples/calculator.rs delete mode 100644 frontend/examples/canvas.rs delete mode 100644 frontend/examples/clear.rs delete mode 100644 frontend/examples/counter.rs-0.3.1-alpha1 delete mode 100644 frontend/examples/csv-import/csv_import.rs delete mode 100644 frontend/examples/csv-import/csv_import_bak.rs delete mode 100644 frontend/examples/csv-import/locales/main.json delete mode 100644 frontend/examples/csv-import/main.rs delete mode 100644 frontend/examples/csv-import/parse_args.rs delete mode 100644 frontend/examples/grid.css delete mode 100644 frontend/examples/grid.rs delete mode 100644 frontend/examples/grid.rs-0.3.1-alpha1 delete mode 100644 frontend/examples/image.rs delete mode 100644 frontend/examples/image.rs-0.3.1-alpha1 delete mode 100644 frontend/examples/messages.rs delete mode 100644 frontend/examples/minimal.rs delete mode 100644 frontend/examples/minimal.rs-0.3.1-alpha1 delete mode 100644 frontend/examples/multi_window.rs delete mode 100644 frontend/examples/numeric_box.rs delete mode 100644 frontend/examples/overlay.rs delete mode 100644 frontend/examples/progress_bar.rs delete mode 100644 frontend/examples/settings.rs delete mode 100644 frontend/examples/stack.rs delete mode 100644 frontend/examples/todo/main.rs delete mode 100644 frontend/examples/todo/state.rs delete mode 100644 frontend/examples/widget.rs delete mode 100644 frontend/examples/widgets.rs delete mode 100644 frontend/examples/widgets.rs-0.3.1-alpha1 diff --git a/frontend/examples/README.md b/frontend/examples/README.md deleted file mode 100644 index 3313ff5..0000000 --- a/frontend/examples/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# OrbTk examples - -[![Build and test](https://github.com/redox-os/orbtk/workflows/build/badge.svg)](https://github.com/redox-os/orbtk/actions) -![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg) - -* calculator: calculator example -* canvas: use third party render library in canvas -* clear: interaction between widgets -* grid: grid layout example -* image: image widget -* minimal: minimal example -* multi_window: multi window example -* overlay: draw widgets on the top -* settings: use registry and settings service (load / save) -* stack: stack layout example -* widgets: widget overview - -## License - -Licensed under MIT license ([LICENSE](../LICENSE)). \ No newline at end of file diff --git a/frontend/examples/calculator-dark.css b/frontend/examples/calculator-dark.css deleted file mode 100644 index 437e2e3..0000000 --- a/frontend/examples/calculator-dark.css +++ /dev/null @@ -1,32 +0,0 @@ -.header { - background: #444e55; -} - -.content { - background: #3b434a; -} - -text_box { - background: transparent; - border-width: 0; - color: #9dafbf; - font-size: 16; -} - -#input { - font-size: 16; -} - -text-block { - font-size: 42; - color: #dfebf5; -} - -#input { - background: transparent; -} - -button { - border-radius: 1; - font-size: 20; -} \ No newline at end of file diff --git a/frontend/examples/calculator-light.css b/frontend/examples/calculator-light.css deleted file mode 100644 index f807825..0000000 --- a/frontend/examples/calculator-light.css +++ /dev/null @@ -1,15 +0,0 @@ -.header { - background: #ffffff; -} - -.content { - background: #fafafa; -} - -text_box { - color: #4d4c4c; -} - -text-block { - color: #4d4c4c; -} \ No newline at end of file diff --git a/frontend/examples/calculator.rs b/frontend/examples/calculator.rs deleted file mode 100644 index 36d9582..0000000 --- a/frontend/examples/calculator.rs +++ /dev/null @@ -1,317 +0,0 @@ -use orbtk::prelude::*; -use orbtk::theme::DEFAULT_THEME_CSS; - -static DARK_EXT: &'static str = include_str!("../resources/calculator-dark.css"); - -#[cfg(feature = "light-theme")] -static LIGHT_EXT: &'static str = include_str!("../resources/calculator-light.css"); - -#[cfg(not(feature = "light-theme"))] -fn get_theme() -> ThemeValue { - ThemeValue::create_from_css(DEFAULT_THEME_CSS) - .extension_css(DARK_EXT) - .build() -} - -#[cfg(feature = "light-theme")] -fn get_theme() -> ThemeValue { - ThemeValue::create() - .extension_css(DARK_EXT) - .extension_css(LIGHT_EXT) - .build() -} - -#[derive(Debug, Copy, Clone)] -enum Action { - Digit(char), - Operator(char), -} - -#[derive(Default, AsAny)] -pub struct MainViewState { - input: String, - operator: Option, - left_side: Option, - right_side: Option, - action: Option, -} - -impl MainViewState { - fn action(&mut self, action: impl Into>) { - self.action = action.into(); - } - - fn calculate(&mut self, ctx: &mut Context) { - let mut result = 0.0; - if let Some(operator) = self.operator { - if let Some(left_side) = self.left_side { - if let Some(right_side) = self.right_side { - match operator { - '+' => { - result = left_side + right_side; - } - '-' => { - result = left_side - right_side; - } - '*' => { - result = left_side * right_side; - } - '/' => { - result = left_side / right_side; - } - _ => {} - } - } - } - } - - if result % 1.0 == 0.0 { - ctx.widget() - .set("text", String16::from(format!("{}", result))); - } else { - ctx.widget() - .set("text", String16::from(format!("{:.8}", result))); - } - - self.left_side = Some(result); - self.right_side = None; - } -} - -impl State for MainViewState { - fn update(&mut self, _: &mut Registry, ctx: &mut Context) { - if let Some(action) = self.action { - match action { - Action::Digit(digit) => { - self.input.push(digit); - ctx.child("input").get_mut::("text").push(digit); - } - Action::Operator(operator) => match operator { - 'C' => { - self.input.clear(); - self.left_side = None; - self.operator = None; - self.right_side = None; - ctx.widget().get_mut::("text").clear(); - ctx.child("input").get_mut::("text").clear() - } - '=' => { - self.right_side = Some(self.input.parse().unwrap_or(0.0)); - self.calculate(ctx); - self.input.clear(); - self.left_side = None; - self.operator = None; - self.right_side = None; - ctx.child("input").get_mut::("text").clear() - } - _ => { - if self.input.is_empty() { - return; - } - if self.left_side.is_none() { - self.left_side = Some(self.input.parse().unwrap_or(0.0)); - } else { - self.right_side = Some(self.input.parse().unwrap_or(0.0)); - self.calculate(ctx); - } - - ctx.child("input") - .get_mut::("text") - .push(operator); - self.input.clear(); - self.operator = Some(operator); - } - }, - } - - self.action = None; - } - } -} - -fn generate_digit_button( - ctx: &mut BuildContext, - id: Entity, - sight: char, - primary: bool, - column: usize, - column_span: usize, - row: usize, -) -> Entity { - let mut button = Button::new() - .class("single_content") - .min_size(48.0, 48.0) - .text(sight.to_string()) - .on_click(move |states, _| -> bool { - state(id, states).action(Action::Digit(sight)); - true - }) - .attach(Grid::column(column)) - .attach(Grid::row(row)) - .attach(Grid::column_span(column_span)); - - if primary { - button = button.class("primary"); - } - - button.build(ctx) -} - -fn generate_operation_button( - ctx: &mut BuildContext, - id: Entity, - sight: char, - primary: bool, - column: usize, - column_span: usize, - row: usize, -) -> Entity { - let mut button = Button::new() - .class("single_content") - .min_size(48.0, 48.0) - .text(sight.to_string()) - .class("square") - .on_click(move |states, _| -> bool { - state(id, states).action(Action::Operator(sight)); - true - }) - .attach(Grid::column(column)) - .attach(Grid::column_span(column_span)) - .attach(Grid::row(row)); - - if primary { - button = button.class("primary"); - } - - button.build(ctx) -} - -widget!(MainView { - text: String16 -}); - -impl Template for MainView { - fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { - self.name("MainView") - .width(212.0) - .height(336.0) - .text("") - .child( - Grid::new() - .rows(Rows::new().add(72.0).add("*").build()) - .child( - Container::new() - .padding(8.0) - .element("container") - .class("header") - .attach(Grid::row(0)) - .child( - Grid::new() - .child( - ScrollViewer::new() - .scroll_viewer_mode(("custom", "disabled")) - .child( - TextBlock::new() - .width(0.0) - .height(14.0) - .text("") - .element("text-block") - .id("input") - .v_align("start") - .build(ctx), - ) - .build(ctx), - ) - .child( - TextBlock::new() - .element("text-block") - .text(id) - .v_align("end") - .h_align("end") - .build(ctx), - ) - .build(ctx), - ) - .build(ctx), - ) - .child( - Container::new() - .element("container") - .class("content") - .padding(8.0) - .attach(Grid::row(1)) - .child( - Grid::new() - .columns( - Columns::new() - .add(48.0) - .add(4.0) - .add(48.0) - .add(4.0) - .add(48.0) - .add(4.0) - .add(48.0) - .build(), - ) - .rows( - Rows::new() - .add(48.0) - .add(4.0) - .add(48.0) - .add(4.0) - .add(48.0) - .add(4.0) - .add(48.0) - .add(4.0) - .add(48.0) - .build(), - ) - // row 0 - .child(generate_operation_button(ctx, id, 'C', false, 0, 5, 0)) - .child(generate_operation_button(ctx, id, '/', true, 6, 3, 0)) - // row 2 - .child(generate_digit_button(ctx, id, '7', false, 0, 1, 2)) - .child(generate_digit_button(ctx, id, '8', false, 2, 1, 2)) - .child(generate_digit_button(ctx, id, '9', false, 4, 1, 2)) - .child(generate_operation_button(ctx, id, '*', true, 6, 1, 2)) - // row 4 - .child(generate_digit_button(ctx, id, '4', false, 0, 1, 4)) - .child(generate_digit_button(ctx, id, '5', false, 2, 1, 4)) - .child(generate_digit_button(ctx, id, '6', false, 4, 1, 4)) - .child(generate_operation_button(ctx, id, '-', true, 6, 1, 4)) - // row 6 - .child(generate_digit_button(ctx, id, '1', false, 0, 1, 6)) - .child(generate_digit_button(ctx, id, '2', false, 2, 1, 6)) - .child(generate_digit_button(ctx, id, '3', false, 4, 1, 6)) - .child(generate_operation_button(ctx, id, '+', true, 6, 1, 6)) - // row 8 - .child(generate_digit_button(ctx, id, '0', false, 0, 3, 8)) - .child(generate_digit_button(ctx, id, '.', false, 4, 1, 8)) - .child(generate_operation_button(ctx, id, '=', true, 6, 1, 8)) - .build(ctx), - ) - .build(ctx), - ) - .build(ctx), - ) - } -} - -fn main() { - Application::new() - .window(|ctx| { - Window::new() - .title("OrbTk - Calculator example") - .position((100.0, 100.0)) - .size(212.0, 336.0) - .theme(get_theme()) - .child(MainView::new().build(ctx)) - .build(ctx) - }) - .run(); -} - -// helper to request MainViewState -fn state<'a>(id: Entity, states: &'a mut StatesContext) -> &'a mut MainViewState { - states.get_mut(id) -} diff --git a/frontend/examples/canvas.rs b/frontend/examples/canvas.rs deleted file mode 100644 index eba6274..0000000 --- a/frontend/examples/canvas.rs +++ /dev/null @@ -1,279 +0,0 @@ -use orbtk::{prelude::*, render::platform::RenderContext2D, utils}; -use std::cell::Cell; - -use euc::{buffer::Buffer2d, rasterizer, Pipeline}; -use vek::*; - -// Cube is copied from euc spinning_cube example -// https://github.com/zesterer/euc/blob/master/examples/spinning_cube.rs -struct Cube<'a> { - mvp: Mat4, - positions: &'a [Vec4], -} - -impl<'a> Pipeline for Cube<'a> { - type Vertex = (usize, Rgba); - type VsOut = Rgba; - type Pixel = u32; - - #[inline(always)] - fn vert(&self, (v_index, v_color): &Self::Vertex) -> ([f32; 4], Self::VsOut) { - ((self.mvp * self.positions[*v_index]).into_array(), *v_color) - } - - #[inline(always)] - fn frag(&self, v_color: &Self::VsOut) -> Self::Pixel { - let bytes = v_color.map(|e| (e * 255.0) as u8).into_array(); - (bytes[2] as u32) << 0 - | (bytes[1] as u32) << 8 - | (bytes[0] as u32) << 16 - | (bytes[3] as u32) << 24 - } -} - -#[derive(Clone, Default, PartialEq, Pipeline)] -struct CubePipeline { - spin: Cell, -} - -impl render::RenderPipeline for CubePipeline { - fn draw(&self, render_target: &mut render::RenderTarget) { - let mut color = Buffer2d::new( - [ - render_target.width() as usize, - render_target.height() as usize, - ], - 0, - ); - let mut depth = Buffer2d::new( - [ - render_target.width() as usize, - render_target.height() as usize, - ], - 1.0, - ); - - let mvp = Mat4::perspective_fov_rh_no( - 1.3, - render_target.width() as f32, - render_target.height() as f32, - 0.01, - 100.0, - ) * Mat4::translation_3d(Vec3::new(0.0, 0.0, -2.0)) - * Mat4::::scaling_3d(0.4) - * Mat4::rotation_x((self.spin.get() * 0.002) * 8.0) - * Mat4::rotation_y((self.spin.get() as f32 * 0.004).cos() * 4.0) - * Mat4::rotation_z((self.spin.get() as f32 * 0.008).sin() * 2.0); - - Cube { - mvp, - positions: &[ - Vec4::new(-1.0, -1.0, -1.0, 1.0), // 0 - Vec4::new(-1.0, -1.0, 1.0, 1.0), // 1 - Vec4::new(-1.0, 1.0, -1.0, 1.0), // 2 - Vec4::new(-1.0, 1.0, 1.0, 1.0), // 3 - Vec4::new(1.0, -1.0, -1.0, 1.0), // 4 - Vec4::new(1.0, -1.0, 1.0, 1.0), // 5 - Vec4::new(1.0, 1.0, -1.0, 1.0), // 6 - Vec4::new(1.0, 1.0, 1.0, 1.0), // 7 - ], - } - .draw::, _>( - &[ - // -x - (0, Rgba::green()), - (3, Rgba::blue()), - (2, Rgba::red()), - (0, Rgba::green()), - (1, Rgba::red()), - (3, Rgba::blue()), - // +x - (7, Rgba::blue()), - (4, Rgba::green()), - (6, Rgba::red()), - (5, Rgba::red()), - (4, Rgba::green()), - (7, Rgba::blue()), - // -y - (5, Rgba::blue()), - (0, Rgba::red()), - (4, Rgba::green()), - (1, Rgba::green()), - (0, Rgba::red()), - (5, Rgba::blue()), - // +y - (2, Rgba::red()), - (7, Rgba::blue()), - (6, Rgba::green()), - (2, Rgba::red()), - (3, Rgba::green()), - (7, Rgba::blue()), - // -z - (0, Rgba::red()), - (6, Rgba::green()), - (4, Rgba::blue()), - (0, Rgba::red()), - (2, Rgba::blue()), - (6, Rgba::green()), - // +z - (7, Rgba::green()), - (1, Rgba::red()), - (5, Rgba::blue()), - (3, Rgba::blue()), - (1, Rgba::red()), - (7, Rgba::green()), - ], - &mut color, - Some(&mut depth), - ); - - render_target.draw(color.as_ref()); - } -} - -// OrbTk 2D drawing -#[derive(Clone, Default, PartialEq, Pipeline)] -struct Graphic2DPipeline; - -impl render::RenderPipeline for Graphic2DPipeline { - fn draw(&self, render_target: &mut render::RenderTarget) { - let mut render_context = - RenderContext2D::new(render_target.width(), render_target.height()); - - let width = 120.0; - let height = 120.0; - - let x = (render_target.width() - width) / 2.0; - let y = (render_target.height() - height) / 2.0; - // render_context.set_fill_style(utils::Brush::SolidColor(Color::from("#000000"))); - - render_context.set_fill_style(utils::Brush::LinearGradient { - start: Point::new(x, y), - end: Point::new(x + width, y + height), - stops: vec![ - LinearGradientStop { - position: 0.0, - color: Color::from("#0021EB"), - }, - LinearGradientStop { - position: 0.5, - color: Color::from("#CE2F24"), - }, - LinearGradientStop { - position: 1.0, - color: Color::from("#70EF49"), - }, - ], - }); - render_context.fill_rect(x, y, width, height); - // render_target.draw(render_context.data()); - } -} - -#[derive(Default, AsAny)] -pub struct MainViewState { - cube_spin: f32, -} - -impl MainViewState { - fn spin(&mut self) { - self.cube_spin += 32.0; - } -} - -impl State for MainViewState { - fn update(&mut self, _: &mut Registry, ctx: &mut Context<'_>) { - if let Some(cube) = ctx - .widget() - .get_mut::("render_pipeline") - .0 - .as_any() - .downcast_ref::() - { - cube.spin.set(self.cube_spin); - } - } -} - -widget!( - MainView { - render_pipeline: RenderPipeline - } -); - -impl Template for MainView { - fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { - self.name("MainView") - .render_pipeline(RenderPipeline(Box::new(CubePipeline::default()))) - .child( - Grid::create() - .rows( - Rows::create() - .row("auto") - .row("*") - .row("auto") - .row("*") - .build(), - ) - .child( - TextBlock::create() - .attach(Grid::row(0)) - .text("Canvas (render with euc crate)") - .element("text-block") - .class("h1") - .margin(4.0) - .build(ctx), - ) - .child( - Canvas::create() - .attach(Grid::row(1)) - .render_pipeline(id) - .build(ctx), - ) - .child( - Button::create() - .text("spin cube") - .vertical_alignment("end") - .attach(Grid::row(1)) - .margin(4.0) - .on_click(move |states, _| { - states.get_mut::(id).spin(); - true - }) - .build(ctx), - ) - .child( - TextBlock::create() - .attach(Grid::row(2)) - .text("Canvas (render with OrbTk)") - .element("text-block") - .class("h1") - .margin(4.0) - .build(ctx), - ) - .child( - Canvas::create() - .attach(Grid::row(3)) - .render_pipeline(RenderPipeline(Box::new(Graphic2DPipeline::default()))) - .build(ctx), - ) - .build(ctx), - ) - } -} - -fn main() { - // use this only if you want to run it as web application. - orbtk::initialize(); - - Application::new() - .window(|ctx| { - Window::create() - .title("OrbTk - canvas example") - .position((100.0, 100.0)) - .size(420.0, 730.0) - .child(MainView::create().build(ctx)) - .build(ctx) - }) - .run(); -} diff --git a/frontend/examples/clear.rs b/frontend/examples/clear.rs deleted file mode 100644 index 02521ca..0000000 --- a/frontend/examples/clear.rs +++ /dev/null @@ -1,67 +0,0 @@ -use orbtk::prelude::*; - -#[derive(Default, AsAny)] -pub struct MainViewState { - clear: bool, -} - -impl MainViewState { - // Sets an action the state - fn clear(&mut self) { - self.clear = true; - } -} - -impl State for MainViewState { - fn update(&mut self, _: &mut Registry, ctx: &mut Context<'_>) { - if self.clear { - // Clears the text property of MainView and because - // of the sharing also the text of the TextBox. - ctx.widget().set("text", String16::from("")); - self.clear = false; - } - } -} - -widget!(MainView { - text: String16 -}); - -impl Template for MainView { - fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { - self.name("MainView").child( - Stack::create() - .orientation("horizontal") - // By injecting the id of the parent the text property - // is shared between the MainView and the TextBox. This - // means both references the same String16 object. - .child(TextBox::create().height(32.0).text(id).build(ctx)) - .child( - Button::create() - .margin((8.0, 0.0, 0.0, 0.0)) - // mouse click event handler - .on_click(move |states, _| { - // Calls clear of the state of MainView - states.get_mut::(id).clear(); - true - }) - .text("Clear") - .build(ctx), - ) - .build(ctx), - ) - } -} - -fn main() { - Application::new() - .window(|ctx| { - Window::create() - .title("OrbTk - minimal example") - .position((100.0, 100.0)) - .size(420.0, 730.0) - .child(MainView::create().margin(4.0).build(ctx)) - .build(ctx) - }) - .run(); -} diff --git a/frontend/examples/counter.rs-0.3.1-alpha1 b/frontend/examples/counter.rs-0.3.1-alpha1 deleted file mode 100644 index 7e15032..0000000 --- a/frontend/examples/counter.rs-0.3.1-alpha1 +++ /dev/null @@ -1,111 +0,0 @@ -use orbtk::api::widget::StatesContext; -use orbtk::prelude::*; - -#[derive(Debug)] -pub enum Event { - Increment(Entity), -} - -#[derive(AsAny, Default)] -pub struct AppState { - events: VecDeque, - pub notes: Entity, - count: u32, -} - -//rbtk_api::widget::states_context::StatesContext<'_> -#[derive(Debug, Copy, Clone)] -enum Action { - Increment(usize), -} - -#[derive(Default, AsAny)] -pub struct MainViewState { - num: usize, - action: Option, -} - -impl MainViewState { - fn action(&mut self, action: impl Into>) { - self.action = action.into(); - } -} - -impl Template for MainView { - fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { - self.name("MainView") - .counter(0) - .result("Button count: 0") - .child( - Button::create() - .selector(Selector::from("button").id("btn")) - .min_size(100.0, 50.0) - .text(("result", id)) - .on_click(move |states, _| -> bool { - state(id, states).action(Action::Increment(10)); - true - }) - .build(ctx), - ) - } -} - -impl State for MainViewState { - fn update(&mut self, _: &mut Registry, ctx: &mut Context<'_>) { - if let Some(action) = self.action { - match action { - Action::Increment(digit) => { - *ctx.widget().get_mut::("counter") += digit as usize; - let counter = *ctx.widget().get::("counter"); - ctx.widget().set( - "result", - String16::from(format!("Button count: {}", counter)), - ); - } - _ => {} - } - - // Is it possible to get rid of this line ? - self.action = None; - } - - if let Some(event) = self.events.pop_front() { - match event { - // Create and append the note to the UI. - Event::Increment(entity) => { - if let Some(copy) = Self::fetch_text(ctx, entity) { - self.append_note(ctx, copy); - let count = self.count + 1; - self.count = count; - if count == 1 { - ctx.widget().set::("spacing", 12.0); - } - } - } - } - } - } -} - -widget!(MainView { - age:i32, - counter:usize, - result: String16 -}); - -fn main() { - Application::new() - .window(|ctx| { - Window::create() - .title("OrbTk - counter example") - .position((100.0, 100.0)) - .size(400.0, 400.0) - .child(MainView::create().build(ctx)) - .build(ctx) - }) - .run(); -} - -fn state<'a>(id: Entity, states: &'a mut StatesContext) -> &'a mut MainViewState { - states.get_mut(id) -} diff --git a/frontend/examples/csv-import/csv_import.rs b/frontend/examples/csv-import/csv_import.rs deleted file mode 100644 index 8a544ad..0000000 --- a/frontend/examples/csv-import/csv_import.rs +++ /dev/null @@ -1,58 +0,0 @@ -/// Commandline program testing csv imports -use log::{info, trace, warn}; -use serde::Deserialize; -use std::{ - error::Error, - io, - process, - thread, - time::{Duration, Instant}}; - -mod parse_args; - -#[derive(Debug, Deserialize)] -struct Environment { - test_lang: String, -} - -#[derive(Debug, Deserialize)] -pub struct CsvImportRecord { - // dion => Allianz Dion: 1 - // policy_code => Policy Typ: "AS" - // policy_number => Versicherungsscheinnummer: "1515735810" - pub dion: String, - pub policy_code: String, - pub policy_number: u32, -} - -#[tokio::main] -async fn main() -> Result<(), Box> { - use parse_args::parse_args; - - use std::net::ToSocketAddrs; - use std::process; - use std::sync::Arc; - - use viperus::Viperus; - - // initialize logger - env_logger::init(); - info!("Commencing the proxy!"); - - // initialize viperus structure - let mut v = Viperus::new(); - - // parse commandline arguments - info!(target: "csv_import", "parsing commandline args"); - parse_args(&mut v)?; - trace!(target: "Viperus", "Config results: {:?}", v); - - // create a new NextCloudTalk client - let config = matches.value_of("config").unwrap_or("advotracker.conf"); - let csv_import = matches.value_of("import").unwrap_or("allianz.txt"); - //let username = matches.value_of("username").unwrap_or("nctalkbot"); - //let password = matches.value_of("password").unwrap_or("botpassword"); - let verbose = matches.occurrences_of("verbose"); - - Ok(()) -} diff --git a/frontend/examples/csv-import/csv_import_bak.rs b/frontend/examples/csv-import/csv_import_bak.rs deleted file mode 100644 index 7ec275b..0000000 --- a/frontend/examples/csv-import/csv_import_bak.rs +++ /dev/null @@ -1,94 +0,0 @@ -/* advotracker infrastructure. - * - * Copyright 2020 Ralf Zerres - * SPDX-License-Identifier: (0BSD or MIT) - */ - -// Rust nightly supports procedural macros! -//#![feature(proc_macro)] -//#![deny(rust_2018_idioms)] - -use dotenv::dotenv; -use locales::t; -use serde::Deserialize; - -use std::env; -use std::error::Error; -use std::io; -use std::process; - -use tracing::{debug, trace, Level}; - -#[derive(Deserialize, Debug)] -struct Environment { - test_lang: String, -} - -#[derive(Debug, Deserialize)] -pub struct CsvImportRecord { - // dion => Allianz Dion: 1 - // policy_code => Policy Typ: "AS" - // policy_number => Versicherungsscheinnummer: "1515735810" - pub dion: String, - pub policy_code: String, - pub policy_number: u32, -} - -#[tokio::main] -async fn main() -> Result<(), Box> { - // the YAML file is found relative to the current file - //use clap_v3::{load_yaml, App}; - use clap::{load_yaml, App}; - - let yaml = load_yaml!("cli.yml"); - //let matches = App::from_yaml(yaml).get_matches(); - let matches = App::from_yaml(yaml) - .name(clap::crate_name!()) - .version(clap::crate_version!()) - .author(clap::crate_authors!()) - .about(clap::crate_description!()) - .get_matches(); - - // Gets the option value if supplied by user, otherwise set defaults - let config = matches.value_of("config").unwrap_or("advotracker.conf"); - let csv_import = matches.value_of("import").unwrap_or("allianz.txt"); - //let username = matches.value_of("username").unwrap_or("nctalkbot"); - //let password = matches.value_of("password").unwrap_or("botpassword"); - let verbose = matches.occurrences_of("verbose"); - - if verbose > 0 { - println!("{}: runtime parameters", clap::crate_name!()); - println!("config_file: '{}'", config); - println!("csv_import: '{}'", csv_import); - println!("verbosity level: {}", matches.occurrences_of("verbose")); - } - - if verbose > 1 { - println!("\nEnvironment:"); - for (key, value) in env::vars() { - println!("{}={}", key, value); - } - } - - Ok(()) -} - -/// import from csv format (Standard in) -fn import() -> Result<(), Box> { - // Build the CSV reader and iterate over each record. - let mut csv_reader = csv::Reader::from_reader(io::stdin()); - for result in csv_reader.deserialize() { - // The iterator yields Result, so we check the - // error here. - let record: CsvImportRecord = result?; - println!("{:?}", record); - } - Ok(()) -} - -fn main() { - if let Err(err) = import() { - println!("error running CSV-Import: {}", err); - process::exit(1); - } -} diff --git a/frontend/examples/csv-import/locales/main.json b/frontend/examples/csv-import/locales/main.json deleted file mode 100644 index b6caee8..0000000 --- a/frontend/examples/csv-import/locales/main.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - "err.lang.not_found": { - "de_DE.UTF-8": "Konnte Sprachkode nicht auslesen", - "de": "Konnte Sprachkode nicht auslesen", - "en": "Couldn't read LANG" - }, - "err.user.not_found": { - "fr": "Utilisateur introuvable: $email, $id", - "de-DE.UTF-8": "Anwender nicht gefunden: $email, $id", - "de": "Anwender nicht gefunden: $email, $id", - "en": "User not found: $email, $id" - }, - "main.started": { - "de_DE.UTF-8": "Programmlogik starten", - "de": "Programmlogik starten", - "en": "Program logic started" - }, - "main.finished": { - "de_DE.UTF-8": "Programmlogik beendet", - "de": "Programmlogik beendet", - "en": "Program logic finished" - }, - "parse.arguments": { - "de_DE.UTF-8": "Programmargumente prüfen", - "de": "Programmargumente prüfen", - "en": "Parsing arguments" - }, - "parse.environment": { - "de_DE.UTF-8": "Umgebungsvariablen prüfen", - "de": "Umgebungsvariablen prüfen", - "en": "Parsing environment" - }, - "parse.results": { - "de_DE.UTF-8": "Ergebnisse der Konfigurations-Parameterprüfung", - "de": "Ergebnisse der Konfigurationsparameterprüfung", - "en": "Config parsing results" - }, - "config.name": { - "de_DE.UTF-8": "Konfigurationswert für", - "de": "Konfigurationswert für", - "en": "Config Value for" - }, - "config.name.lang": { - "de_DE.UTF-8": "Sprach-Code", - "de": "Sprach-Code", - "en": "Language code" - }, - "config.name.verbositylevel": { - "de_DE.UTF-8": "Ausgabe-Ebene", - "de": "Ausgabe-Ebene", - "en": "verbosity level" - }, - "config.name.environment": { - "de_DE.UTF-8": "Umgebungsvariablen", - "de": "Umgebungsvariablen", - "en": "environment" - }, - "config.name.configfile": { - "de_DE.UTF-8": "Konfigurations-Datei", - "de": "Konfigurations-Datei", - "en": "config file" - }, - "config.name.dbdriver": { - "de_DE.UTF-8": "Datenbank-Treiber", - "de": "Datenbank-Treiber", - "en": "database driver" - }, - "state.started": { - "de_DE.UTF-8": "gestartet", - "de": "gestartet", - "en": "started" - }, - "state.finished": { - "de_DE.UTF-8": "beendet", - "de": "beended", - "en": "finished" - } -} diff --git a/frontend/examples/csv-import/main.rs b/frontend/examples/csv-import/main.rs deleted file mode 100644 index 6e4fc57..0000000 --- a/frontend/examples/csv-import/main.rs +++ /dev/null @@ -1,117 +0,0 @@ -/// Commandline program testing csv imports -use serde::Deserialize; -use std::env; -use std::{ - error::Error, - io, -// process, -// thread, - // time::{Duration, Instant} -}; -use tracing::{debug, trace, Level}; - -mod parse_args; - -#[derive(Debug, Deserialize)] -struct Environment { - test_lang: String, -} - -#[derive(Debug, Deserialize)] -pub struct CsvImportRecord { - // dion => Allianz Dion: 1 - // policy_code => Policy Typ: "AS" - // policy_number => Versicherungsscheinnummer: "1515735810" - pub dion: String, - pub policy_code: String, - pub policy_number: u32, -} - -/// import from csv format (Standard in) -fn import() -> Result<(), Box> { - // Build the CSV reader and iterate over each record. - let mut csv_reader = csv::Reader::from_reader(io::stdin()); - for result in csv_reader.deserialize() { - // The iterator yields Result, so we check the - // error here. - let record: CsvImportRecord = result?; - println!("{:?}", record); - } - Ok(()) -} - -fn main() -> Result<(), Box> { - use dotenv::dotenv; - use parse_args::parse_args; - use locales::t; - //use std::process; - //use std::sync::Arc; - use tracing_subscriber::fmt; - use viperus::Viperus; - - //static DEFAULT_FILTER: &str = concat!(module_path!(), "=", "trace"); - - // initialize the tracing subsystem - // a drop in replacement for classical logging - // reference: https://tokio.rs/blog/2019-08-tracing/ - let span = tracing::span!(Level::TRACE, "csv-import"); - let _enter = span.enter(); - let subscriber = fmt::Subscriber::builder() - .with_env_filter("trace") - //.with_max_level(tracing::Level::DEBUG) - .finish(); - - // initialize logger - //env_logger::init(); - //info!("Commencing the import Test-Run!"); - - tracing::subscriber::with_default(subscriber, || { - // get system environment - let mut lang = env::var("LANG").unwrap_or("en".to_string()); - let mut res = t!("parse.environment", lang); - let mut state = t!("state.started", lang); - trace!(target: "csv-import", message = ?res, state = ?state); - //debug!(message = ?res, state = ?state); - trace!(target: "csv-import", environment = "system", lang = ?lang); - - // get testing environment (.env) - dotenv().ok(); - match envy::from_env::() { - Ok(environment) => { - if environment.test_lang != lang { lang = environment.test_lang; } - }, - Err(e) => { debug!(target: "csv-import", "{}", e); } - } - res = t!("parse.environment", lang); - trace!(target: "csv-import", environment = "envy", lang = ?lang); - state = t!("state.finished", lang); - trace!(target: "csv-import", message = ?res, state = ?state); - - // initialize viperus structure - let mut v = Viperus::new(); - - // parse commandline arguments - res = t!("parse.arguments", lang); - state = t!("state.started", lang); - trace!(target: "csv-import", process = ?res, state = ?state); - - let _ = parse_args(&mut v); - state = t!("state.finished", lang); - trace!(target: "csv-import", process = ?res, state = ?state); - //trace!(target: "Viperus", "Config results: {:?}", v); - - // Starting the program logic - res = t!("main.started", lang); - state = t!("state.started", lang); - trace!(target: "csv-import", process = ?res, state = ?state); - - // import the given import file - let csv_file = v.get::("import_file").unwrap(); - - state = t!("state.finished", lang); - res = t!("main.finished", lang); - trace!(target: "csv-import", process = ?res, state = ?state); - }); - - Ok(()) -} diff --git a/frontend/examples/csv-import/parse_args.rs b/frontend/examples/csv-import/parse_args.rs deleted file mode 100644 index 9123cd9..0000000 --- a/frontend/examples/csv-import/parse_args.rs +++ /dev/null @@ -1,151 +0,0 @@ -use viperus::Viperus; - -/// The given Viperus structure will be muted according to the -/// processed default, environment and commandline arguments -pub fn parse_args(v: &mut Viperus) -> Result<(), Box> { - //use log::{debug, info, trace, warn}; - use tracing::{trace, Level}; - use std::env; - - if cfg!(feature = "fmt-clap") { - trace!(target: "Viperus", "Viperus feature 'fmt-clap' enabled."); - println!("Using feature fmt-clap"); - } - - // preset default key/value pairs (lowest priority) - v.add_default("config_file", String::from("csv_import.ron")); - v.add_default("import_file", String::from("allianz.txt")); - //v.add_default("username", String::from("nctalkbot")); - //v.add_default("password", String::from("botpassword")); - v.add_default("verbose", 0); - - // parse CLI commandline arguments with clap - use clap::{crate_authors, crate_description, crate_name, crate_version, App, Arg}; - - // CLI arguments are defined inline - let matches = App::new("csv-import") - .name(crate_name!()) - .version(crate_version!()) - .author(crate_authors!()) - .about(crate_description!()) - .after_help("Test: Versicherungsnummern-Import Allianz DirectCall") - .template( - "\ - {bin} v{version} -{about} - -{all-args} - -(C) 2020 {author} -{after-help}", - ) - .arg( - Arg::with_name("configFile") - .short("c") - .long("configFile") - .value_name("FILE") - .help("Select a config file") - .takes_value(true), - ) - .arg( - Arg::with_name("importFile") - .short("i") - .long("importFile") - //.value_name("FILE") - .help("Select source file for the csv-import") - .takes_value(true), - ) - // .arg( - // Arg::with_name("username") - // .short("u") - // .long("username") - // .help("Sets username") - // .takes_value(true), - // ) - // .arg( - // Arg::with_name("password") - // .short("P") - // .long("password") - // .help("Sets password") - // .takes_value(true), - // ) - .arg( - Arg::with_name("verbose") - .short("v") - .long("verbose") - .help("Sets verbosity level") - .multiple(true), - ) - .get_matches(); - - if matches.occurrences_of("verbose") > 0 { - // clap is using i64, viperus i32 - let n = matches.occurrences_of("verbose") as i32; - v.add("verbose", n); - } - - // preset the prefix for relevant environment variables ("ADVOTRACKER_") - let mut env_prefix: String = crate_name!().to_uppercase(); - env_prefix.push_str("_"); - v.set_env_prefix(&env_prefix); - - // respect dotenv environment (e.g for testing) - // -> overwrites the preset default values - println!( - "RUST_LOG={}", - dotenv::var("RUST_LOG").unwrap_or_else(|_| String::from("None")) - ); - - // enable caching and automatic update of environment values - if cfg!(feature = "fmt-cache") { - v.cache(true); - } - if cfg!(feature = "fmt-env") { - v.automatic_env(true); - } - - // load user selected call arguments - // -> overwrites values given via environment variables - v.load_clap(matches)?; - - // bond the clap names to camel_case rust variable names - v.bond_clap("configFile", "config_file"); - v.bond_clap("importFile", "import_file"); - //v.bond_clap("username", "username"); - //v.bond_clap("password", "password"); - v.bond_clap("verbose", "verbose"); - - trace!("verbose {:?}", v.get::("verbose").unwrap()); - if v.get::("verbose").unwrap() > 0 { - println!( - "config_file: {:?}", - v.get::("config_file").unwrap_or_default() - ); - println!( - "import_file: {:?}", - v.get::("import_file").unwrap_or_default() - ); - // println!( - // "username: {:?}", - // v.get::("username").unwrap_or_default() - // ); - // println!( - // "password: {:?}", - // v.get::("password").unwrap_or_default() - // ); // only for testing now - - println!( - "verbosity level: {:?}", - v.get::("verbose").unwrap_or_default() - ); - } - - if v.get::("verbose").unwrap() > 1 { - println!("\nEnvironment:"); - for (key, value) in env::vars() { - println!("{}={}", key, value); - } - } - - Ok(()) -} diff --git a/frontend/examples/grid.css b/frontend/examples/grid.css deleted file mode 100644 index a5af45f..0000000 --- a/frontend/examples/grid.css +++ /dev/null @@ -1,25 +0,0 @@ -* { - font-size: 24; -} - -lynch { - background: #647b91; -} - -bluebayoux { - background: #516475; -} - -linkwater { - background: #dfebf5; - color: #3b434a; -} - -light-text { - color: #dfebf5; -} - -goldendream { - background: #efd035; - color: #3b434a; -} \ No newline at end of file diff --git a/frontend/examples/grid.rs b/frontend/examples/grid.rs deleted file mode 100644 index 1acd5b2..0000000 --- a/frontend/examples/grid.rs +++ /dev/null @@ -1,108 +0,0 @@ -use orbtk::prelude::*; -use orbtk::theme::DEFAULT_THEME_CSS; - -static CSS_EXT: &'static str = include_str!("../resources/grid.css"); - -fn get_theme() -> ThemeValue { - ThemeValue::create_from_css(DEFAULT_THEME_CSS) - .extension_css(CSS_EXT) - .build() -} - -widget!(MainView); - -impl Template for MainView { - fn template(self, _: Entity, ctx: &mut BuildContext) -> Self { - self.name("MainView").child( - Grid::create() - .columns( - Columns::create() - .column("*") - .column("auto") - .column(50.0) - .build(), - ) - .rows(Rows::create().row("*").row("*").build()) - .child( - Grid::create() - .element("lynch") - .margin((10.0, 0.0, 0.0, 4.0)) - .attach(Grid::column(0)) - .child( - TextBlock::create() - .text("(0,0)") - .element("light-text") - .horizontal_alignment("center") - .vertical_alignment("center") - .build(ctx), - ) - .build(ctx), - ) - .child( - Grid::create() - .element("bluebayoux") - .margin(10.0) - .constraint(Constraint::create().width(150.0).build()) - .attach(Grid::column(1)) - .child( - TextBlock::create() - .text("(1,0)") - .element("white") - .horizontal_alignment("center") - .vertical_alignment("center") - .build(ctx), - ) - .build(ctx), - ) - .child( - Grid::create() - .element("linkwater") - .attach(Grid::column(2)) - .child( - TextBlock::create() - .text("(2,0)") - .element("linkwater") - .horizontal_alignment("center") - .vertical_alignment("center") - .build(ctx), - ) - .build(ctx), - ) - .child( - Grid::create() - .element("goldendream") - .attach(Grid::column(0)) - .attach(Grid::row(1)) - .attach(Grid::column_span(3)) - .child( - TextBlock::create() - .text("(0,1) - ColumnSpan 3") - .element("goldendream") - .horizontal_alignment("center") - .vertical_alignment("center") - .build(ctx), - ) - .build(ctx), - ) - .build(ctx), - ) - } -} - -fn main() { - // use this only if you want to run it as web application. - orbtk::initialize(); - - Application::new() - .window(|ctx| { - Window::create() - .title("OrbTk - grid example") - .position((400.0, 400.0)) - .size(420.0, 730.0) - .theme(get_theme()) - .resizeable(true) - .child(MainView::create().build(ctx)) - .build(ctx) - }) - .run(); -} diff --git a/frontend/examples/grid.rs-0.3.1-alpha1 b/frontend/examples/grid.rs-0.3.1-alpha1 deleted file mode 100644 index 511a3b0..0000000 --- a/frontend/examples/grid.rs-0.3.1-alpha1 +++ /dev/null @@ -1,154 +0,0 @@ -use orbtk::prelude::*; -use orbtk::theme::DEFAULT_THEME_CSS; - -static CSS_EXT: &'static str = include_str!("../resources/stylesheets/grid.css"); - -fn get_theme() -> ThemeValue { - ThemeValue::create_from_css(DEFAULT_THEME_CSS) - .extension_css(CSS_EXT) - .build() -} - -widget!(MainView); - -impl Template for MainView { - fn template(self, _: Entity, ctx: &mut BuildContext) -> Self { - self.name("MainView").child( - Grid::create() - .columns( - Columns::create() - .column("*") - .column("auto") - .column(90.0) - .build(), - ) - .rows(Rows::create().row("*").row("*").row("*").build()) - .child( - Grid::create() - .selector("hiedemann") - .margin((30.0, 25.0, 0.0, 20.0)) - .constraint(Constraint::create().width(80.0).build()) - .attach(Grid::column(0)) - .child( - TextBlock::create() - .text("Grid\n(0,0)") - .selector("hiedemann") - .horizontal_alignment("center") - .vertical_alignment("center") - .build(ctx), - ) - .build(ctx), - ) - .child( - Grid::create() - .selector("bluebayoux") - .margin(10.0) - .constraint(Constraint::create().width(150.0).build()) - .attach(Grid::column(1)) - .child( - TextBlock::create() - .text("Grid\n(1,0)") - .selector("white") - .horizontal_alignment("center") - .vertical_alignment("center") - .build(ctx), - ) - .build(ctx), - ) - .child( - Grid::create() - .selector("linkwater") - .attach(Grid::column(2)) - .child( - TextBlock::create() - .text("Grid\n(2,0)") - .selector("linkwater") - .horizontal_alignment("center") - .vertical_alignment("center") - .build(ctx), - ) - .build(ctx), - ) - .child( - Grid::create() - .selector("goldendream") - .attach(Grid::column(0)) - .attach(Grid::row(1)) - .attach(Grid::column_span(3)) - .child( - TextBlock::create() - .text("Grid (0,1) - ColumnSpan 3") - .selector("goldendream") - .horizontal_alignment("center") - .vertical_alignment("center") - .build(ctx), - ) - .build(ctx), - ) - .child( - Grid::create() - .selector("bluebayoux") - .margin(10.0) - .constraint(Constraint::create().width(200.0).build()) - .attach(Grid::column(0)) - .attach(Grid::row(2)) - .child( - TextBlock::create() - .text("Row 2") - .selector("white") - .horizontal_alignment("center") - .vertical_alignment("center") - .build(ctx), - ) - .child( - TextBlock::create() - .text("(0,1)") - .selector("white") - .horizontal_alignment("center") - .vertical_alignment("center") - .build(ctx), - ) - .build(ctx), - ) - /*.child( - Grid::create() - .selector("hiedemann") - .attach(Grid::column(1)) - .attach(Grid::row(2)) - //.attach(Grid::column_span(2)) - .margin((30.0, 25.0, 0.0, 20.0)) - .attach(Grid::column(0)) - .child( - TextBlock::create() - .text("(0,2)") - //.selector("light-text") - .selector("hiedemann") - .horizontal_alignment("center") - .vertical_alignment("center") - .build(ctx), - ) - .build(ctx), - ) - */ - .build(ctx), - ) - } -} - -fn main() { - // use this only if you want to run it as web application. - //orbtk::initialize(); - - Application::new() - .window(|ctx| { - Window::create() - .title("OrbTk - grid example") - .position((100.0, 10.0)) - .size(420.0, 530.0) - .theme(get_theme()) - .resizeable(true) - .child(MainView::create().build(ctx)) - .build(ctx) - }) - .run(); -} diff --git a/frontend/examples/image.rs b/frontend/examples/image.rs deleted file mode 100644 index cea11c0..0000000 --- a/frontend/examples/image.rs +++ /dev/null @@ -1,21 +0,0 @@ -use orbtk::prelude::*; - -fn main() { - // use this only if you want to run it as web application. - orbtk::initialize(); - - Application::new() - .window(|ctx| { - Window::new() - .title("OrbTk - image example") - .position((100.0, 100.0)) - .size(800.0, 420.0) - .child( - ImageWidget::new() - .image("../resources/orbtk-space.png") - .build(ctx), - ) - .build(ctx) - }) - .run(); -} diff --git a/frontend/examples/image.rs-0.3.1-alpha1 b/frontend/examples/image.rs-0.3.1-alpha1 deleted file mode 100644 index 889f62e..0000000 --- a/frontend/examples/image.rs-0.3.1-alpha1 +++ /dev/null @@ -1,27 +0,0 @@ -use orbtk::prelude::*; - -fn main() { - // use this only if you want to run it as web application. - orbtk::initialize(); - - Application::new() - .window(|ctx| { - Window::create() - .title("OrbTk - image example") - .position((100.0, 100.0)) - .size(610.0, 610.0) - .resizeable(true) - .child( - ImageWidget::create() - .image("resources/images/advotracker.jpg") - .margin(10.0) - .vertical_alignment("Center") - .horizontal_alignment("Center") - .size(600.0, 600.0) - .clip(true) - .build(ctx), - ) - .build(ctx) - }) - .run(); -} diff --git a/frontend/examples/messages.rs b/frontend/examples/messages.rs deleted file mode 100644 index 6ae34b5..0000000 --- a/frontend/examples/messages.rs +++ /dev/null @@ -1,86 +0,0 @@ -// // This examples shows how you could send messages between different widgets / views. - -// use orbtk::*; - -// mod sender { -// use orbtk::*; -// use std::{cell::Cell, rc::Rc}; - -// #[derive(Default)] -// struct SenderState { -// send_message: Cell, -// } - -// impl State for SenderState { -// fn update(&mut self, ctx: &mut Context<'_>) { -// if self.send_message.get() { -// ctx.send_message("receiver_view", StringMessage::from("Hello from sender.")); -// } -// } -// } - -// widget!(SenderView); - -// impl Widget for SenderView { -// fn create() -> Self { -// let state = Rc::new(SenderState::default()); -// let send_state = state.clone(); - -// SenderView::new() -// .debug_name("SenderView") -// .child( -// Button::create() -// .text("Send message") -// .on_click(move |_| -> bool { -// send_state.send_message.set(true); -// true -// }), -// ) -// .state(state) -// } -// } -// } - -// mod receiver { -// use super::sender; -// use orbtk::*; -// use std::rc::Rc; - -// struct ReceiverState; - -// impl State for ReceiverState { -// fn receive_messages(&self, _context: &mut Context<'_>, messages: &Vec) { -// for message in messages { -// if let Ok(message) = message.downcast_ref::() { -// println!("Message received: {}", message.0); -// } -// } -// } -// } - -// widget!(ReceiverView); - -// impl Widget for ReceiverView { -// fn create() -> Self { -// ReceiverView::new() -// .debug_name("ReceiverView") -// .child(Container::create().child(sender::SenderView::create())) -// .attach(Selector::default().id("receiver_view")) -// .state(Rc::new(ReceiverState)) -// } -// } -// } - -// fn main() { -// let mut application = Application::default(); -// application -// .create_window() -// .bounds((100.0, 100.0, 420.0, 730.0)) -// .title("OrbTk - minimal example") -// .root(receiver::ReceiverView::create()) -// .debug_flag(true) -// .build(); -// application.run(); -// } - -fn main() {} diff --git a/frontend/examples/minimal.rs b/frontend/examples/minimal.rs deleted file mode 100644 index bd024bc..0000000 --- a/frontend/examples/minimal.rs +++ /dev/null @@ -1,17 +0,0 @@ -use orbtk::prelude::*; - -fn main() { - // use this only if you want to run it as web application. - orbtk::initialize(); - - Application::new() - .window(|ctx| { - Window::create() - .title("OrbTk - minimal example") - .position((100.0, 100.0)) - .size(420.0, 730.0) - .child(TextBlock::create().text("OrbTk").margin(4.0).build(ctx)) - .build(ctx) - }) - .run(); -} diff --git a/frontend/examples/minimal.rs-0.3.1-alpha1 b/frontend/examples/minimal.rs-0.3.1-alpha1 deleted file mode 100644 index bd024bc..0000000 --- a/frontend/examples/minimal.rs-0.3.1-alpha1 +++ /dev/null @@ -1,17 +0,0 @@ -use orbtk::prelude::*; - -fn main() { - // use this only if you want to run it as web application. - orbtk::initialize(); - - Application::new() - .window(|ctx| { - Window::create() - .title("OrbTk - minimal example") - .position((100.0, 100.0)) - .size(420.0, 730.0) - .child(TextBlock::create().text("OrbTk").margin(4.0).build(ctx)) - .build(ctx) - }) - .run(); -} diff --git a/frontend/examples/multi_window.rs b/frontend/examples/multi_window.rs deleted file mode 100644 index bbea4d6..0000000 --- a/frontend/examples/multi_window.rs +++ /dev/null @@ -1,97 +0,0 @@ -/// mutli window will not work properly on web now. But it will be fixed. - -use orbtk::prelude::*; - -#[derive(AsAny, Default)] -struct MainState { - show_window: bool, -} - -impl MainState { - fn show_window(&mut self) { - self.show_window = true; - } - fn disable_window(&mut self) { - self.show_window = false; - } -} - -impl State for MainState { - fn update(&mut self, _: &mut Registry, ctx: &mut Context) { - if self.show_window { - ctx.child("window1_button").set("enabled", false); - ctx.show_window(|ctx| { - Window::new() - .title("Dialog") - .position((120.0, 120.0)) - .size(120.0, 125.0) - .child( - Stack::new() - .child(TextBlock::new().text("I'm the new window").margin(4.0).build(ctx)) - .child( - Button::new() - .id("window3_button") - .margin(4.0) - .text("Disable me") - .build(ctx), - ) - .build(ctx), - ) - .build(ctx) - }); - self.show_window = false; - } - } -} - -widget!(MainView); - -impl Template for MainView { - fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { - self.child( - Stack::new() - .child(TextBlock::new().text("Window 1").margin(4.0).build(ctx)) - .child( - Button::new() - .id("window1_button") - .on_click(move |states, _| { - states.get_mut::(id).show_window(); - true - }) - .margin(4.0) - .text("Show new child window") - .build(ctx), - ) - .build(ctx), - ) - } -} - -fn main() { - // use this only if you want to run it as web application. - orbtk::initialize(); - - Application::new() - .window(|ctx| { - Window::new() - .title("OrbTk - multi window example window 1") - .position((100.0, 100.0)) - .size(420.0, 730.0) - .child(MainView::new().build(ctx)) - .build(ctx) - }) - .window(|ctx| { - Window::new() - .title("OrbTk - multi window example window 2") - .position((600.0, 100.0)) - .size(420.0, 730.0) - .child( - Stack::new() - .child(TextBlock::new().text("Window 2").margin(4.0).build(ctx)) - .child(Button::new().margin(4.0).text("Click me").build(ctx)) - .build(ctx), - ) - .build(ctx) - }) - .run(); -} diff --git a/frontend/examples/numeric_box.rs b/frontend/examples/numeric_box.rs deleted file mode 100644 index 2402655..0000000 --- a/frontend/examples/numeric_box.rs +++ /dev/null @@ -1,43 +0,0 @@ -use orbtk::prelude::*; - -widget!(MainView); - -impl Template for MainView { - fn template(self, _id: Entity, ctx: &mut BuildContext) -> Self { - self.child( - Stack::create() - .spacing(8.0) - .orientation("vertical") - .horizontal_alignment("center") - .child( - TextBlock::create() - .text("Tyre pressure") - .font_size(20.0) - .build(ctx), - ) - .child( - NumericBox::create() - .max(123.0) - .step(0.123) - .val(0.123) - .build(ctx), - ) - .child(Button::create().text("Blow air").build(ctx)) - .build(ctx), - ) - } -} - -fn main() { - Application::new() - .window(|ctx| { - Window::create() - .title("OrbTk - NumericBox example") - .position((100.0, 100.0)) - .size(420.0, 730.0) - .resizeable(true) - .child(MainView::create().build(ctx)) - .build(ctx) - }) - .run(); -} diff --git a/frontend/examples/overlay.rs b/frontend/examples/overlay.rs deleted file mode 100644 index f3c690a..0000000 --- a/frontend/examples/overlay.rs +++ /dev/null @@ -1,68 +0,0 @@ -use orbtk::prelude::*; - -widget!(MainView); - -impl Template for MainView { - fn template(self, _: Entity, ctx: &mut BuildContext) -> Self { - let container = Container::new() - .background("#dfebf5") - .width(200.0) - .height(200.0) - .child( - TextBlock::new() - .foreground("#3b434a") - .text("Overlay 1") - .element("h2") - .v_align("center") - .h_align("center") - .build(ctx), - ) - .build(ctx); - - let container = Container::new() - .background("#dffff5") - .width(180.0) - .height(180.0) - .position((250.0, 250.0)) - .child( - TextBlock::new() - .foreground("#3f3f3f") - .text("Overlay 2") - .v_align("center") - .h_align("center") - .build(ctx), - ) - .build(ctx); - - ctx.append_child_to_overlay(container).unwrap(); - self.name("MainView").child( - Container::new() - .background("#e1bc21") - .child( - TextBlock::new() - .text("MainView") - .element("h1") - .v_align("center") - .h_align("center") - .build(ctx), - ) - .build(ctx), - ) - } -} - -fn main() { - // use this only if you want to run it as web application. - orbtk::initialize(); - - Application::new() - .window(|ctx| { - Window::new() - .title("OrbTk - overlay example") - .position((100.0, 100.0)) - .size(420.0, 730.0) - .child(MainView::create().build(ctx)) - .build(ctx) - }) - .run(); -} diff --git a/frontend/examples/progress_bar.rs b/frontend/examples/progress_bar.rs deleted file mode 100644 index 13737c5..0000000 --- a/frontend/examples/progress_bar.rs +++ /dev/null @@ -1,120 +0,0 @@ -use orbtk::prelude::*; - -#[derive(Copy, Clone)] -enum ProgressEvent { - Advance(f64), - Reset, - SetToFull, -} - -#[derive(Default, AsAny)] -struct MainViewState { - action: Option, -} - -widget!(MainView); - -impl MainViewState { - fn action(&mut self, action: impl Into>) { - self.action = action.into(); - } -} - -impl State for MainViewState { - fn update(&mut self, _: &mut Registry, ctx: &mut Context<'_>) { - if let Some(action) = self.action { - match action { - ProgressEvent::Advance(amount) => { - let old_width = ctx.child("pgbar").clone_or_default::("val"); - let new_width = old_width + amount; - // Set the ProgressBar's val property to the calculated percentage - // (whereas 0.0 means 0 %, and 1.0 means 100 %) to advance the progress - ctx.child("pgbar").set::("val", new_width); - } - ProgressEvent::Reset => { - ctx.child("pgbar").set::("val", 0.0); - } - ProgressEvent::SetToFull => { - ctx.child("pgbar").set::("val", 1.0); - } - } - self.action = None; - } - } -} - -impl Template for MainView { - fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { - self.child( - Stack::new() - .h_align("center") - .margin((16.0, 16.0, 16.0, 16.0)) - .spacing(8.0) - .child( - ProgressBar::new() - .id("pgbar") - .val(0.0) - .width(512.0) - .build(ctx), - ) - .child( - Stack::new() - .h_align("center") - .spacing(8.0) - .child( - Button::new() - .text("Progress by 25%") - .width(256.0) - .on_click(move |states, _| -> bool { - states - .get_mut::(id) - .action(ProgressEvent::Advance(0.25)); - true - }) - .build(ctx), - ) - .child( - Button::new() - .text("Reset") - .width(256.0) - .on_click(move |states, _| -> bool { - states - .get_mut::(id) - .action(ProgressEvent::Reset); - true - }) - .build(ctx), - ) - .child( - Button::new() - .text("Set to 100%") - .width(256.0) - .on_click(move |states, _| -> bool { - states - .get_mut::(id) - .action(ProgressEvent::SetToFull); - true - }) - .build(ctx), - ) - .build(ctx), - ) - .build(ctx), - ) - } -} - -fn main() { - Application::new() - .window(|ctx| { - Window::new() - .title("OrbTk - ProgressBar example") - .position((0.0, 0.0)) - .size(720.0, 576.0) - .borderless(false) - .resizeable(true) - .child(MainView::new().build(ctx)) - .build(ctx) - }) - .run(); -} diff --git a/frontend/examples/settings.rs b/frontend/examples/settings.rs deleted file mode 100644 index be048f8..0000000 --- a/frontend/examples/settings.rs +++ /dev/null @@ -1,162 +0,0 @@ -use serde_derive::{Deserialize, Serialize}; - -use orbtk::prelude::*; - -#[derive(Copy, Clone, PartialEq)] -enum Action { - Load, - Save, - Clear, -} - -#[derive(Default, Clone, Serialize, Deserialize)] -pub struct Global { - pub label: String, -} - -#[derive(Default, AsAny)] -pub struct MainViewState { - action: Option, -} - -impl MainViewState { - fn action(&mut self, action: Action) { - self.action = Some(action); - } -} - -impl State for MainViewState { - fn update(&mut self, registry: &mut Registry, ctx: &mut Context<'_>) { - if let Some(action) = self.action { - match action { - Action::Load => { - // load label from settings file. - if let Ok(global) = registry - .get::("settings") - .load::("global") - { - ctx.widget().set("text", String16::from(global.label)); - } - - ctx.widget().set( - "info_text", - String16::from("Label loaded from settings file."), - ); - } - Action::Save => { - // save label to settings file. - registry - .get_mut::("settings") - .save( - "global", - &Global { - label: ctx.widget().get::("text").to_string(), - }, - ) - .unwrap(); - ctx.widget() - .set("info_text", String16::from("Label saved to settings file.")); - } - Action::Clear => { - ctx.widget().set("text", String16::default()); - ctx.widget().set("info_text", String16::from("")); - } - } - - self.action = None; - } - } -} - -widget!(MainView { - text: String16, - info_text: String16 -}); - -impl Template for MainView { - fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { - self.name("MainView").child( - Grid::new() - .rows(Rows::new().add(36.0).add(4.0).add("auto").build()) - .columns( - Columns::new() - .add(160.0) - .add(4.0) - .add("Auto") - .add(4.0) - .add("Auto") - .add(4.0) - .add("Auto") - .build(), - ) - .child( - TextBox::new() - .v_align("center") - .text(id) - .build(ctx), - ) - .child( - Button::new() - .class("single_content") - .attach(Grid::row(0)) - .attach(Grid::column(2)) - .on_click(move |states, _| { - state(id, states).action(Action::Load); - true - }) - .text("Load") - .build(ctx), - ) - .child( - Button::new() - .class("single_content") - .attach(Grid::row(0)) - .attach(Grid::column(4)) - .on_click(move |states, _| { - state(id, states).action(Action::Save); - true - }) - .text("Save") - .build(ctx), - ) - .child( - Button::new() - .class("single_content") - .attach(Grid::row(0)) - .attach(Grid::column(6)) - .on_click(move |states, _| { - state(id, states).action(Action::Clear); - true - }) - .text("Clear") - .build(ctx), - ) - .child( - TextBlock::new() - .attach(Grid::row(2)) - .attach(Grid::column(0)) - .text(("info_text", id)) - .build(ctx), - ) - .build(ctx), - ) - } -} - -fn main() { - Application::from_name("orbtk-settings") - .window(|ctx| { - Window::new() - .title("OrbTk - settings example") - .position((100.0, 100.0)) - .size(420.0, 730.0) - .child(MainView::new().margin(4.0).build(ctx)) - .build(ctx) - }) - .run(); -} - -// helper to request MainViewState -fn state<'a>(id: Entity, states: &'a mut StatesContext) -> &'a mut MainViewState { - states.get_mut(id) -} diff --git a/frontend/examples/stack.rs b/frontend/examples/stack.rs deleted file mode 100644 index 57cac5f..0000000 --- a/frontend/examples/stack.rs +++ /dev/null @@ -1,112 +0,0 @@ -use orbtk::prelude::*; - -widget!(MainView); - -impl Template for MainView { - fn template(self, _: Entity, ctx: &mut BuildContext) -> Self { - self.name("MainView").child( - Stack::create() - .child( - TextBlock::create() - .margin((0.0, 0.0, 0.0, 8.0)) - .text("Stack vertical") - .element("h1") - .build(ctx), - ) - .child( - Stack::create() - .spacing(4.0) - .child( - Button::create() - .class("single_content") - .text("left") - .horizontal_alignment("start") - .build(ctx), - ) - .child( - Button::create() - .class("single_content") - .text("center") - .horizontal_alignment("center") - .build(ctx), - ) - .child( - Button::create() - .class("single_content") - .text("stretch") - .horizontal_alignment("stretch") - .build(ctx), - ) - .child( - Button::create() - .class("single_content") - .text("right") - .horizontal_alignment("end") - .build(ctx), - ) - .build(ctx), - ) - .child( - TextBlock::create() - .margin((0.0, 0.0, 0.0, 8.0)) - .text("Stack horizontal") - .element("h1") - .build(ctx), - ) - .child( - Stack::create() - .orientation("horizontal") - .spacing(4.0) - .height(100.0) - .child( - Button::create() - .class("single_content") - .text("top") - .vertical_alignment("start") - .build(ctx), - ) - .child( - Button::create() - .class("single_content") - .text("center") - .vertical_alignment("center") - .build(ctx), - ) - .child( - Button::create() - .class("single_content") - .height(0.0) - .text("stretch") - .vertical_alignment("stretch") - .build(ctx), - ) - .child( - Button::create() - .class("single_content") - .text("bottom") - .vertical_alignment("end") - .build(ctx), - ) - .build(ctx), - ) - .build(ctx), - ) - } -} - -fn main() { - // use this only if you want to run it as web application. - orbtk::initialize(); - - Application::new() - .window(|ctx| { - Window::create() - .title("OrbTk - stack example") - .position((100.0, 100.0)) - .size(420.0, 730.0) - .resizeable(true) - .child(MainView::create().margin(4.0).build(ctx)) - .build(ctx) - }) - .run(); -} diff --git a/frontend/examples/todo/main.rs b/frontend/examples/todo/main.rs deleted file mode 100644 index a132056..0000000 --- a/frontend/examples/todo/main.rs +++ /dev/null @@ -1,68 +0,0 @@ -mod state; - -use self::state::{AppState, Event}; - -use orbtk::prelude::*; - -widget! { - MainView { - orientation: Orientation, - spacing: f64 - } -} - -impl Template for MainView { - fn template(mut self, id: Entity, ctx: &mut BuildContext) -> Self { - let entry = TextBox::create() - .vertical_alignment(Alignment::End) - .on_activate(move |ctxt, entity| { - ctxt.get_mut::(id).send(Event::Create(entity)); - }) - .build(ctx); - - let notes = Stack::create() - .orientation(Orientation::Vertical) - .spacing(4) - .build(ctx); - - self.state.notes = notes; - - let scroll_viewer = ScrollViewer::create() - .scroll_viewer_mode(("disabled", "auto")) - .child(notes) - .build(ctx); - - self.name("main-view") - .orientation(Orientation::Vertical) - .margin(4) - .child( - Container::create() - .child(scroll_viewer) - .child( - ScrollIndicator::create() - .padding(2.0) - .scroll_offset(scroll_viewer) - .build(ctx), - ) - .build(ctx) - ) - .child(entry) - } - - fn layout(&self) -> Box { - Box::new(StackLayout::new()) - } -} - -fn main() { - Application::new() - .window(|ctx| { - Window::create() - .title("Orbital To Do") - .position((500.0, 500.0)) - .size(400.0, 400.0) - .child(MainView::create().build(ctx)) - .build(ctx) - }) - .run(); -} diff --git a/frontend/examples/todo/state.rs b/frontend/examples/todo/state.rs deleted file mode 100644 index 44e0419..0000000 --- a/frontend/examples/todo/state.rs +++ /dev/null @@ -1,92 +0,0 @@ -use orbtk::prelude::*; - -use std::collections::VecDeque; - -#[derive(Debug)] -pub enum Event { - Create(Entity), - Delete(Entity), -} - -#[derive(AsAny, Default)] -pub struct AppState { - events: VecDeque, - pub notes: Entity, - count: u32, -} - -impl AppState { - fn append_note(&self, ctx: &mut Context, copy: String) { - let id = ctx.entity; - let bctx = &mut ctx.build_context(); - let text = TextBox::create().text(copy); - - let container = Stack::create() - .orientation(Orientation::Horizontal) - .vertical_alignment(Alignment::Start) - .child(text.build(bctx)) - .build(bctx); - - let button = Button::create() - .horizontal_alignment(Alignment::End) - .text("Delete") - .on_click(move |ctxt, _| { - ctxt.get_mut::(id) - .events - .push_back(Event::Delete(container)); - - true - }) - .build(bctx); - - bctx.append_child(container, button); - bctx.append_child(self.notes, container); - } - - fn fetch_text(ctx: &mut Context, entity: Entity) -> Option { - let mut widget = ctx.get_widget(entity); - - let entry = widget.get_mut::("text"); - if entry.is_empty() { - return None; - } - - let copy = entry.to_string(); - entry.clear(); - Some(copy) - } - - pub fn send(&mut self, event: Event) { - self.events.push_back(event); - } -} - -impl State for AppState { - fn update(&mut self, _: &mut Registry, ctx: &mut Context) { - if let Some(event) = self.events.pop_front() { - match event { - // Create and append the note to the UI. - Event::Create(entity) => { - if let Some(copy) = Self::fetch_text(ctx, entity) { - self.append_note(ctx, copy); - let count = self.count + 1; - self.count = count; - if count == 1 { - ctx.widget().set::("spacing", 12.0); - } - } - } - - // Delete the note of the given ID from the UI. - Event::Delete(id) => { - ctx.remove_child_from(id, self.notes); - let count = self.count - 1; - self.count = count; - if count == 0 { - ctx.widget().set::("spacing", 0.0); - } - } - } - } - } -} diff --git a/frontend/examples/widget.rs b/frontend/examples/widget.rs deleted file mode 100644 index 8e29646..0000000 --- a/frontend/examples/widget.rs +++ /dev/null @@ -1,15 +0,0 @@ -// source: https://gitlab.redox-os.org/redox-os/orbtk/tree/develop -use orbtk::prelude::*; - -fn main() { - Application::new() - .window(|ctx| { - Window::create() - .title("OrbTk - minimal example") - .position((100.0, 100.0)) - .size(420.0, 730.0) - .child(TextBlock::create().text("OrbTk").build(ctx)) - .build(ctx) - }) - .run(); -} diff --git a/frontend/examples/widgets.rs b/frontend/examples/widgets.rs deleted file mode 100644 index 3b07b79..0000000 --- a/frontend/examples/widgets.rs +++ /dev/null @@ -1,478 +0,0 @@ -use std::collections::HashSet; - -use orbtk::prelude::*; - -#[derive(Debug, Copy, Clone)] -enum Action { - AddItem, - ClearText, - EntryActivated(Entity), - EntryChanged(Entity), - ValueChanged(Entity), - IncrementCounter, - RemoveItem, -} - -#[derive(AsAny)] -pub struct MainViewState { - action: Option, -} - -impl Default for MainViewState { - fn default() -> Self { - MainViewState { action: None } - } -} - -impl MainViewState { - fn action(&mut self, action: impl Into>) { - self.action = action.into(); - } -} - -impl State for MainViewState { - fn update(&mut self, _: &mut Registry, ctx: &mut Context<'_>) { - if let Some(action) = self.action { - match action { - Action::AddItem => { - let len = ctx.widget().get::("list").len(); - if len < 5 { - ctx.widget() - .get_mut::("list") - .push(format!("Item {}", len + 1)); - ctx.child("items").set("count", len + 1); - ctx.child("remove-item-button").set("enabled", true); - - if len == 4 { - ctx.child("add-item-button").set("enabled", false); - } - } - } - Action::RemoveItem => { - let len = ctx.widget().get::("list").len(); - if len > 0 { - ctx.widget().get_mut::("list").remove(len - 1); - ctx.child("items").set("count", len - 1); - ctx.child("add-item-button").set("enabled", true); - - if len == 1 { - ctx.child("remove-item-button").set("enabled", false); - } - } - } - Action::IncrementCounter => { - *ctx.widget().get_mut::("counter") += 1; - - let counter = *ctx.widget().get::("counter"); - - ctx.widget().set( - "result", - String16::from(format!("Button count: {}", counter)), - ); - } - Action::ClearText => { - ctx.widget().set("text_one", String16::from("")); - ctx.widget().set("text_two", String16::from("")); - } - Action::EntryActivated(entity) => { - let mut widget = ctx.get_widget(entity); - let text = widget.get_mut::("text"); - println!("submitting {}", text); - text.clear(); - } - Action::EntryChanged(entity) => { - let widget = ctx.get_widget(entity); - let text = widget.get::("text"); - println!("entry changed: {}", text); - } - Action::ValueChanged(entity) => { - let val = - ((*ctx.get_widget(entity).get::("val")).floor() as i32).to_string(); - ctx.child("value_text").set("text", String16::from(val)); - } - } - - self.action = None; - } - } - - fn update_post_layout(&mut self, _: &mut Registry, ctx: &mut Context<'_>) { - let mut selection_string = "Selected:".to_string(); - - for index in &ctx.widget().get::("selected_indices").0 { - selection_string = format!("{} {}", selection_string, index); - } - - ctx.child("selection") - .set("text", String16::from(selection_string)); - } -} - -fn create_header(ctx: &mut BuildContext, text: &str) -> Entity { - TextBlock::new() - .text(text) - .element("text-block") - .class("h1") - .build(ctx) -} - -type List = Vec; - -widget!( - MainView { - selected_indices: SelectedIndices, - counter: usize, - list_count: usize, - combo_box_list_count: usize, - list: List, - selection_list: List, - combo_box_list: List, - selection_list_count: usize, - text_one: String16, - text_two: String16, - result: String16 - } -); - -impl Template for MainView { - fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { - self.name("MainView") - .result("Button count: 0") - .counter(0) - .selected_indices(HashSet::new()) - .list(vec![ - "Item 1".to_string(), - "Item 2".to_string(), - "Item 3".to_string(), - ]) - .list_count(3) - .selection_list(vec![ - "Item 1".to_string(), - "Item 2".to_string(), - "Item 3".to_string(), - "Item 4".to_string(), - "Item 5".to_string(), - "Item 6".to_string(), - "Item 7".to_string(), - "Item 8".to_string(), - "Item 9".to_string(), - "Item 10".to_string(), - ]) - .combo_box_list(vec![ - "CB 1".to_string(), - "CB 2".to_string(), - "CB 3".to_string(), - "CB 4".to_string(), - "CB 5".to_string(), - "CB 6".to_string(), - "CB 7".to_string(), - "CB 8".to_string(), - "CB 9".to_string(), - "CB 10".to_string(), - ]) - .selection_list_count(10) - .combo_box_list_count(10) - .child( - Grid::new() - .margin(8.0) - .columns( - Columns::new() - .add(132.0) - .add(16.0) - .add(132.0) - .add(16.0) - .add(132.0), - ) - .child( - Stack::new() - .attach(Grid::column(0)) - // Column 0 - .child(create_header(ctx, "Buttons")) - .child( - Button::new() - .text("Button") - .margin((0.0, 8.0, 0.0, 0.0)) - .icon(material_font_icons::CHECK_FONT_ICON) - .attach(Grid::column(0)) - .attach(Grid::row(1)) - .on_click(move |states, _| { - state(id, states).action(Action::IncrementCounter); - true - }) - .build(ctx), - ) - .child( - Button::new() - .text("Primary") - .element("button") - .class("primary") - .margin((0.0, 8.0, 0.0, 0.0)) - .icon(material_font_icons::CHECK_FONT_ICON) - .attach(Grid::column(0)) - .attach(Grid::row(2)) - .build(ctx), - ) - .child( - ToggleButton::new() - .class("single_content") - .text("ToggleButton") - .margin((0.0, 8.0, 0.0, 0.0)) - .attach(Grid::column(0)) - .attach(Grid::row(3)) - .build(ctx), - ) - .child( - CheckBox::new() - .text("CheckBox") - .margin((0.0, 8.0, 0.0, 0.0)) - .attach(Grid::column(0)) - .attach(Grid::row(4)) - .build(ctx), - ) - .child( - Switch::new() - .margin((0.0, 8.0, 0.0, 0.0)) - .attach(Grid::column(0)) - .attach(Grid::row(5)) - .build(ctx), - ) - .child( - TextBlock::new() - .margin((0.0, 8.0, 0.0, 0.0)) - .element("h1") - .id("value_text") - .text("0") - .h_align("center") - .build(ctx), - ) - .child( - Slider::new() - .on_changed(move |states, entity| { - state(id, states).action(Action::ValueChanged(entity)); - }) - .build(ctx), - ) - .build(ctx), - ) - .child( - Stack::new() - .attach(Grid::column(2)) - .child(create_header(ctx, "Text")) - .child( - TextBlock::new() - .class("body") - .text(("result", id)) - .margin((0.0, 8.0, 0.0, 0.0)) - .attach(Grid::column(2)) - .attach(Grid::row(1)) - .build(ctx), - ) - .child( - TextBox::new() - .water_mark("TextBox...") - .text(("text_one", id)) - .margin((0.0, 8.0, 0.0, 0.0)) - .attach(Grid::column(2)) - .attach(Grid::row(2)) - .on_activate(move |states, entity| { - state(id, states).action(Action::EntryActivated(entity)); - }) - .on_changed(move |states, entity| { - state(id, states).action(Action::EntryChanged(entity)); - }) - .build(ctx), - ) - .child( - TextBox::new() - .water_mark("TextBox...") - .text(("text_two", id)) - .margin((0.0, 8.0, 0.0, 0.0)) - .attach(Grid::column(2)) - .attach(Grid::row(2)) - .on_activate(move |states, entity| { - state(id, states).action(Action::EntryActivated(entity)); - }) - .on_changed(move |states, entity| { - state(id, states).action(Action::EntryChanged(entity)); - }) - .build(ctx), - ) - .child( - Button::new() - .margin((0.0, 8.0, 0.0, 0.0)) - .class("single_content") - .text("clear text") - .on_click(move |states, _| { - state(id, states).action(Action::ClearText); - true - }) - .build(ctx), - ) - .child( - NumericBox::new() - .margin((0.0, 8.0, 0.0, 0.0)) - .max(123.0) - .step(0.123) - .val(0.123) - .build(ctx), - ) - .build(ctx), - ) - .child( - Grid::new() - .rows( - Rows::new() - .add("auto") - .add(32.0) - .add(16.0) - .add(204.0) - .add("auto") - .add(192.0) - .add("auto"), - ) - .columns(Columns::new().add("*").add(4.0).add("*")) - .attach(Grid::column(4)) - .child( - TextBlock::new() - .text("Items") - .element("text-block") - .class("h1") - .attach(Grid::column(0)) - .attach(Grid::column_span(3)) - .attach(Grid::row(0)) - .build(ctx), - ) - .child( - ComboBox::new() - .items_builder(move |bc, index| { - let text = bc - .get_widget(id) - .get::>("combo_box_list")[index] - .clone(); - TextBlock::new() - .margin((0.0, 0.0, 0.0, 2.0)) - .v_align("center") - .text(text) - .build(bc) - }) - .selected_index(0) - .attach(Grid::column(0)) - .attach(Grid::column_span(3)) - .attach(Grid::row(1)) - .margin((0.0, 8.0, 0.0, 0.0)) - .count(("combo_box_list_count", id)) - .build(ctx), - ) - .child( - ItemsWidget::new() - .element("items-widget") - .id("items") - .padding((4.0, 4.0, 4.0, 2.0)) - .attach(Grid::column(0)) - .attach(Grid::column_span(3)) - .attach(Grid::row(3)) - .margin((0.0, 0.0, 0.0, 8.0)) - .items_builder(move |bc, index| { - let text = bc.get_widget(id).get::>("list") - [index] - .clone(); - - Button::new() - .margin((0.0, 0.0, 0.0, 2.0)) - .text(text) - .build(bc) - }) - .count(("list_count", id)) - .build(ctx), - ) - .child( - Button::new() - .element("button") - .class("single_content") - .id("remove-item-button") - .icon(material_font_icons::MINUS_FONT_ICON) - .on_click(move |states, _| { - state(id, states).action(Action::RemoveItem); - true - }) - .min_width(0.0) - .attach(Grid::column(0)) - .attach(Grid::row(4)) - .build(ctx), - ) - .child( - Button::new() - .element("button") - .class("single_content") - .id("add-item-button") - .icon(material_font_icons::ADD_FONT_ICON) - .on_click(move |states, _| { - state(id, states).action(Action::AddItem); - true - }) - .min_width(0.0) - .attach(Grid::column(2)) - .attach(Grid::row(4)) - .build(ctx), - ) - .child( - ListView::new() - .attach(Grid::column(0)) - .attach(Grid::column_span(3)) - .attach(Grid::row(5)) - .selected_indices(id) - .margin((0.0, 16.0, 0.0, 8.0)) - .items_builder(move |bc, index| { - let text = bc - .get_widget(id) - .get::>("selection_list")[index] - .clone(); - TextBlock::new() - .margin((0.0, 0.0, 0.0, 2.0)) - .v_align("center") - .text(text) - .build(bc) - }) - .count(("selection_list_count", id)) - .build(ctx), - ) - .child( - // todo: wrong text width???? - TextBlock::new() - .element("text-block") - .id("selection") - .max_width(120.0) - .attach(Grid::column(0)) - .attach(Grid::column_span(3)) - .attach(Grid::row(6)) - .text("Selected:") - .build(ctx), - ) - .build(ctx), - ) - .build(ctx), - ) - } -} - -fn main() { - // use this only if you want to run it as web application. - orbtk::initialize(); - - Application::new() - .window(|ctx| { - Window::new() - .title("OrbTk - widgets example") - .position((100.0, 100.0)) - .size(468.0, 730.0) - .resizeable(true) - .child(MainView::new().build(ctx)) - .build(ctx) - }) - .run(); -} - -// helper to request MainViewState -fn state<'a>(id: Entity, states: &'a mut StatesContext) -> &'a mut MainViewState { - states.get_mut(id) -} diff --git a/frontend/examples/widgets.rs-0.3.1-alpha1 b/frontend/examples/widgets.rs-0.3.1-alpha1 deleted file mode 100644 index 55c1e19..0000000 --- a/frontend/examples/widgets.rs-0.3.1-alpha1 +++ /dev/null @@ -1,415 +0,0 @@ -use std::{ - collections::HashSet, -}; - -use orbtk::prelude::*; - -#[derive(Debug, Copy, Clone)] -enum Action { - AddItem, - ClearText, - EntryActivated(Entity), - EntryChanged(Entity), - IncrementCounter, - RemoveItem, -} - -#[derive(AsAny)] -pub struct MainViewState { - action: Option, -} - -impl Default for MainViewState { - fn default() -> Self { - MainViewState { - action: None, - } - } -} - -impl MainViewState { - fn action(&mut self, action: impl Into>) { - self.action = action.into(); - } -} - -impl State for MainViewState { - fn update(&mut self, _: &mut Registry, ctx: &mut Context<'_>) { - if let Some(action) = self.action { - match action { - Action::AddItem => { - let len = ctx.widget().get::("list").len(); - if len < 5 { - ctx.widget() - .get_mut::("list") - .push(format!("Item {}", len + 1)); - ctx.child("items").set("count", len + 1); - ctx.child("remove-item-button").set("enabled", true); - - if len == 4 { - ctx.child("add-item-button").set("enabled", false); - } - } - } - Action::RemoveItem => { - let len = ctx.widget().get::("list").len(); - if len > 0 { - ctx.widget().get_mut::("list").remove(len - 1); - ctx.child("items").set("count", len - 1); - //ctx.child("add-item-button").set("enabled", true); - - if len == 1 { - ctx.child("remove-item-button").set("enabled", false); - } - } - } - Action::IncrementCounter => { - *ctx.widget().get_mut::("counter") += 1; - - let counter = *ctx.widget().get::("counter"); - - ctx.widget().set( - "result", - String16::from(format!("Button count: {}", counter)), - ); - } - Action::ClearText => { - ctx.widget().set("text_one", String16::from("")); - ctx.widget().set("text_two", String16::from("")); - } - Action::EntryActivated(entity) => { - let mut widget = ctx.get_widget(entity); - let text = widget.get_mut::("text"); - println!("submitting {}", text); - text.clear(); - } - Action::EntryChanged(entity) => { - let widget = ctx.get_widget(entity); - let text = widget.get::("text"); - println!("entry changed: {}", text); - } - } - - self.action = None; - } - } - - fn update_post_layout(&mut self, _: &mut Registry, ctx: &mut Context<'_>) { - let mut selection_string = "Selected:".to_string(); - - for index in &ctx.widget().get::("selected_indices").0 { - selection_string = format!("{} {}", selection_string, index); - } - - ctx.child("selection") - .set("text", String16::from(selection_string)); - } -} - -fn create_header(ctx: &mut BuildContext, text: &str) -> Entity { - TextBlock::create() - .text(text) - .selector(Selector::new().with("text-block").class("h1")) - .build(ctx) -} - -type List = Vec; - -widget!( - MainView { - selected_indices: SelectedIndices, - counter: usize, - list_count: usize, - list: List, - selection_list: List, - selection_list_count: usize, - text_one: String16, - text_two: String16, - result: String16 - } -); - -impl Template for MainView { - fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { - self.name("MainView") - .result("Button count: 0") - .counter(0) - .selected_indices(HashSet::new()) - .list(vec![ - "Item 1".to_string(), - "Item 2".to_string(), - "Item 3".to_string(), - ]) - .list_count(3) - .selection_list(vec![ - "Item 1".to_string(), - "Item 2".to_string(), - "Item 3".to_string(), - "Item 4".to_string(), - "Item 5".to_string(), - "Item 6".to_string(), - "Item 7".to_string(), - "Item 8".to_string(), - "Item 9".to_string(), - "Item 10".to_string(), - ]) - .selection_list_count(10) - .child( - Grid::create() - .margin(8.0) - .columns( - Columns::create() - .column(132.0) - .column(16.0) - .column(132.0) - .column(16.0) - .column(132.0) - .build(), - ) - .child( - Stack::create() - .attach(Grid::column(0)) - // Column 0 - .child(create_header(ctx, "Buttons")) - .child( - Button::create() - .text("Button") - .margin((0.0, 8.0, 0.0, 0.0)) - .icon(material_font_icons::CHECK_FONT_ICON) - .attach(Grid::column(0)) - .attach(Grid::row(1)) - .on_mouse_move(move |states, _| { - println!("ABc"); - true - }) - .on_click(move |states, _| { - state(id, states).action(Action::IncrementCounter); - true - }) - .build(ctx), - ) - .child( - Button::create() - .text("Primary") - .selector(Selector::new().with("button").class("primary")) - .margin((0.0, 8.0, 0.0, 0.0)) - .icon(material_font_icons::CHECK_FONT_ICON) - .attach(Grid::column(0)) - .attach(Grid::row(2)) - .build(ctx), - ) - .child( - ToggleButton::create() - .text("ToggleButton") - .margin((0.0, 8.0, 0.0, 0.0)) - .attach(Grid::column(0)) - .attach(Grid::row(3)) - .build(ctx), - ) - .child( - CheckBox::create() - .text("CheckBox") - .margin((0.0, 8.0, 0.0, 0.0)) - .attach(Grid::column(0)) - .attach(Grid::row(4)) - .build(ctx), - ) - .child( - Switch::create() - .margin((0.0, 8.0, 0.0, 0.0)) - .attach(Grid::column(0)) - .attach(Grid::row(5)) - .build(ctx), - ) - .build(ctx), - ) - .child( - Stack::create() - .attach(Grid::column(2)) - .child(create_header(ctx, "Text")) - .child( - TextBlock::create() - .selector(Selector::new().class("body")) - .text(("result", id)) - .margin((0.0, 8.0, 0.0, 0.0)) - .attach(Grid::column(2)) - .attach(Grid::row(1)) - .build(ctx), - ) - .child( - TextBox::create() - .water_mark("TextBox...") - .text(("text_one", id)) - .margin((0.0, 8.0, 0.0, 0.0)) - .attach(Grid::column(2)) - .attach(Grid::row(2)) - .on_activate(move |states, entity| { - state(id, states).action(Action::EntryActivated(entity)); - }) - .on_changed(move |states, entity| { - state(id, states).action(Action::EntryChanged(entity)); - }) - .build(ctx), - ) - .child( - TextBox::create() - .water_mark("TextBox...") - .text(("text_two", id)) - .margin((0.0, 8.0, 0.0, 0.0)) - .attach(Grid::column(2)) - .attach(Grid::row(2)) - .on_activate(move |states, entity| { - state(id, states).action(Action::EntryActivated(entity)); - }) - .on_changed(move |states, entity| { - state(id, states).action(Action::EntryChanged(entity)); - }) - .build(ctx), - ) - .child( - Button::create() - .margin((0.0, 8.0, 0.0, 0.0)) - .text("clear text") - .on_click(move |states, _| { - state(id, states).action(Action::ClearText); - true - }) - .build(ctx), - ) - .build(ctx), - ) - .child( - Grid::create() - .rows( - Rows::create() - .row("auto") - .row(192.0) - .row("auto") - .row(192.0) - .row("auto") - .build(), - ) - .columns( - Columns::create() - .column("*") - .column(4.0) - .column("*") - .build(), - ) - .attach(Grid::column(4)) - .child( - TextBlock::create() - .text("Items") - .selector(Selector::new().with("text-block").class("h1")) - .attach(Grid::column(0)) - .attach(Grid::column_span(3)) - .attach(Grid::row(0)) - .build(ctx), - ) - .child( - ItemsWidget::create() - .selector(Selector::from("items-widget").id("items")) - .padding((4.0, 4.0, 4.0, 2.0)) - .attach(Grid::column(0)) - .attach(Grid::column_span(3)) - .attach(Grid::row(1)) - .margin((0.0, 8.0, 0.0, 8.0)) - .items_builder(move |bc, index| { - let text = bc.get_widget(id).get::>("list") - [index] - .clone(); - - Button::create() - .margin((0.0, 0.0, 0.0, 2.0)) - .text(text) - .build(bc) - }) - .count(("list_count", id)) - .build(ctx), - ) - .child( - Button::create() - .selector(Selector::from("button").id("remove-item-button")) - .icon(material_font_icons::MINUS_FONT_ICON) - .on_click(move |states, _| { - state(id, states).action(Action::RemoveItem); - true - }) - .min_width(0.0) - .attach(Grid::column(0)) - .attach(Grid::row(2)) - .build(ctx), - ) - .child( - Button::create() - .selector(Selector::from("button").id("add-item-button")) - .icon(material_font_icons::ADD_FONT_ICON) - .on_click(move |states, _| { - state(id, states).action(Action::AddItem); - true - }) - .min_width(0.0) - .attach(Grid::column(2)) - .attach(Grid::row(2)) - .build(ctx), - ) - .child( - ListView::create() - .attach(Grid::column(0)) - .attach(Grid::column_span(3)) - .attach(Grid::row(3)) - .selected_indices(id) - .margin((0.0, 16.0, 0.0, 8.0)) - .items_builder(move |bc, index| { - let text = bc - .get_widget(id) - .get::>("selection_list")[index] - .clone(); - TextBlock::create() - .margin((0.0, 0.0, 0.0, 2.0)) - .vertical_alignment("center") - .text(text) - .build(bc) - }) - .count(("selection_list_count", id)) - .build(ctx), - ) - .child( - // todo: wrong text width???? - TextBlock::create() - .selector(Selector::from("text-block").id("selection")) - .max_width(120.0) - .attach(Grid::column(0)) - .attach(Grid::column_span(3)) - .attach(Grid::row(4)) - .text("Selected:") - .build(ctx), - ) - .build(ctx), - ) - .build(ctx), - ) - } -} - -fn main() { - // use this only if you want to run it as web application. - orbtk::initialize(); - - Application::new() - .window(|ctx| { - Window::create() - .title("OrbTk - widgets example") - .position((100.0, 100.0)) - .size(468.0, 730.0) - .resizeable(true) - .child(MainView::create().build(ctx)) - .build(ctx) - }) - .run(); -} - -// helper to request MainViewState -fn state<'a>(id: Entity, states: &'a mut StatesContext) -> &'a mut MainViewState { - states.get_mut(id) -}