]> uap-core.de Git - note.git/commitdiff
use new widget/container macros for the note window ui main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 24 Jul 2026 19:25:50 +0000 (21:25 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 24 Jul 2026 19:25:50 +0000 (21:25 +0200)
application/note/src/window.rs
ui-rs/src/ui/container.rs

index fed3a66a6fca134a71d86dd76d4e26ce99900c13..5f518d4cb480da1cb1477336d5c56aabc3fa01b3 100644 (file)
@@ -28,7 +28,7 @@
 
 use std::any::Any;
 use backend::backend::{BackendHandle, BroadcastMessage, NoteId};
-use ui_rs::{action, button, hbox, ui_actions, UiModel};
+use ui_rs::{action, button, grid, hbox, label, sidebar, sourcelist, tableview, tabview, textarea, textfield, ui_actions, UiModel};
 use ui_rs::ui::*;
 use crate::{App, AppStates};
 use entity::collection::{Model as Collection, Node};
@@ -195,13 +195,12 @@ pub fn create_window(app: &App, ctx: &AppContext<MainWindow>) -> UiObject<MainWi
         obj.ctx.set_state(AppStates::NoteEnableNew as i32);
 
         obj.sidebar_builder().create(|obj|{
-            obj.sourcelist(|b|{
-                b.fill(true);
-                b.value(&data.notebooks);
-                b.getvalue(|elm,_row,item|{
+            sourcelist!(obj,
+                fill = true, value = &data.notebooks,
+                getvalue = |elm,_row,item|{
                     item.label = Some(elm.data.name.clone());
-                });
-                b.onactivate(|e|{
+                },
+                onactivate = |e|{
                     if let EventType::SubList(sl) = &e.event_type {
                         if let Some(nb) = sl.get_mut_from(&mut e.data.notebooks) {
                             let nav = NavigationItem { collection_id: nb.data.collection_id, ..Default::default() };
@@ -220,8 +219,8 @@ pub fn create_window(app: &App, ctx: &AppContext<MainWindow>) -> UiObject<MainWi
                             e.data.navigation.push(nav);
                         }
                     }
-                });
-            });
+                }
+            );
         });
 
         obj.left_panel_builder().create(|obj|{
@@ -229,92 +228,43 @@ pub fn create_window(app: &App, ctx: &AppContext<MainWindow>) -> UiObject<MainWi
             model.add_column("Name", ColumnType::String, -1);
             model.add_column("Last Modified", ColumnType::String, 0);
 
-            obj.tableview_builder::<NoteItem>()
-                .varname("notes")
-                .model(&model)
-                .fill(true)
-                .getvalue(notelist_getvalue)
-                .onselection_action("note_selected")
-                .onactivate_action("note_activated")
-                .create();
+            tableview!(obj,
+                varname = "notes",
+                model = &model,
+                fill = true,
+                getvalue = notelist_getvalue,
+                onselection_action = "note_selected",
+                onactivate_action = "note_activated");
         });
 
         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.label(|l|{
-                            l.margin(4);
-                            l.varname("note_info");
-                            l.visibility_states(&[AppStates::NoteShowInfo as i32]);
-                        });
+            tabview!(obj, fill = true, tabview_type = TabViewType::Invisible, varname = "note_type", |tabview|{
+                tabview.tab("empty", |_obj| {});
 
-                        obj.hbox_builder()
-                            .visibility_states(&[AppStates::NoteShowExtModInfo as i32])
-                            .spacing(4)
-                            .create(|obj|{
-                            obj.label(|l|{
-                                l.label("The note has been modified by an external program");
-                                l.fill(true);
-                            });
-                            obj.button(|b|{
-                                b.label("Reload");
-                                b.action("note_reload");
-                            });
-                            obj.button(|b|{
-                                b.label("Close");
-                                b.action("note_extmod_close");
-                            });
-                        });
+                tabview.tab("textnote", |obj| {
+                    label!(obj, margin = 4, varname = "note_info", visibility_states = &[AppStates::NoteShowInfo as i32]);
 
-                        let textarea = obj.textarea(|b|{
-                           b.fill(true);
-                            b.varname("note_text");
-                            b.onchange_action("note_text_change");
-                            b.ontextchanged_action("note_text_changed");
-                        });
-                        obj.ctx.add_action_untyped("textarea_focus", move|_event|{
-                            textarea.focus();
-                        });
+                    hbox!(obj, visibility_states = &[AppStates::NoteShowExtModInfo as i32], spacing = 4, |obj|{
+                        label!(obj, fill = true, label = "The note has been modified by an external program");
+                        button!(obj, label = "Reload", action = "note_reload");
+                        button!(obj, label = "Close", action = "note_extmod_close");
                     });
+                    let textarea = textarea!(obj, fill = true, varname = "note_text", onchange_action = "note_text_change", ontextchanged_action = "note_text_changed");
+                    obj.ctx.add_action_untyped("textarea_focus", move|_event|{
+                        textarea.focus();
+                    });
+                });
 
-                    tabview.tab("file", |obj| {
-                        obj.grid(
-                            |g|{
-                                g.fill(true);
-                                g.margin(8);
-                                g.columnspacing(8);
-                                g.rowspacing(8);
-                                g.def_vfill(true);
-                            },
-                            |obj|{
-                                obj.grid_row(|obj|{
-                                    obj.rlabel(|l|{
-                                        l.label("Name");
-                                    });
-                                    obj.textfield(|t|{
-                                        t.hexpand(true);
-                                        t.hfill(true);
-                                        t.varname("note_nodename");
-                                        t.onchange_action("note_nodename_change");
-                                    });
-                                    button!(obj, label = "Open", action = "open_extern");
-                                });
-
-                                hbox!(obj, spacing = 10, |obj| {
-
-                                });
-                            }
-                        );
+                tabview.tab("file", |obj| {
+                    grid!(obj, fill = true, margin = 8, columnspacing = 8, rowspacing = 8, def_vfill = true, |g|{
+                        g.grid_row(|obj|{
+                            label!(obj, label = "Name");
+                            textfield!(obj, hexpand = true, hfill = true, varname = "note_nodename", onchange_action = "note_nodename_change");
+                            button!(obj, label = "Open", action = "open_extern");
+                        });
                     });
                 });
+            });
         });
     });
 
index c2025a6bb2a3b47f1259b9a8df81a8dcf55cf994..5dca705f677c51eb296adac04146168aa43b4bfe 100644 (file)
@@ -188,6 +188,22 @@ macro_rules! right_panel {
     }};
 }
 
+#[macro_export]
+macro_rules! tabview {
+    (
+        $parent:expr
+        $(, $name:ident = $value:expr )*
+        ,
+        |$child:ident| $body:block
+    ) => {{
+        $parent.tabview_builder()
+            $(.$name($value))*
+            .create(|$child| $body)
+    }};
+}
+
+
+
 macro_rules! container_fn {
     ($fn_name:ident, $builder_fn:ident, $builder_ty:ident) => {
         pub fn $fn_name<F, U>(&mut self, build: F, ui: U)