From 29815fd9c8b736b135b42c9ca6594adff362a182 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Fri, 24 Apr 2026 18:03:35 +0200 Subject: [PATCH] add base window ui --- application/src/main.rs | 100 +++++++++++++++----------------------- application/src/window.rs | 88 +++++++++++++++++++++++++++++++++ ui-rs/src/ui/mod.rs | 1 + 3 files changed, 127 insertions(+), 62 deletions(-) create mode 100644 application/src/window.rs diff --git a/application/src/main.rs b/application/src/main.rs index e9f90ff..eb9801f 100644 --- a/application/src/main.rs +++ b/application/src/main.rs @@ -1,76 +1,52 @@ -use ui_rs::{action, ui, ui_actions, UiModel}; +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2026 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +mod window; + +use ui_rs::{ui}; use ui_rs::ui::*; +use crate::window::*; fn main() { ui::app_init("note"); let mut app = App; - ui::app_run::(&mut app); + ui::app_run::(&mut app); } struct App; -#[derive(UiModel, Default)] -struct TestData { - i: i32, - #[bind("list")] - list: UiList, - #[bind("source")] - sublists: UiSourceList -} - -#[ui_actions] -impl TestData { - #[action] - pub fn my_action(&mut self, _event: &ActionEvent) { - println!("my action {}", self.i); - self.i += 1; - } -} - -fn create_window(app: &AppContext) { - let testdata: TestData = Default::default(); - - let window = app.window("note", testdata, |obj, data| { - let list = data.list.data(); - list.push(10); - list.push(11); - list.push(12); - - let mut sl = SubList::new(); - sl.set_header("Header"); - sl.data().push(String::from("Elm 1")); - sl.data().push(String::from("Elm 2")); - - data.sublists.push(sl); - - - obj.button_builder().label("Hello").onclick(|e| { - println!("Button clicked: {}", e.data.i); - e.data.i += 1; - }).create(); - obj.button_builder().label("Action").action("my_action").create(); - //let mut model = TableModel::new(); - //model.add_column("Name", ColumnType::String, -1); - //obj.tableview_builder::().fill(true).varname("list").model(&model).getvalue(|elm, _row, _col| { - // ListValue::String(elm.to_string()) - //}).create(); - obj.sourcelist_builder::().fill(true).value(&data.sublists).getvalue(|elm, index, item| { - item.label = Some(elm.to_string()); - item.badge = Some(index.to_string()); - }).create(); - - println!("test"); - }); - - window.show(); -} -impl Application for App { - fn on_startup(&mut self, app: &AppContext) { - app.menu("File", |menu| { - menu.item("Open").create(); - }); +impl Application for App { + fn on_startup(&mut self, app: &AppContext) { + //app.menu("File", |menu| { + // menu.item("Open").create(); + //}); create_window(app); } diff --git a/application/src/window.rs b/application/src/window.rs new file mode 100644 index 0000000..a83100d --- /dev/null +++ b/application/src/window.rs @@ -0,0 +1,88 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2026 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +use ui_rs::{action, ui_actions, UiModel}; +use ui_rs::ui::*; + +#[derive(UiModel, Default)] +pub struct MainWindow { + #[bind] + notebooks: UiSourceList +} + +#[ui_actions] +impl MainWindow { + #[action] + pub fn my_action(&mut self, _event: &ActionEvent) { + + } +} + +pub fn create_window(app: &AppContext) { + let windowdata: MainWindow = Default::default(); + + let window = app.splitview_window("note", true, windowdata, |obj, data| { + obj.sidebar_builder().create(|obj|{ + obj.sourcelist(|b|{ + b.fill(true); + b.value(&data.notebooks); + }); + }); + + obj.left_panel_builder().create(|obj|{ + let mut model = TableModel::new(); + model.add_column("Name", ColumnType::String, -1); + model.add_column("Last Modified", ColumnType::String, 0); + + obj.tableview_builder::() + .varname("notes") + .fill(true) + .create(); + }); + + obj.right_panel_builder().create(|obj|{ + obj.tabview( + |b|{ + b.fill(true); + b.tabview_type(TabViewType::Invisible); + b.varname("note_type"); + }, + |tabview| { + tabview.tab("empty", |_obj| {}); + + tabview.tab("textnote", |obj| { + obj.textarea(|b|{ + b.fill(true); + }); + }); + }); + }) + }); + + window.show(); +} \ No newline at end of file diff --git a/ui-rs/src/ui/mod.rs b/ui-rs/src/ui/mod.rs index 788c9d4..d912af0 100644 --- a/ui-rs/src/ui/mod.rs +++ b/ui-rs/src/ui/mod.rs @@ -41,6 +41,7 @@ mod toolbar; pub use toolkit::*; pub use event::*; +pub use container::*; pub use application::*; pub use window::*; pub use button::*; -- 2.47.3