]> uap-core.de Git - note.git/commitdiff
add support for integer values in tableview columns main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 16 Apr 2026 17:03:14 +0000 (19:03 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 16 Apr 2026 17:03:14 +0000 (19:03 +0200)
ui-rs/src/ui/list.rs

index cb6a14ed8a7f88ec310e797bc543dd07ea8e6324..7398b757bc89981658ae9024d2f5b3d9fdb7beab 100644 (file)
@@ -10,7 +10,8 @@ use crate::ui::widget::{widget_typed_fn};
 pub enum ListValue<'a> {
     None,
     Str(&'a str),
-    String(String)
+    String(String),
+    Integer(i64)
 }
 
 pub struct ListViewBuilder<'a, T, E> {
@@ -240,7 +241,7 @@ impl<'a, T, E> ListViewBuilder<'a, T, E> {
     pub fn getvalue<F>(&mut self, f: F) -> &mut Self
     where F: Fn(&E, i32, i32) -> ListValue<'a> + 'static {
         unsafe {
-            let wrapper = Box::new(GetValueWrapper { callback: Box::new(f) });
+            let wrapper = Box::new(GetValueWrapper { callback: Box::new(f), is_table: false });
             let ptr = self.obj.reg_box(wrapper);
             ui_list_args_set_getvalue_func2(self.args, getvalue_wrapper::<T>);
             ui_list_args_set_getvalue_data(self.args, ptr as *mut c_void);
@@ -418,7 +419,7 @@ impl<'a, T, E> TableViewBuilder<'a, T, E> {
     pub fn getvalue<F>(&mut self, f: F) -> &mut Self
     where F: Fn(&E, i32, i32) -> ListValue<'a> + 'static {
         unsafe {
-            let wrapper = Box::new(GetValueWrapper { callback: Box::new(f) });
+            let wrapper = Box::new(GetValueWrapper { callback: Box::new(f), is_table: true });
             let ptr = self.obj.reg_box(wrapper);
             ui_list_args_set_getvalue_func2(self.args, getvalue_wrapper::<T>);
             ui_list_args_set_getvalue_data(self.args, ptr as *mut c_void);
@@ -480,8 +481,9 @@ impl Drop for TableModel {
 
 type GetValueFunc = extern "C" fn(list: *const ffi::UiList, elm_ptr: *const c_void, row: i32, col: i32, wrapper: *const c_void, free: *mut bool) -> *mut c_void;
 
-pub struct GetValueWrapper<'a, T> {
-    pub callback: Box<dyn Fn(&T, i32, i32) -> ListValue<'a>>,
+struct GetValueWrapper<'a, T> {
+    callback: Box<dyn Fn(&T, i32, i32) -> ListValue<'a>>,
+    is_table: bool
 }
 
 
@@ -512,7 +514,15 @@ pub extern "C" fn getvalue_wrapper<T>(_list: *const ffi::UiList, elm_ptr: *const
     match result {
         ListValue::None => std::ptr::null_mut(),
         ListValue::Str(s) => str_dup(s),
-        ListValue::String(s) => str_dup(s.as_str())
+        ListValue::String(s) => str_dup(s.as_str()),
+        ListValue::Integer(i) => {
+            if wrapper.is_table {
+                i as *mut c_void
+            } else {
+                let s = i.to_string();
+                str_dup(s.as_str())
+            }
+        }
     }
 }