From 88b9ef5115f78e5d38ee83fee83cb2bcf5eb824f Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Mon, 25 May 2026 17:34:45 +0200 Subject: [PATCH] add UiDoc reference to UiDocProxy callback --- application/src/note.rs | 3 +-- application/src/notebook.rs | 7 +++---- application/src/window.rs | 6 +++--- ui-rs/src/ui/toolkit.rs | 14 ++++++++++---- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/application/src/note.rs b/application/src/note.rs index ffc2e77..afac9db 100644 --- a/application/src/note.rs +++ b/application/src/note.rs @@ -19,10 +19,9 @@ impl Note { pub fn init_from_model(&mut self, model: &entity::note::Model) { self.text.set(model.content.as_str()); - let tab = match(model.kind) { + let tab = match model.kind { NoteType::PlainTextNote => NoteTypeTabView::TextArea, NoteType::MDTextNote => NoteTypeTabView::TextArea, - _ => NoteTypeTabView::Empty }; self.note_type.set(tab as i64); } diff --git a/application/src/notebook.rs b/application/src/notebook.rs index 40de6f4..5ceeacf 100644 --- a/application/src/notebook.rs +++ b/application/src/notebook.rs @@ -1,8 +1,7 @@ use ui_rs::{action, ui_actions, UiModel}; use ui_rs::ui::*; -use entity::note::{Model as Note, NoteType}; -use crate::window::NoteTypeTabView; +use entity::note::{Model as Note}; #[derive(UiModel, Default)] pub struct Notebook { @@ -34,7 +33,7 @@ impl Notebook { #[action] pub fn note_selected(&mut self, event: &ActionEvent) { - if let (EventType::ListSelection(s)) = event.event_type { + if let EventType::ListSelection(s) = event.event_type { if let Some(note) = s.selected_element(self.notes.data()) { // detach the current note if let Some(current) = &self.selected_note { @@ -43,7 +42,7 @@ impl Notebook { } // Create the new note - let mut note_data: crate::note::Note = Default::default(); + let note_data: crate::note::Note = Default::default(); // TODO: setting the text here is the right thing to do, but for some // reasons it doesn't work yet. Fix this shit. //note_data.text.set(note.content.as_str()); diff --git a/application/src/window.rs b/application/src/window.rs index b37b038..8534825 100644 --- a/application/src/window.rs +++ b/application/src/window.rs @@ -138,7 +138,7 @@ pub fn create_window(app: &App, ctx: &AppContext) -> UiObject { nb.set_notes(notes); @@ -168,7 +168,7 @@ pub fn create_window(app: &App, ctx: &AppContext) -> UiObject UiDoc { } } - pub fn new(mut data: T) -> UiDoc { + pub fn new(data: T) -> UiDoc { UiDoc::new2(data, |_,_| {}) } - pub fn new2(mut data: T, init: F) -> UiDoc + pub fn new2(data: T, init: F) -> UiDoc where F: FnOnce(&mut T, &UiDoc) { unsafe { let doc = ui_document_new(mem::size_of::<*mut T>()); @@ -468,12 +468,12 @@ impl UiDocProxy { } pub fn call_mainthread(self, f: F) - where F: FnOnce(&mut T) + Send + 'static { + where F: FnOnce(&UiDoc, &mut T) + Send + 'static { call_mainthread(|| { let doc: UiDoc = UiDoc::from_ptr(self.ptr); unsafe { let data = doc.get_data_ptr(); - f(&mut *data); + f(&doc, &mut *data); } drop(self); }); @@ -874,6 +874,12 @@ impl ListSelection { } None } + + pub fn count(&self) -> usize { + unsafe { + ui_list_selection_get_count(self.ptr) as usize + } + } } -- 2.47.3