]> uap-core.de Git - rssreader.git/commitdiff
add UiList free method
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 10 Aug 2025 12:32:18 +0000 (14:32 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 10 Aug 2025 12:32:18 +0000 (14:32 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt
ui-java/src/main/java/de/unixwork/ui/Context.java
ui-java/src/main/java/de/unixwork/ui/ToolkitFuncs.java
ui-java/src/main/java/de/unixwork/ui/UiList.java

index 1df2afcf1ba5ca95f95a2234619864bc9f7e9257..6937d931d0fd27d244d8e7b5c900226fc319854d 100644 (file)
@@ -3,6 +3,6 @@ package de.unixwork.rssreader
 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
index e7f1d82dc6b5d3720e81d40c4448da61079042d6..2aca7ae04da54487cb52ff8673e2f26caee48793 100644 (file)
@@ -13,6 +13,7 @@ class FeedSourceList : Document() {
         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
index d05c86c6833dee8cb8ea86dd16667afbe8088cc0..473b0150dbd4c1aec6c2c2dbfb0655248665c457 100644 (file)
@@ -13,14 +13,17 @@ class MainWindow {
         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") {
+
                         }
                     }
                 }
index 89e2b955b89e9d203357f44cd291215f4ccc5742..11d983e37141c930de1c537e15a4656d1d6fb709 100644 (file)
@@ -48,9 +48,15 @@ public abstract class Context {
         // 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;
index 4d6655e8c3a63c01fece39f514021987cce8b5f1..b8e2a25b4dccc0bc9c68b23d74731cb4df7b0d1f 100644 (file)
@@ -62,6 +62,9 @@ public class ToolkitFuncs {
 
     public MethodHandle call_mainthread;
 
+    public MethodHandle ui_malloc;
+    public MethodHandle ui_free;
+
     // some libc stuff
     public MethodHandle malloc;
     public MethodHandle free;
@@ -72,6 +75,7 @@ public class ToolkitFuncs {
         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);
@@ -132,6 +136,9 @@ public class ToolkitFuncs {
 
         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();
 
@@ -192,6 +199,9 @@ public class ToolkitFuncs {
 
         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);
     }
index f11f18d5c3ca9552b1c54003fd3eda8dfad92b5d..488ad248f682a65a319ae3074b8b8f449cb47e2f 100644 (file)
@@ -10,12 +10,14 @@ import java.lang.invoke.MethodType;
 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();
@@ -60,6 +62,16 @@ public class UiList<T> extends ArrayList<T> {
         }
     }
 
+    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 {