feedList.items.selected?.let {
feedList.selectItem(it)
}
+ },
+ getstyle = { elm, col, style ->
+ false
}
)
{ elm, col ->
MethodHandle list_args_set_getvalue_func;
MethodHandle list_args_set_getvalue_func2;
MethodHandle list_args_set_getvalue_data;
+ MethodHandle list_args_set_getstyle_func;
+ MethodHandle list_args_set_getstyle_data;
MethodHandle list_args_set_onactivate;
MethodHandle list_args_set_onactivatedata;
MethodHandle list_args_set_onselection;
MemorySegment ui_list_args_set_getvalue_func_addr = lib.find("ui_list_args_set_getvalue_func").orElseThrow();
MemorySegment ui_list_args_set_getvalue_func2_addr = lib.find("ui_list_args_set_getvalue_func2").orElseThrow();
MemorySegment ui_list_args_set_getvalue_data_addr = lib.find("ui_list_args_set_getvalue_data").orElseThrow();
+ MemorySegment ui_list_args_set_getstyle_func_addr = lib.find("ui_list_args_set_getstyle_func").orElseThrow();
+ MemorySegment ui_list_args_set_getstyle_data_addr = lib.find("ui_list_args_set_getstyle_data").orElseThrow();
MemorySegment ui_list_args_set_onactivate_addr = lib.find("ui_list_args_set_onactivate").orElseThrow();
MemorySegment ui_list_args_set_onactivatedata_addr = lib.find("ui_list_args_set_onactivatedata").orElseThrow();
MemorySegment ui_list_args_set_onselection_addr = lib.find("ui_list_args_set_onselection").orElseThrow();
list_args_set_getvalue_func = linker.downcallHandle(ui_list_args_set_getvalue_func_addr, sigv_mm);
list_args_set_getvalue_func2 = linker.downcallHandle(ui_list_args_set_getvalue_func2_addr, sigv_mm);
list_args_set_getvalue_data = linker.downcallHandle(ui_list_args_set_getvalue_data_addr, sigv_mm);
+ list_args_set_getstyle_func = linker.downcallHandle(ui_list_args_set_getstyle_func_addr, sigv_mm);
+ list_args_set_getstyle_data = linker.downcallHandle(ui_list_args_set_getstyle_data_addr, sigv_mm);
list_args_set_onactivate = linker.downcallHandle(ui_list_args_set_onactivate_addr, sigv_mm);
list_args_set_onactivatedata = linker.downcallHandle(ui_list_args_set_onactivatedata_addr, sigv_mm);
list_args_set_onselection = linker.downcallHandle(ui_list_args_set_onselection_addr, sigv_mm);
private ArrayList<UiList> lists = new ArrayList<>();
private ArrayList<ListValueConverter> converters = new ArrayList<>();
+ private ArrayList<ListStyleProvider> styleProviders = new ArrayList<>();
private ArrayList<SubListValueConverter> sublistConverters = new ArrayList<>();
protected void setCtx(MemorySegment ptr) {
return funcData;
}
+ public MemorySegment registerStyleProvider(ListStyleProvider provider) {
+ MemorySegment funcData = arena.allocate(ValueLayout.JAVA_LONG, 2);
+ funcData.setAtIndex(ValueLayout.JAVA_LONG, 0, ptr.address());
+ funcData.setAtIndex(ValueLayout.JAVA_LONG, 1, styleProviders.size());
+ styleProviders.add(provider);
+ return funcData;
+ }
+
public MemorySegment registerSubListValueConverter(SubListValueConverter converter) {
MemorySegment funcData = arena.allocate(ValueLayout.JAVA_LONG, 2);
funcData.setAtIndex(ValueLayout.JAVA_LONG, 0, ptr.address());
return converters.get(index);
}
+ public ListStyleProvider getStyleProvider(int index) {
+ return styleProviders.get(index);
+ }
+
public SubListValueConverter getSubListValueConverter(int index) {
return sublistConverters.get(index);
}
--- /dev/null
+package de.unixwork.ui;
+
+@FunctionalInterface
+public interface ListStyleProvider<T> {
+ public boolean getStyle(T elm, int column, TextStyle style);
+}
private UiList<T> list;
// TODO: model
// TODO: static elements
- private ListValueConverter getvalue;
+ private ListValueConverter<T> getvalue;
+ private ListStyleProvider<T> getstyle;
private EventHandler onActivate;
private EventHandler onSelection;
private EventHandler onDragStart;
return this;
}
+ public ListViewBuilder<T> getstyle(ListStyleProvider<T> getstyle) {
+ this.getstyle = getstyle;
+ return this;
+ }
+
public ListViewBuilder<T> onActivate(EventHandler onActivate) {
this.onActivate = onActivate;
return this;
if(list != null) {
ui.list_args_set_value.invoke(args, list.valuePtr);
}
- if(getvalue != null) {
- // always use the Toolkit.getValue wrapper function
- ui.list_args_set_getvalue_func2.invoke(args, Toolkit.getInstance().getValue);
- MemorySegment userdata = obj.registerValueConverter(getvalue);
- ui.list_args_set_getvalue_data.invoke(args, userdata);
+
+ if(getvalue == null) {
+ getvalue = (elm, col) -> {
+ return elm.toString();
+ };
+ }
+ // always use the Toolkit.getValue wrapper function
+ ui.list_args_set_getvalue_func2.invoke(args, Toolkit.getInstance().getValue);
+ MemorySegment userdata = obj.registerValueConverter(getvalue);
+ ui.list_args_set_getvalue_data.invoke(args, userdata);
+
+ if(getstyle != null) {
+ ui.list_args_set_getstyle_func.invoke(args, Toolkit.getInstance().getStyle);
+ MemorySegment getstyledata = obj.registerStyleProvider(getstyle);
+ ui.list_args_set_getstyle_data.invoke(args, getstyledata);
}
if (onActivate != null) {
private TableModel model;
// TODO: static elements
private ListValueConverter getvalue;
+ private ListStyleProvider<T> getstyle;
private EventHandler onActivate;
private EventHandler onSelection;
private EventHandler onDragStart;
return this;
}
+ public TableViewBuilder<T> getstyle(ListStyleProvider<T> getstyle) {
+ this.getstyle = getstyle;
+ return this;
+ }
+
public TableViewBuilder<T> onActivate(EventHandler onActivate) {
this.onActivate = onActivate;
return this;
MemorySegment userdata = obj.registerValueConverter(getvalue);
ui.list_args_set_getvalue_data.invoke(args, userdata);
}
+ if(getstyle != null) {
+ ui.list_args_set_getstyle_func.invoke(args, Toolkit.getInstance().getStyle);
+ MemorySegment getstyledata = obj.registerStyleProvider(getstyle);
+ ui.list_args_set_getstyle_data.invoke(args, getstyledata);
+ }
if(model != null) {
modelPtr = model.createModel(obj);
ui.list_args_set_model.invoke(args, modelPtr);
--- /dev/null
+package de.unixwork.ui;
+
+import java.awt.*;
+import java.lang.foreign.MemorySegment;
+
+public class TextStyle {
+ private boolean bold;
+ private boolean italic;
+ private boolean underline;
+ private Color color;
+
+ public Color getColor() {
+ return color;
+ }
+
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
+ public boolean isUnderline() {
+ return underline;
+ }
+
+ public void setUnderline(boolean underline) {
+ this.underline = underline;
+ }
+
+ public boolean isItalic() {
+ return italic;
+ }
+
+ public void setItalic(boolean italic) {
+ this.italic = italic;
+ }
+
+ public boolean isBold() {
+ return bold;
+ }
+
+ public void setBold(boolean bold) {
+ this.bold = bold;
+ }
+
+ protected void applySettings(MemorySegment style) {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try {
+ ui.textstyle_set_bold.invoke(style, bold);
+ ui.textstyle_set_italic.invoke(style, italic);
+ ui.textstyle_set_underline.invoke(style, underline);
+ if(color != null) {
+ int r = color.getRed();
+ int g = color.getGreen();
+ int b = color.getBlue();
+ ui.textstyle_set_color.invoke(style, r, g, b);
+ } else {
+ ui.textstyle_enable_color.invoke(style, false);
+ }
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
protected MemorySegment getValue;
protected MemorySegment sourceListGetValue;
+ protected MemorySegment getStyle;
protected MemorySegment threadFuncPtr;
// list/table getvaluefunc wrapper
try {
- MethodHandle getvalue = MethodHandles.lookup().findStatic(
+ MethodHandle getValueMethod = MethodHandles.lookup().findStatic(
Toolkit.class,
"getValue",
MethodType.methodType(MemorySegment.class,
int.class,
MemorySegment.class,
MemorySegment.class));
+ MethodHandle getStyleMethod = MethodHandles.lookup().findStatic(
+ Toolkit.class,
+ "getStyle",
+ MethodType.methodType(boolean.class,
+ MemorySegment.class,
+ MemorySegment.class,
+ int.class,
+ int.class,
+ MemorySegment.class,
+ MemorySegment.class));
getValue = linker.upcallStub(
- getvalue,
+ getValueMethod,
FunctionDescriptor.of(ValueLayout.ADDRESS,
ValueLayout.ADDRESS,
ValueLayout.ADDRESS,
ValueLayout.ADDRESS,
ValueLayout.ADDRESS),
staticArena);
+ getStyle = linker.upcallStub(
+ getStyleMethod,
+ FunctionDescriptor.of(ValueLayout.JAVA_BOOLEAN,
+ ValueLayout.ADDRESS,
+ ValueLayout.ADDRESS,
+ ValueLayout.JAVA_INT,
+ ValueLayout.JAVA_INT,
+ ValueLayout.ADDRESS,
+ ValueLayout.ADDRESS),
+ staticArena);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
}
}
+ public static boolean getStyle(MemorySegment list, MemorySegment elm, int row, int col, MemorySegment userdata, MemorySegment stylePtr) {
+ if(userdata == MemorySegment.NULL) {
+ return false;
+ }
+ // userdata: contains the context ptr and styleprovider index
+ userdata = userdata.reinterpret(16); // long[2]
+ long ctxPtr = userdata.getAtIndex(ValueLayout.JAVA_LONG, 0);
+ long styleProviderIndex = userdata.getAtIndex(ValueLayout.JAVA_LONG, 1);
+
+ var listfuncs = ListFuncs.getInstance();
+
+ var uilist = Toolkit.listPtrToObject(list);
+
+ Object listElm = null;
+ try {
+ listElm = uilist.get((int) row);
+ } catch (Throwable e) {
+ return false;
+ }
+
+ var ctx = Toolkit.getInstance().getContext(ctxPtr);
+ var getstyle = ctx.getStyleProvider((int)styleProviderIndex);
+ var style = new TextStyle();
+ boolean ret = getstyle.getStyle(listElm, col, style);
+ style.applySettings(stylePtr);
+
+ return ret;
+ }
+
// converts a C toolkit UiList* pointer to a java UiList object
protected static UiList listPtrToObject(MemorySegment list) {
ListFuncs listfuncs = ListFuncs.getInstance();
public MethodHandle model_add_column;
public MethodHandle model_free;
+ public MethodHandle textstyle_set_bold;
+ public MethodHandle textstyle_set_italic;
+ public MethodHandle textstyle_set_underline;
+ public MethodHandle textstyle_set_color;
+ public MethodHandle textstyle_enable_color;
+
public MethodHandle call_mainthread;
public MethodHandle ui_malloc;
FunctionDescriptor sigv_mb = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_BOOLEAN);
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_mmimi = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.JAVA_INT);
MemorySegment object_get_context_addr = lib.find("ui_object_get_context").orElseThrow();
MemorySegment model_add_column_addr = lib.find("ui_model_add_column").orElseThrow();
MemorySegment model_free_addr = lib.find("ui_model_free").orElseThrow();
+ MemorySegment textstyle_set_bold_addr = lib.find("ui_textstyle_set_bold").orElseThrow();
+ MemorySegment textstyle_set_italic_addr = lib.find("ui_textstyle_set_italic").orElseThrow();
+ MemorySegment textstyle_set_underline_addr = lib.find("ui_textstyle_set_underline").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();
+
MemorySegment call_mainthread_addr = lib.find("ui_call_mainthread").orElseThrow();
MemorySegment ui_malloc_addr = lib.find("ui_malloc").orElseThrow();
model_add_column = linker.downcallHandle(model_add_column_addr, sigv_mmimi);
model_free = linker.downcallHandle(model_free_addr, sigv_mm);
+ textstyle_set_bold = linker.downcallHandle(textstyle_set_bold_addr, sigv_mb);
+ textstyle_set_italic = linker.downcallHandle(textstyle_set_italic_addr, sigv_mb);
+ textstyle_set_underline = linker.downcallHandle(textstyle_set_underline_addr, sigv_mb);
+ textstyle_set_color = linker.downcallHandle(textstyle_set_color_addr, sigv_miii);
+ textstyle_enable_color = linker.downcallHandle(textstyle_enable_color_addr, sigv_mb);
+
call_mainthread = linker.downcallHandle(call_mainthread_addr, sigv_mm);
ui_malloc = linker.downcallHandle(ui_malloc_addr, sigm_ml);
import de.unixwork.ui.WebView
import de.unixwork.ui.Label
import de.unixwork.ui.LinkButtonType
+import de.unixwork.ui.ListStyleProvider
import de.unixwork.ui.ListViewBuilder
import de.unixwork.ui.TabViewType
import de.unixwork.ui.TableModel
styleClass: String? = null,
onActivate: EventHandler? = null,
onSelection: EventHandler? = null,
+ getstyle: ListStyleProvider<T>? = null,
getvalue: ListValueConverter<T>? = null
): UiWidget {
val table = ListView.table<T>(ui)
onSelection?.let {
table.onSelection(it)
}
+ getstyle?.let {
+ table.getstyle(it)
+ }
getvalue?.let {
table.getvalue(it)
}