]> uap-core.de Git - rssreader.git/commitdiff
add first kotlin code, prototype for kotlin API
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 18 Jun 2025 19:50:23 +0000 (21:50 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 18 Jun 2025 19:50:23 +0000 (21:50 +0200)
ui-java/src/main/java/de/unixwork/ui/UiObjectFuncs.java
ui-kotlin/src/main/kotlin/de/unixwork/ui/kotlin/Toplevel.kt [new file with mode: 0644]
ui-kotlin/src/test/kotlin/de/unixwork/ui/kotlin/demo/Main.kt [new file with mode: 0644]

index 4f2071eb1ade664ea41275dc9af3410a21bf8826..1de1827ce475a55d8463684c9faa5b8ac9de5cd1 100644 (file)
@@ -6,8 +6,8 @@ import java.lang.invoke.MethodHandle;
 class UiObjectFuncs {
     static UiObjectFuncs instance;
 
-    MethodHandle ui_show;
-    MethodHandle ui_window;
+    public MethodHandle ui_show;
+    public MethodHandle ui_window;
 
     private UiObjectFuncs(Linker linker, SymbolLookup lib) {
         // void* func(void*, void*)
diff --git a/ui-kotlin/src/main/kotlin/de/unixwork/ui/kotlin/Toplevel.kt b/ui-kotlin/src/main/kotlin/de/unixwork/ui/kotlin/Toplevel.kt
new file mode 100644 (file)
index 0000000..69ed4d4
--- /dev/null
@@ -0,0 +1,70 @@
+package de.unixwork.ui.kotlin
+
+import de.unixwork.ui.Button
+import de.unixwork.ui.ButtonBuilder
+import de.unixwork.ui.EventHandler
+import de.unixwork.ui.EventWrapper.eventHandler
+import de.unixwork.ui.UiObject
+import de.unixwork.ui.UiWidget
+import java.lang.foreign.MemorySegment
+
+class Toplevel(obj: UiObject) {
+    private val obj: UiObject = obj
+
+    fun button(
+        label: String? = null,
+        stockId: String? = null,
+        icon: String? = null,
+        fill: Boolean = false,
+        hexpand: Boolean = false,
+        vexpand: Boolean = false,
+        hfill: Boolean = false,
+        vfill: Boolean = false,
+        overrideDefaults: Boolean = false,
+        colspan: Int = -1,
+        rowspan: Int = -1,
+        name: String? = null,
+        styleClass: String? = null,
+        onClick: EventHandler? = null
+    ): UiWidget {
+        val button = Button.button(obj)
+        label?.let {
+            button.label(it)
+        }
+        // TODO: fill
+        if(hexpand) {
+            button.hexpand(true)
+        }
+        if(vexpand) {
+            button.vexpand(true)
+        }
+        if(hfill) {
+            button.hfill(true)
+        }
+        if(vfill) {
+            button.vfill(true)
+        }
+        if(colspan > 0) {
+            button.colspan(colspan)
+        }
+        if(rowspan > 0) {
+            button.rowspan(rowspan)
+        }
+        if(overrideDefaults) {
+            button.overrideDefaults(true)
+        }
+        name?.let {
+            button.name(name)
+        }
+        styleClass?.let {
+            button.styleClass(it)
+        }
+        stockId?.let {
+            button.stockId(it)
+        }
+        onClick?.let {
+            button.onClick(onClick)
+        }
+        return button.create()
+    }
+}
\ No newline at end of file
diff --git a/ui-kotlin/src/test/kotlin/de/unixwork/ui/kotlin/demo/Main.kt b/ui-kotlin/src/test/kotlin/de/unixwork/ui/kotlin/demo/Main.kt
new file mode 100644 (file)
index 0000000..e715840
--- /dev/null
@@ -0,0 +1,27 @@
+package de.unixwork.ui.kotlin.demo
+
+import de.unixwork.ui.Application
+import de.unixwork.ui.Button
+import de.unixwork.ui.Toolkit
+import de.unixwork.ui.UiObject
+import de.unixwork.ui.kotlin.Toplevel
+
+class Main : Application {
+    override fun startup() {
+        val window = UiObject.createWindow("Test Window")
+        val toplevel = Toplevel(window)
+
+        toplevel.button(label = "Hello World")
+
+        window.show()
+    }
+}
+
+fun main() {
+    println("Kotlin UI Demo")
+
+
+
+    Toolkit.init("testapp")
+    Toolkit.runApplication(Main())
+}
\ No newline at end of file