package de.unixwork.ui;
import java.lang.foreign.MemorySegment;
+import java.lang.reflect.Field;
public class Document extends Context {
protected MemorySegment ptr;
} catch (Throwable e) {
throw new RuntimeException(e);
}
+
+ // init UI vars
+ Class<?> clazz = this.getClass();
+ for (Field field : clazz.getDeclaredFields()) {
+ Var annotation = field.getAnnotation(Var.class);
+ if (annotation != null) {
+ String name = annotation.name();
+ Class<?> type = field.getType();
+
+ try {
+ field.setAccessible(true); // allow access to private fields
+ if (type == UiString.class) {
+ field.set(this, this.string(name));
+ } else if (type == UiInteger.class) {
+ field.set(this, this.integer(name));
+ } else if (type == UiList.class) {
+ field.set(this, this.list(name));
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to initialize field " + field.getName(), e);
+ }
+ }
+ }
}
public MemorySegment getPtr() {
--- /dev/null
+package de.unixwork.ui;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface Var {
+ String name();
+}
\ No newline at end of file