import de.unixwork.ui.Document
class FeedCollection(name: String) : Document() {
- private val name = name
- private val items = list<Item>("items")
+ val name = name
+ val items = list<Item>("items")
}
\ No newline at end of file
val sublist1data = list<FeedCollection>("sublist1data")
val col1 = FeedCollection("Test Feed")
sublist1data.add(col1)
+ sublist1.value = sublist1data
feeds.add(sublist1)
}
}
\ No newline at end of file
window = sidebarWindow("RSS Reader") {
sidebar {
vbox(fill = true) {
- sourcelist(fill = true, varname = "feeds") { elm: Object ->
+ sourcelist(fill = true, varname = "feeds") { elm: FeedCollection ->
val item = SubListItem()
- item.label = "todo"
+ item.label = elm.name
item
}
- hbox(margin = 4) {
+ hbox(margin = 4, spacing = 4) {
button(icon = "list-add") {
+ }
+ button(icon = "folder-new") {
+
}
}
}
// create a list object, that will be used as list->data
// listObj contains the context pointer and the list index
// ctx+index will be used to lookup the UiList java object
- MemorySegment listObj = arena.allocate(ValueLayout.JAVA_LONG, 2);
- listObj.setAtIndex(ValueLayout.JAVA_LONG, 0, ptr.address());
- listObj.setAtIndex(ValueLayout.JAVA_LONG, 1, lists.size());
+ MemorySegment listObj;
+ try {
+ listObj = ((MemorySegment)ToolkitFuncs.getInstance().ui_malloc.invoke(ptr, 16)).reinterpret(16); // 2*sizeof(long)
+ listObj.setAtIndex(ValueLayout.JAVA_LONG, 0, ptr.address());
+ listObj.setAtIndex(ValueLayout.JAVA_LONG, 1, lists.size());
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+
var ls = new UiList<T>(this, name, listObj);
lists.add(ls);
return ls;
public MethodHandle call_mainthread;
+ public MethodHandle ui_malloc;
+ public MethodHandle ui_free;
+
// some libc stuff
public MethodHandle malloc;
public MethodHandle free;
FunctionDescriptor sigi_m = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS);
FunctionDescriptor sigm_mm = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS);
FunctionDescriptor sigv_mm = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.ADDRESS);
+ FunctionDescriptor sigm_ml = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_LONG);
FunctionDescriptor sigv_mb = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_BOOLEAN);
FunctionDescriptor sigv_m = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS);
FunctionDescriptor sigm_l = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.JAVA_LONG);
MemorySegment call_mainthread_addr = lib.find("ui_call_mainthread").orElseThrow();
+ MemorySegment ui_malloc_addr = lib.find("ui_malloc").orElseThrow();
+ MemorySegment ui_free_addr = lib.find("ui_free").orElseThrow();
+
MemorySegment malloc_addr = lib.find("malloc").orElseThrow();
MemorySegment free_addr = lib.find("free").orElseThrow();
call_mainthread = linker.downcallHandle(call_mainthread_addr, sigv_mm);
+ ui_malloc = linker.downcallHandle(ui_malloc_addr, sigm_ml);
+ ui_free = linker.downcallHandle(ui_free_addr, sigv_mm);
+
malloc = linker.downcallHandle(malloc_addr, sigm_l);
free = linker.downcallHandle(free_addr, sigv_m);
}
import java.util.ArrayList;
public class UiList<T> extends ArrayList<T> {
+ protected Context ctx;
protected MemorySegment valuePtr;
protected MemorySegment dataPtr;
protected int iter = 0;
protected UiList(Context ctx, String name, MemorySegment listObj) {
super();
+ this.ctx = ctx;
ToolkitFuncs ui = ToolkitFuncs.getInstance();
Toolkit toolkit = Toolkit.getInstance();
}
}
+ public void free() {
+ ToolkitFuncs tk = ToolkitFuncs.getInstance();
+ try {
+ tk.ui_free.invoke(ctx.getCtx(), valuePtr);
+ tk.ui_free.invoke(ctx.getCtx(), dataPtr);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
public static UiList<?> getList(MemorySegment ls) {
ListFuncs ui = ListFuncs.getInstance();
try {