]> uap-core.de Git - note.git/commitdiff
refactor listview/tableview builder create method to returns a ListView widget main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 3 May 2026 15:25:22 +0000 (17:25 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 3 May 2026 15:25:22 +0000 (17:25 +0200)
ui-rs/src/ui/list.rs

index 0e7b12b5eff19803b4f7b0438cedd2551a5ad2bf..437d60e309bc0a89584ac69e4c32577721a37fa8 100644 (file)
 #![allow(dead_code)]
 
 use crate::ui::ffi::{UiObject, UiListArgs, UiCallback, UiList, UiSourceListArgs};
-use crate::ui::{event, ffi, toolkit, ui_list_get, ui_list_get_data, EventWrapper};
+use crate::ui::{event, ffi, toolkit, ui_list_get, ui_list_get_data, Button, EventWrapper};
 use std::ffi::{c_char, c_int, c_void};
 use std::ffi::CString;
 use std::marker::PhantomData;
 use std::mem;
-use crate::ui::widget::{widget_typed_fn};
+use crate::ui::widget::{widget_typed_fn, Widget};
+
+
+pub struct ListView {
+    ptr: *mut c_void
+}
+
+impl Widget for ListView {
+    fn get_widget(&self) -> *mut c_void {
+        self.ptr
+    }
+}
 
 pub enum ListValue<'a> {
     None,
@@ -96,7 +107,7 @@ pub enum ColumnType {
     EditableBool = 7
 }
 
-pub type ListBuilderCreate = fn(*const UiObject, *const UiListArgs);
+pub type ListBuilderCreate = fn(*const UiObject, *const UiListArgs) -> ListView;
 
 impl<T> toolkit::UiObject<T> {
     widget_typed_fn!(listview, listview_builder, ListViewBuilder);
@@ -132,21 +143,21 @@ impl<T> toolkit::UiObject<T> {
     }
 }
 
-fn list_create(obj: *const UiObject, args: *const UiListArgs) {
+fn list_create(obj: *const UiObject, args: *const UiListArgs) -> ListView {
     unsafe {
-        ui_listview_create(obj, args);
+        ListView { ptr: ui_listview_create(obj, args) }
     }
 }
 
-fn dropdown_create(obj: *const UiObject, args: *const UiListArgs) {
+fn dropdown_create(obj: *const UiObject, args: *const UiListArgs) -> ListView {
     unsafe {
-        ui_dropdown_create(obj, args);
+        ListView { ptr: ui_dropdown_create(obj, args) }
     }
 }
 
-fn tableview_create(obj: *const UiObject, args: *const UiListArgs) {
+fn tableview_create(obj: *const UiObject, args: *const UiListArgs) -> ListView {
     unsafe {
-        ui_table_create(obj, args);
+        ListView { ptr: ui_table_create(obj, args) }
     }
 }
 
@@ -159,13 +170,13 @@ impl<'a, T, E> Drop for ListViewBuilder<'a, T, E> {
 }
 
 impl<'a, T, E> ListViewBuilder<'a, T, E> {
-    pub fn create(&mut self) {
+    pub fn create(&mut self) -> ListView {
         if !self.has_getvalue_func {
             unsafe {
                 ui_list_args_set_getvalue_func2(self.args, null_getvalue_wrapper);
             }
         }
-        (self.create)(self.obj.ptr, self.args);
+        (self.create)(self.obj.ptr, self.args)
     }
 
     pub fn fill(&mut self, fill: bool) -> &mut Self {
@@ -337,7 +348,7 @@ impl<'a, T, E> Drop for TableViewBuilder<'a, T, E> {
 }
 
 impl<'a, T, E> TableViewBuilder<'a, T, E> {
-    pub fn create(&mut self) {
+    pub fn create(&mut self) -> ListView {
         if !self.has_getvalue_func {
             unsafe {
                 ui_list_args_set_getvalue_func2(self.args, null_getvalue_wrapper);
@@ -350,7 +361,7 @@ impl<'a, T, E> TableViewBuilder<'a, T, E> {
                 ui_model_ref(self.model);
             }
         }
-        (self.create)(self.obj.ptr, self.args);
+        (self.create)(self.obj.ptr, self.args)
     }
 
     pub fn fill(&mut self, fill: bool) -> &mut Self {
@@ -899,10 +910,10 @@ type SLGetValueFunc = extern "C" fn(
 extern "C" {
     fn malloc(size: usize) -> *mut c_void;
 
-    fn ui_listview_create(obj: *const UiObject, args: *const UiListArgs);
-    fn ui_dropdown_create(obj: *const UiObject, args: *const UiListArgs);
-    fn ui_table_create(obj: *const UiObject, args: *const UiListArgs);
-    fn ui_sourcelist_create(obj: *const UiObject, args: *const UiSourceListArgs);
+    fn ui_listview_create(obj: *const UiObject, args: *const UiListArgs) -> *mut c_void;
+    fn ui_dropdown_create(obj: *const UiObject, args: *const UiListArgs)-> *mut c_void;
+    fn ui_table_create(obj: *const UiObject, args: *const UiListArgs)-> *mut c_void;
+    fn ui_sourcelist_create(obj: *const UiObject, args: *const UiSourceListArgs)-> *mut c_void;
 
     fn ui_list_args_new() -> *mut UiListArgs;
     fn ui_list_args_set_fill(args: *mut UiListArgs, fill: c_int);