* 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) {
/*
* 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);
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]
/* -------------------------------- 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<D, T> {
+ callback: Box<dyn Fn(&mut toolkit::UiObject<D>, &T, i32)>
+}
+
+extern "C" fn createui_wrapper<D, T>(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<D, T> ) };
+ let elm = unsafe { &*(elm_ptr as *const T) };
+
+ let mut obj: toolkit::UiObject<D> = toolkit::UiObject::from_ptr(obj_ptr);
+ (wrapper.callback)(&mut obj, elm, row);
+}
+
pub struct ItemListContainerBuilder<'a, T, C> {
args: *mut UiItemListContainerArgs,
self
}
- pub fn getvalue<F>(&mut self, f: F) -> &mut Self
- where F: Fn(&C, i32, i32) + 'static {
+ pub fn createui<F>(&mut self, f: F) -> &mut Self
+ where F: Fn(&mut toolkit::UiObject<T>, &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::<T, C>);
+ ui_itemlist_container_args_set_userdata(self.args, ptr as *mut c_void);
}
self
}
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);
}
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;
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;
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;
/*