]> uap-core.de Git - note.git/commitdiff
implement list selection functions
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 16 Apr 2026 06:35:32 +0000 (08:35 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 16 Apr 2026 06:35:32 +0000 (08:35 +0200)
ui-rs/src/ui/ffi.rs
ui-rs/src/ui/toolkit.rs

index 99eba46df7e942f8189485cf3dcf5519e63033b9..c75f4a7bb4efb0575fd80dd0980c6a05ca98f579 100644 (file)
@@ -47,6 +47,11 @@ pub struct UiList {
     _private: [u8; 0],
 }
 
+#[repr(C)]
+pub struct UiListSelection {
+    _private: [u8; 0],
+}
+
 pub type UiCallback = Option<extern "C" fn(event: *const UiEvent, *mut c_void)>;
 pub type UiDestructor = extern "C" fn(object: *mut c_void);
 
index 1e7abb4bcee493ca4dbbbf51a79bd3819fd39417..d550975610131614ce66f6763089d87a1f4a628a 100644 (file)
@@ -104,6 +104,41 @@ impl<T> UiList<T> {
             self.ptr = ui_list_new2(ctx.ptr, c_str, list_init::<T>, data as *mut c_void);
         }
     }
+
+    pub fn update(&mut self) {
+        unsafe {
+            ui_list_update(self.ptr);
+        }
+    }
+
+    pub fn update_row(&mut self, row: i32) {
+        unsafe {
+            ui_list_update_row(self.ptr, row);
+        }
+    }
+
+    pub fn selection(&mut self) -> Vec<i32> {
+        let mut sel = Vec::new();
+        unsafe {
+            let selection = ui_list_get_selection_allocated(self.ptr);
+            let count = ui_list_selection_get_count(selection) as usize;
+            if count > 0 {
+                let indices = ui_list_selection_get_rows(selection);
+                sel.set_len(count as usize);
+                for i in 0..count {
+                    sel.push(*indices.add(i) as i32);
+                }
+            }
+            ui_list_selection_free(selection);
+        }
+        sel
+    }
+
+    pub fn set_selection(&mut self, sel: &Vec<i32>) {
+        unsafe {
+            ui_list_set_selected_indices(self.ptr, sel.as_ptr(), sel.len() as c_int);
+        }
+    }
 }
 
 
@@ -313,4 +348,12 @@ extern "C" {
     fn ui_list_get_data(list: *mut ffi::UiList) -> *mut c_void;
     fn ui_list_get_iter(list: *mut ffi::UiList) -> *mut c_void;
     fn ui_list_set_iter(list: *mut ffi::UiList, iter: *mut c_void);
+
+    fn ui_list_update(list: *mut ffi::UiList);
+    fn ui_list_update_row(list: *mut ffi::UiList, row: c_int);
+    fn ui_list_get_selection_allocated(list: *mut ffi::UiList) -> *mut ffi::UiListSelection;
+    fn ui_list_set_selected_indices(list: *mut ffi::UiList, indices: *const c_int, len: c_int);
+    fn ui_list_selection_get_count(list: *mut ffi::UiListSelection) -> c_int;
+    fn ui_list_selection_get_rows(list: *mut ffi::UiListSelection) -> *const c_int;
+    fn ui_list_selection_free(list: *mut ffi::UiListSelection);
 }