From: Olaf Wintermann Date: Sun, 3 May 2026 15:25:22 +0000 (+0200) Subject: refactor listview/tableview builder create method to returns a ListView widget X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;ds=sidebyside;p=note.git refactor listview/tableview builder create method to returns a ListView widget --- diff --git a/ui-rs/src/ui/list.rs b/ui-rs/src/ui/list.rs index 0e7b12b..437d60e 100644 --- a/ui-rs/src/ui/list.rs +++ b/ui-rs/src/ui/list.rs @@ -29,12 +29,23 @@ #![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 toolkit::UiObject { widget_typed_fn!(listview, listview_builder, ListViewBuilder); @@ -132,21 +143,21 @@ impl toolkit::UiObject { } } -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);