public abstract class AbstractWidgetBuilder {
UiObject obj;
+ MemorySegment args;
MethodHandle widgetConstructor;
+ MethodHandle argsFree;
public abstract MemorySegment createArgs(Arena arena) throws Throwable;
try (Arena arena = Arena.ofConfined()) {
MemorySegment args = createArgs(arena);
widget = new UiWidget((MemorySegment) widgetConstructor.invoke(obj.ptr, args));
+ freeArgs();
} catch (Throwable e) {
throw new RuntimeException(e);
}
return widget;
}
+
+ void freeArgs() {
+ if(argsFree != null) {
+ try {
+ argsFree.invoke(args);
+ args = null;
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
}
public MemorySegment createArgs(Arena arena) throws Throwable {
ArgFuncs ui = ArgFuncs.getInstance();
- MemorySegment args = (MemorySegment)ui.button_args_new.invoke();
+ args = (MemorySegment)ui.button_args_new.invoke();
if(fill) {
ui.button_args_set_fill.invoke(args, fill);
}
public MemorySegment createArgs(Arena arena) throws Throwable {
ArgFuncs ui = ArgFuncs.getInstance();
- MemorySegment args = (MemorySegment)ui.container_args_new.invoke();
+ args = (MemorySegment)ui.container_args_new.invoke();
if(fill) {
ui.container_args_set_fill.invoke(args, fill);
}
public ListViewBuilder(UiObject obj, MethodHandle widgetConstructor) {
this.obj = obj;
this.widgetConstructor = widgetConstructor;
+ this.argsFree = ArgFuncs.getInstance().list_args_free;
}
public ListViewBuilder<T> fill(boolean fill) {
public MemorySegment createArgs(Arena arena) throws Throwable {
ArgFuncs ui = ArgFuncs.getInstance();
- MemorySegment args = (MemorySegment) ui.list_args_new.invoke();
+ args = (MemorySegment) ui.list_args_new.invoke();
if (fill) {
ui.list_args_set_fill.invoke(args, fill);
}
public SplitPaneBuilder(UiObject obj, MethodHandle widgetConstructor) {
this.obj = obj;
this.widgetConstructor = widgetConstructor;
+ this.argsFree = ArgFuncs.getInstance().splitpane_args_free;
}
public SplitPaneBuilder fill(boolean fill) {
public ToggleBuilder(UiObject obj, MethodHandle widgetConstructor) {
this.obj = obj;
this.widgetConstructor = widgetConstructor;
+ this.argsFree = ArgFuncs.getInstance().toggle_args_free;
}
public ToggleBuilder fill(boolean fill) {
public MemorySegment createArgs(Arena arena) throws Throwable {
ArgFuncs ui = ArgFuncs.getInstance();
- MemorySegment args = (MemorySegment)ui.toggle_args_new.invoke();
+ args = (MemorySegment)ui.toggle_args_new.invoke();
if(fill) {
// TODO
}