// void* func(void*)
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);
+ FunctionDescriptor sigm_mm = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS);
FunctionDescriptor sigv_mm = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.ADDRESS);
FunctionDescriptor sigv_m = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS);
FunctionDescriptor sigm_l = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.JAVA_LONG);
--- /dev/null
+package de.unixwork.ui;
+
+import java.lang.foreign.Arena;
+import java.lang.foreign.MemorySegment;
+
+public class UiDouble {
+ protected MemorySegment valuePtr;
+
+ protected UiDouble(Context ctx, String name) {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+
+ MemorySegment nameCStr = MemorySegment.NULL;
+ try (Arena arena = Arena.ofConfined()) {
+ if(name != null) {
+ nameCStr = arena.allocateFrom(name);
+ }
+
+ valuePtr = (MemorySegment) ui.double_new.invoke(ctx.getCtx(), nameCStr);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public double doubleValue() {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try {
+ Double value = (Double) ui.double_get.invoke(valuePtr);
+ return value.doubleValue();
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setDoubleValue(double value) {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try (Arena arena = Arena.ofConfined()) {
+ ui.int_set.invoke(valuePtr, value);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
ToolkitFuncs ui = ToolkitFuncs.getInstance();
try {
Integer value = (Integer) ui.int_get.invoke(valuePtr);
- return intValue();
+ return value.intValue();
} catch (Throwable e) {
throw new RuntimeException(e);
}
--- /dev/null
+package de.unixwork.ui;
+
+import java.lang.foreign.Arena;
+import java.lang.foreign.MemorySegment;
+
+public class UiText {
+ protected MemorySegment valuePtr;
+
+ protected UiText(Context ctx, String name) {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+
+ MemorySegment nameCStr = MemorySegment.NULL;
+ try (Arena arena = Arena.ofConfined()) {
+ if(name != null) {
+ nameCStr = arena.allocateFrom(name);
+ }
+
+ valuePtr = (MemorySegment) ui.text_new.invoke(ctx.getCtx(), nameCStr);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public String toString() {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try {
+ MemorySegment cstr = (MemorySegment) ui.text_get.invoke(valuePtr);
+ if (cstr != null && cstr.address() != 0) {
+ return cstr.getString(0);
+ }
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ return null;
+ }
+
+ public void setText(String string) {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try (Arena arena = Arena.ofConfined()) {
+ MemorySegment cstr = arena.allocateFrom(string);
+ ui.text_set.invoke(valuePtr, cstr);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
import static java.awt.SystemColor.window;
+class MyDocument extends Document {
+ @Var(name = "string")
+ UiString string;
+
+ MyDocument() {
+
+ }
+}
+
public class Main implements Application{
public void startup() {
UiObject window = UiObject.createWindow("Test Window");
mylist.add("Test3");
mylist.add("Test4");
+ MyDocument doc = new MyDocument();
+
Button.button(window).label("Click Me").onClick(event -> {
System.out.println("Clicked");
}).create();