public MethodHandle textstyle_set_color;
public MethodHandle textstyle_enable_color;
+ public MemorySegment ui_set_visible_addr;
+ public MemorySegment ui_set_enabled_addr;
+
+ public MethodHandle set_visible;
+ public MethodHandle set_enabled;
+ public MethodHandle set_widget_groups2;
+ public MethodHandle set_widget_visibility_states;
+
public MethodHandle call_mainthread;
public MethodHandle ui_malloc;
FunctionDescriptor sigm_ml = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_LONG);
FunctionDescriptor sigm_mi = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT);
FunctionDescriptor sigv_mb = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_BOOLEAN);
+ FunctionDescriptor sigv_mi = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT);
FunctionDescriptor sigv_m = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS);
FunctionDescriptor sigm_l = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.JAVA_LONG);
FunctionDescriptor sigv_miii = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT);
FunctionDescriptor sigv_md = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_DOUBLE);
FunctionDescriptor sigd_m = FunctionDescriptor.of(ValueLayout.JAVA_DOUBLE, ValueLayout.ADDRESS);
FunctionDescriptor sigv_mdd = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE);
+ FunctionDescriptor sigv_mmmi = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT);
+ FunctionDescriptor sigv_mmmmi = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT);
MemorySegment object_get_context_addr = lib.find("ui_object_get_context").orElseThrow();
MemorySegment textstyle_set_color_addr = lib.find("ui_textstyle_set_color").orElseThrow();
MemorySegment textstyle_enable_color_addr = lib.find("ui_textstyle_enable_color").orElseThrow();
+ ui_set_visible_addr = lib.find("ui_set_visible").orElseThrow();
+ ui_set_enabled_addr = lib.find("ui_set_enabled").orElseThrow();
+ MemorySegment ui_widget_set_groups2_addr = lib.find("ui_widget_set_groups2").orElseThrow();
+ MemorySegment ui_widget_set_visibility_states_addr = lib.find("ui_widget_set_visibility_states").orElseThrow();
+
MemorySegment call_mainthread_addr = lib.find("ui_call_mainthread").orElseThrow();
MemorySegment ui_malloc_addr = lib.find("ui_malloc").orElseThrow();
textstyle_set_color = linker.downcallHandle(textstyle_set_color_addr, sigv_miii);
textstyle_enable_color = linker.downcallHandle(textstyle_enable_color_addr, sigv_mb);
+ set_enabled = linker.downcallHandle(ui_set_enabled_addr, sigv_mi);
+ set_visible = linker.downcallHandle(ui_set_visible_addr, sigv_mi);
+ set_widget_groups2 = linker.downcallHandle(ui_widget_set_groups2_addr, sigv_mmmmi);
+ set_widget_visibility_states = linker.downcallHandle(ui_widget_set_visibility_states_addr, sigv_mmmi);
+
call_mainthread = linker.downcallHandle(call_mainthread_addr, sigv_mm);
getappdir = linker.downcallHandle(getappdir_addr, sigm);
package de.unixwork.ui;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
+import java.lang.foreign.ValueLayout;
public class UiWidget {
private MemorySegment widget;
+ private UiObject obj;
- public UiWidget(MemorySegment widget) {
+ public UiWidget(UiObject obj, MemorySegment widget) {
+ this.obj = obj;
this.widget = widget;
}
public MemorySegment getWidgetPtr() {
return widget;
}
+
+ public UiObject getToplevelObject() {
+ return obj;
+ }
+
+ public void setEnabled(boolean enabled) {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try {
+ ui.set_enabled.invoke(widget, enabled ? 1 : 0);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setVisible(boolean visible) {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try {
+ ui.set_visible.invoke(widget, visible ? 1 : 0);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setEnabledStates(int... states) {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try (Arena arena = Arena.ofConfined()) {
+ MemorySegment statesArray = arena.allocate(ValueLayout.JAVA_INT, states.length);
+ MemorySegment.copy(states, 0, statesArray, ValueLayout.JAVA_INT, 0, states.length);
+ ui.set_widget_groups2.invoke(obj.getCtx(), widget, MemorySegment.NULL, statesArray, states.length);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
}