pub enum ListValue<'a> {
None,
Str(&'a str),
- String(String)
+ String(String),
+ Integer(i64)
}
pub struct 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);
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);
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
}
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())
+ }
+ }
}
}