MethodHandle list_args_set_model;
MethodHandle list_args_set_static_elements;
MethodHandle list_args_set_getvalue_func;
+ MethodHandle list_args_set_getvalue_func2;
+ MethodHandle list_args_set_getvalue_data;
MethodHandle list_args_set_onactivate;
MethodHandle list_args_set_onactivatedata;
MethodHandle list_args_set_onselection;
MemorySegment ui_list_args_set_model_addr = lib.find("ui_list_args_set_model").orElseThrow();
MemorySegment ui_list_args_set_static_elements_addr = lib.find("ui_list_args_set_static_elements").orElseThrow();
MemorySegment ui_list_args_set_getvalue_func_addr = lib.find("ui_list_args_set_getvalue_func").orElseThrow();
+ MemorySegment ui_list_args_set_getvalue_func2_addr = lib.find("ui_list_args_set_getvalue_func2").orElseThrow();
+ MemorySegment ui_list_args_set_getvalue_data_addr = lib.find("ui_list_args_set_getvalue_data").orElseThrow();
MemorySegment ui_list_args_set_onactivate_addr = lib.find("ui_list_args_set_onactivate").orElseThrow();
MemorySegment ui_list_args_set_onactivatedata_addr = lib.find("ui_list_args_set_onactivatedata").orElseThrow();
MemorySegment ui_list_args_set_onselection_addr = lib.find("ui_list_args_set_onselection").orElseThrow();
list_args_set_model = linker.downcallHandle(ui_list_args_set_model_addr, sigv_mm);
list_args_set_static_elements = linker.downcallHandle(ui_list_args_set_static_elements_addr, sigv_mml);
list_args_set_getvalue_func = linker.downcallHandle(ui_list_args_set_getvalue_func_addr, sigv_mm);
+ list_args_set_getvalue_func2 = linker.downcallHandle(ui_list_args_set_getvalue_func2_addr, sigv_mm);
+ list_args_set_getvalue_data = linker.downcallHandle(ui_list_args_set_getvalue_data_addr, sigv_mm);
list_args_set_onactivate = linker.downcallHandle(ui_list_args_set_onactivate_addr, sigv_mm);
list_args_set_onactivatedata = linker.downcallHandle(ui_list_args_set_onactivatedata_addr, sigv_mm);
list_args_set_onselection = linker.downcallHandle(ui_list_args_set_onselection_addr, sigv_mm);
private Arena arena = Arena.ofShared();
private ArrayList<UiList> lists = new ArrayList<>();
+ private ArrayList<ListValueConverter> converters = new ArrayList<>();
protected void setCtx(MemorySegment ptr) {
this.ptr = ptr;
return ls;
}
+ public MemorySegment registerValueConverter(ListValueConverter converter) {
+ MemorySegment funcData = arena.allocate(ValueLayout.JAVA_LONG, 2);
+ funcData.setAtIndex(ValueLayout.JAVA_LONG, 0, ptr.address());
+ funcData.setAtIndex(ValueLayout.JAVA_LONG, 1, converters.size());
+ converters.add(converter);
+ return funcData;
+ }
+
public void attach(Document doc) {
ToolkitFuncs ui = ToolkitFuncs.getInstance();
ui.list_args_set_value.invoke(args, list.valuePtr);
}
if(getvalue != null) {
- // fuck
+ // always use the Toolkit.getValue wrapper function
+ ui.list_args_set_getvalue_func2.invoke(args, Toolkit.getInstance().getValue);
+ MemorySegment userdata = obj.registerValueConverter(getvalue);
+ ui.list_args_set_getvalue_data.invoke(args, userdata);
}
if (onActivate != null) {
private HashMap<Long, UiObject> toplevelObjects = new HashMap<>();
private HashMap<Long, Document> documents = new HashMap<>();
- private HashMap<Long, Context> contexts = new HashMap<>(); // TODO: maybe we can replace the UiObject and Doument maps with just this context map
+ private HashMap<Long, Context> contexts = new HashMap<>(); // TODO: maybe we can replace the UiObject and Document maps with just this context map
// used for all strings and other memory, that is expected to be const
// and the UI toolkit does not create copies
protected MemorySegment listGet;
protected MemorySegment listCount;
+ protected MemorySegment getValue;
+
private Toolkit(String appName) {
// load shared library
System.loadLibrary("uitk");
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
+
+ // list/table getvaluefunc wrapper
+ try {
+ MethodHandle getvalue = MethodHandles.lookup().findStatic(
+ Toolkit.class,
+ "getValue",
+ MethodType.methodType(MemorySegment.class, MemorySegment.class, MemorySegment.class, int.class, int.class, MemorySegment.class));
+
+ getValue = linker.upcallStub(
+ getvalue,
+ FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.ADDRESS),
+ staticArena);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
}
public static Toolkit getInstance() {
public Context getContext(long address) {
return contexts.get(address);
}
+
+ /*
+ * list getvaluefunc wrapper
+ */
+ public static MemorySegment getValue(MemorySegment list, MemorySegment elm, int row, int col, MemorySegment userdata) {
+
+
+ return MemorySegment.NULL;
+ }
}