list_get_iter = linker.downcallHandle(ui_list_get_iter_addr, sigm_m);
list_set_iter = linker.downcallHandle(ui_list_set_iter_addr, sigm_mm);
- srclist_new = linker.downcallHandle(ui_srclist_new_addr, sigm_m);
+ srclist_new = linker.downcallHandle(ui_srclist_new_addr, sigm_mm);
srclist_add = linker.downcallHandle(ui_srclist_add_addr, sigv_mm);
srclist_insert = linker.downcallHandle(ui_srclist_insert_addr, sigv_mim);
srclist_remove = linker.downcallHandle(ui_srclist_remove_addr, sigv_mi);
public SourceListBuilder(UiObject obj, MethodHandle widgetConstructor) {
this.obj = obj;
this.widgetConstructor = widgetConstructor;
- this.argsFree = ArgFuncs.getInstance().list_args_free;
+ this.argsFree = ArgFuncs.getInstance().sourcelist_args_free;
}
public SourceListBuilder<T> fill(boolean fill) {
ui.sourcelist_args_set_getvalue_func.invoke(args, Toolkit.getInstance().sourceListGetValue);
MemorySegment userdata = obj.registerSubListValueConverter(getvalue);
ui.sourcelist_args_set_getvalue_userdata.invoke(args, userdata);
+ } else {
+ throw new IllegalArgumentException("getvalue must be set");
}
return args;
try(Arena arena = Arena.ofConfined()) {
MemorySegment sublist = (MemorySegment) ui.sublist_new.invoke();
if(value != null) {
+ MemorySegment vp = value.valuePtr;
ui.sublist_set_value.invoke(sublist, value.valuePtr);
}
if(varname != null) {
Toolkit.class,
"sourceListGetValue",
MethodType.methodType(void.class,
+ MemorySegment.class,
MemorySegment.class,
MemorySegment.class,
int.class,
sourceListGetValue = linker.upcallStub(
scGetValue,
FunctionDescriptor.ofVoid(
+ ValueLayout.ADDRESS,
ValueLayout.ADDRESS,
ValueLayout.ADDRESS,
ValueLayout.JAVA_INT,
if(userdata == MemorySegment.NULL) {
return MemorySegment.NULL;
}
+ // userdata: contains the context ptr and converter index
userdata = userdata.reinterpret(16); // long[2]
long ctxPtr = userdata.getAtIndex(ValueLayout.JAVA_LONG, 0);
long converterIndex = userdata.getAtIndex(ValueLayout.JAVA_LONG, 1);
ListFuncs listfuncs = ListFuncs.getInstance();
- MemorySegment listdata = null; // long[2]
- try {
- listdata = ((MemorySegment)listfuncs.list_get_data.invoke(list)).reinterpret(16);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- long listCtxPtr = listdata.getAtIndex(ValueLayout.JAVA_LONG, 0);
- long listIndex = listdata.getAtIndex(ValueLayout.JAVA_LONG, 1);
- Context listCtx = Toolkit.getInstance().getContext(listCtxPtr);
- UiList uilist = listCtx.getList((int)listIndex);
+ UiList uilist = Toolkit.listPtrToObject(list);
Object listElm = null;
try {
return MemorySegment.NULL;
}
- public static void sourceListGetValue(MemorySegment sublistData, MemorySegment rowData, int index, MemorySegment out_item, MemorySegment userdata) {
- if(userdata == MemorySegment.NULL || sublistData == MemorySegment.NULL) {
+ public static void sourceListGetValue(MemorySegment list, MemorySegment sublistData, MemorySegment rowData, int index, MemorySegment out_item, MemorySegment userdata) {
+ if(userdata == MemorySegment.NULL || list == MemorySegment.NULL) {
return;
}
Context ctx = Toolkit.getInstance().getContext(ctxPtr);
SubListValueConverter conv = ctx.getSubListValueConverter((int)converterIndex);
- ListFuncs listfuncs = ListFuncs.getInstance();
-
- MemorySegment listdata = null; // long[2]
- try {
- listdata = ((MemorySegment)listfuncs.list_get_data.invoke(sublistData)).reinterpret(16);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- long listCtxPtr = listdata.getAtIndex(ValueLayout.JAVA_LONG, 0);
- long listIndex = listdata.getAtIndex(ValueLayout.JAVA_LONG, 1);
- Context listCtx = Toolkit.getInstance().getContext(listCtxPtr);
- UiList uilist = listCtx.getList((int)listIndex);
+ UiList uilist = Toolkit.listPtrToObject(list);
ToolkitFuncs ui = ToolkitFuncs.getInstance();
try(Arena arena = Arena.ofShared()) {
}
}
+
+ // converts a C toolkit UiList* pointer to a java UiList object
+ protected static UiList listPtrToObject(MemorySegment list) {
+ ListFuncs listfuncs = ListFuncs.getInstance();
+
+ MemorySegment listdata = null; // long[2]
+ try {
+ listdata = ((MemorySegment)listfuncs.list_get_data.invoke(list)).reinterpret(16);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+
+ long listCtxPtr = listdata.getAtIndex(ValueLayout.JAVA_LONG, 0);
+ long listIndex = listdata.getAtIndex(ValueLayout.JAVA_LONG, 1);
+ Context listCtx = Toolkit.getInstance().getContext(listCtxPtr);
+ return listCtx.getList((int)listIndex);
+ }
}
public MethodHandle free;
private ToolkitFuncs(Linker linker, SymbolLookup lib) {
- // void* func(void*)
+ FunctionDescriptor sigm = FunctionDescriptor.of(ValueLayout.ADDRESS);
FunctionDescriptor sigm_m = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS);
FunctionDescriptor sigi_m = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS);
FunctionDescriptor sigm_mm = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS);
event_get_int = linker.downcallHandle(event_get_int_addr, sigi_m);
event_get_set = linker.downcallHandle(event_get_set_addr, sigi_m);
- sublist_new = linker.downcallHandle(sublist_new_addr, sigm_m);
+ sublist_new = linker.downcallHandle(sublist_new_addr, sigm);
sublist_set_value = linker.downcallHandle(sublist_set_value_addr, sigv_mm);
sublist_set_varname = linker.downcallHandle(sublist_set_varname_addr, sigv_mm);
sublist_set_header = linker.downcallHandle(sublist_set_header_addr, sigv_mm);
range_new = linker.downcallHandle(range_new_addr, sigm_mm);
generic_new = linker.downcallHandle(generic_new_addr, sigm_mm);
list_new = linker.downcallHandle(list_new_addr, sigm_mm);
- list_new2 = linker.downcallHandle(list_new2_addr, FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS));
+ list_new2 = linker.downcallHandle(list_new2_addr, FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS));
string_set = linker.downcallHandle(string_set_addr, sigv_mm);
string_get = linker.downcallHandle(string_get_addr, sigm_m);
mylist.add("Test3");
mylist.add("Test4");
- MyDocument doc = new MyDocument();
+ UiSourceList src = window.sourcelist("src");
+ UiList<String> sublist1 = window.list();
+ sublist1.add("Item 1");
+ sublist1.add("Item 2");
+ sublist1.add("Item 3");
+ SubList<String> sub = new SubList<>();
+ sub.setValue(sublist1);
+ sub.setHeader("Header");
+ src.add(sub);
+ //MyDocument doc = new MyDocument();
+
+ ListView.<String>sourcelist(window).dynamicSublists(src).fill(true).getvalue((elm) -> {
+ return new SubListItem(elm);
+ }).create();
+
+
+ /*
Button.button(window).label("Click Me").onClick(event -> {
System.out.println("Clicked");
}).create();
}).create();
});
}
+ */
window.show();
}