From a38de8b34298b5c8f84fc8ee6ab9c891095d3c5b Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Tue, 25 Aug 2026 20:56:53 +0200 Subject: [PATCH] implement itemlist createui arg --- application/attachment.c | 2 +- application/attachment.h | 2 +- ui-rs/src/ui/container.rs | 26 +++++++++++++++++++++----- ui/gtk/container.c | 2 +- ui/gtk/container.h | 2 +- ui/ui/container.h | 6 +++--- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/application/attachment.c b/application/attachment.c index 604f650..32ae906 100644 --- a/application/attachment.c +++ b/application/attachment.c @@ -140,7 +140,7 @@ cxmutstr attachment_file_load(const CxAllocator *a, const char *path) { * itemlist create_ui function * used by the note horizontal attachments list */ -void attachment_item(UiObject *obj, int index, void *elm, void *userdata) { +void attachment_item(UiObject *obj, UiList *list, int index, void *elm, void *userdata) { Attachment *attachment = elm; if(attachment->type == NOTE_ATTACHMENT_IMAGE) { diff --git a/application/attachment.h b/application/attachment.h index b738fb7..734dd55 100644 --- a/application/attachment.h +++ b/application/attachment.h @@ -58,7 +58,7 @@ cxmutstr attachment_file_load(const CxAllocator *a, const char *path); /* * create UI for an attachment item */ -void attachment_item(UiObject *obj, int index, void *elm, void *userdata); +void attachment_item(UiObject *obj, UiList *list, int index, void *elm, void *userdata); void action_attachment_clicked(UiEvent *event, void *userdata); diff --git a/ui-rs/src/ui/container.rs b/ui-rs/src/ui/container.rs index 45b2c2e..a71d767 100644 --- a/ui-rs/src/ui/container.rs +++ b/ui-rs/src/ui/container.rs @@ -33,7 +33,7 @@ use std::ffi::{c_char, c_int, c_void}; use std::ffi::CString; use std::marker::PhantomData; use crate::ui::ffi::*; -use crate::ui::{ffi, getvalue_wrapper, toolkit, Button, GetValueWrapper}; +use crate::ui::{ffi, getvalue_wrapper, toolkit, Button, GetValueWrapper, ListValue}; use crate::ui::widget::Widget; #[macro_export] @@ -1320,7 +1320,20 @@ impl<'a, T> TabViewBuilder<'a, T> { /* -------------------------------- ItemList Container -------------------------------- */ -pub type CreateUiFunc = extern "C" fn(obj: *mut ffi::UiObject, row: c_int, elm: *mut c_void, userdata: *mut c_void); +type CreateUiFunc = extern "C" fn(obj: *mut ffi::UiObject, list: *mut ffi::UiList, row: c_int, elm: *mut c_void, userdata: *mut c_void); + +struct CreateUiWrapper { + callback: Box, &T, i32)> +} + +extern "C" fn createui_wrapper(obj_ptr: *mut ffi::UiObject, _list: *mut ffi::UiList, row: c_int, elm_ptr: *mut c_void, userdata: *mut c_void) { + let wrapper = unsafe { &*(userdata as *const CreateUiWrapper ) }; + let elm = unsafe { &*(elm_ptr as *const T) }; + + let mut obj: toolkit::UiObject = toolkit::UiObject::from_ptr(obj_ptr); + (wrapper.callback)(&mut obj, elm, row); +} + pub struct ItemListContainerBuilder<'a, T, C> { args: *mut UiItemListContainerArgs, @@ -1464,10 +1477,13 @@ impl<'a, T, C> ItemListContainerBuilder<'a, T, C> { self } - pub fn getvalue(&mut self, f: F) -> &mut Self - where F: Fn(&C, i32, i32) + 'static { + pub fn createui(&mut self, f: F) -> &mut Self + where F: Fn(&mut toolkit::UiObject, &C, i32) + 'static { unsafe { - // TODO + let wrapper = Box::new(CreateUiWrapper { callback: Box::new(f) }); + let ptr = self.obj.ctx.reg_box(wrapper); + ui_itemlist_container_args_set_create_ui(self.args, createui_wrapper::); + ui_itemlist_container_args_set_userdata(self.args, ptr as *mut c_void); } self } diff --git a/ui/gtk/container.c b/ui/gtk/container.c index 5174dc6..2a90e44 100644 --- a/ui/gtk/container.c +++ b/ui/gtk/container.c @@ -1303,7 +1303,7 @@ static void update_itemlist(UiList *list, int c) { UiLayout layout = {0}; ui_box_container_add(ct->container, obj->widget, &layout); if(ct->create_ui) { - ct->create_ui(obj, index, elm, ct->userdata); + ct->create_ui(obj, list, index, elm, ct->userdata); } cxMapPut(new_items, key, obj); } diff --git a/ui/gtk/container.h b/ui/gtk/container.h index 352b50e..a4396d7 100644 --- a/ui/gtk/container.h +++ b/ui/gtk/container.h @@ -135,7 +135,7 @@ typedef struct UiGtkItemListContainer { UiObject *parent; GtkWidget *widget; UiContainerPrivate *container; - void (*create_ui)(UiObject *, int, void *, void *); + void (*create_ui)(UiObject *, UiList *, int, void *, void *); void *userdata; UiSubContainerType subcontainer; CxMap *current_items; diff --git a/ui/ui/container.h b/ui/ui/container.h index 0e8ee99..fbd6c03 100644 --- a/ui/ui/container.h +++ b/ui/ui/container.h @@ -217,7 +217,7 @@ typedef struct UiSplitPaneArgs { const int *visibility_states; } UiSplitPaneArgs; -typedef void (*ui_create_ui_func)(UiObject *, int, void *, void *); +typedef void (*ui_create_ui_func)(UiObject *, UiList *, int, void *, void *); typedef struct UiItemListContainerArgs { UiBool fill; @@ -246,14 +246,14 @@ typedef struct UiItemListContainerArgs { UiList *value; const char *varname; /* - * void create_ui(UiObject *obj, int index, void *elm, void *userdata) + * void create_ui(UiObject *obj, UiList *, int index, void *elm, void *userdata) * * UI constructor for each list element * * This callback is executed for each list element. A new UiObject is * created for every item. */ - void (*create_ui)(UiObject *, int, void *, void *); + void (*create_ui)(UiObject *, UiList *, int, void *, void *); void *userdata; /* -- 2.52.0