public MethodHandle int_get;
public MethodHandle double_set;
public MethodHandle double_get;
+ public MethodHandle range_set;
+ public MethodHandle range_get;
+ public MethodHandle range_set_range;
+ public MethodHandle range_get_min;
+ public MethodHandle range_get_max;
+ public MethodHandle range_set_extent;
+ public MethodHandle range_get_extent;
public MethodHandle text_set;
public MethodHandle text_get;
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_mmimi = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.ADDRESS, 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);
MemorySegment object_get_context_addr = lib.find("ui_object_get_context").orElseThrow();
MemorySegment double_get_addr = lib.find("ui_double_get").orElseThrow();
MemorySegment text_set_addr = lib.find("ui_text_set").orElseThrow();
MemorySegment text_get_addr = lib.find("ui_text_get").orElseThrow();
+ MemorySegment range_set_addr = lib.find("ui_range_set").orElseThrow();
+ MemorySegment range_get_addr = lib.find("ui_range_get").orElseThrow();
+ MemorySegment range_set_range_addr = lib.find("ui_range_set_range").orElseThrow();
+ MemorySegment range_get_min_addr = lib.find("ui_range_get_min").orElseThrow();
+ MemorySegment range_get_max_addr = lib.find("ui_range_get_max").orElseThrow();
+ MemorySegment range_set_extent_addr = lib.find("ui_range_set_extent").orElseThrow();
+ MemorySegment range_get_extent_addr = lib.find("ui_range_get_extent").orElseThrow();
MemorySegment model_new_addr = lib.find("ui_model_new").orElseThrow();
MemorySegment model_add_column_addr = lib.find("ui_model_add_column").orElseThrow();
string_get = linker.downcallHandle(string_get_addr, sigm_m);
int_set = linker.downcallHandle(int_set_addr, FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_LONG));
int_get = linker.downcallHandle(int_get_addr, FunctionDescriptor.of(ValueLayout.JAVA_LONG, ValueLayout.ADDRESS));
- double_set = linker.downcallHandle(double_set_addr, FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_DOUBLE));
- double_get = linker.downcallHandle(double_get_addr, FunctionDescriptor.of(ValueLayout.JAVA_DOUBLE, ValueLayout.ADDRESS));
+ double_set = linker.downcallHandle(double_set_addr, sigv_md);
+ double_get = linker.downcallHandle(double_get_addr, sigd_m);
text_set = linker.downcallHandle(text_set_addr, sigv_mm);
text_get = linker.downcallHandle(text_get_addr, sigm_m);
+ range_set = linker.downcallHandle(range_set_addr, sigv_md);
+ range_get = linker.downcallHandle(range_get_addr, sigd_m);
+ range_set_range = linker.downcallHandle(range_set_range_addr, sigv_mdd);
+ range_get_min = linker.downcallHandle(range_get_min_addr, sigd_m);
+ range_get_max = linker.downcallHandle(range_get_max_addr, sigd_m);
+ range_set_extent = linker.downcallHandle(range_set_extent_addr, sigv_md);
+ range_get_extent = linker.downcallHandle(range_get_extent_addr, sigd_m);
model_new = linker.downcallHandle(model_new_addr, sigm_m);
model_add_column = linker.downcallHandle(model_add_column_addr, sigv_mmimi);
--- /dev/null
+package de.unixwork.ui;
+
+import java.lang.foreign.Arena;
+import java.lang.foreign.MemorySegment;
+
+public class UiRange {
+ protected MemorySegment valuePtr;
+
+ protected UiRange(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.range_new.invoke(ctx.getCtx(), nameCStr);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public double doubleValue() {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try {
+ return (double)ui.double_get.invoke(valuePtr);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setDoubleValue(double value) {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try (Arena arena = Arena.ofConfined()) {
+ ui.range_set.invoke(valuePtr, value);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setRange(double min, double max) {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try (Arena arena = Arena.ofConfined()) {
+ ui.range_set_range.invoke(valuePtr, min, max);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setExtent(double extent) {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try (Arena arena = Arena.ofConfined()) {
+ ui.range_set_extent.invoke(valuePtr, extent);
+ } catch (Throwable e) {}
+ }
+
+ public double getMin() {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try (Arena arena = Arena.ofConfined()) {
+ return (double) ui.range_get_min.invoke(valuePtr);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public double getMax() {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try (Arena arena = Arena.ofConfined()) {
+ return (double) ui.range_get_max.invoke(valuePtr);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+}