add ui_customwidget_create function (GTK)

Mon, 13 Jan 2025 22:36:57 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 13 Jan 2025 22:36:57 +0100
changeset 442
dc762a79e72d
parent 441
752bd110375e
child 443
3379c8a5b6bb

add ui_customwidget_create function (GTK)

ui/gtk/container.c file | annotate | diff | comparison | revisions
ui/ui/container.h file | annotate | diff | comparison | revisions
--- a/ui/gtk/container.c	Wed Jan 08 20:35:24 2025 +0100
+++ b/ui/gtk/container.c	Mon Jan 13 22:36:57 2025 +0100
@@ -52,6 +52,17 @@
     return 1;
 }
 
+UIEXPORT UIWIDGET ui_customwidget_create(UiObject *obj, ui_createwidget_func create_widget, void *userdata, UiWidgetArgs args) {
+    UiObject* current = uic_current_obj(obj);
+    
+    UIWIDGET widget = create_widget(obj, args, userdata);
+    
+    UI_APPLY_LAYOUT1(current, args);
+    current->container->add(current->container, widget, FALSE);
+    
+    return widget;
+}
+
 GtkWidget* ui_gtk_vbox_new(int spacing) {
 #if GTK_MAJOR_VERSION >= 3
     return gtk_box_new(GTK_ORIENTATION_VERTICAL, spacing);
--- a/ui/ui/container.h	Wed Jan 08 20:35:24 2025 +0100
+++ b/ui/ui/container.h	Mon Jan 13 22:36:57 2025 +0100
@@ -57,6 +57,18 @@
     UI_HEADERBAR_ALTERNATIVE_BOX
 } UiHeaderbarAlternative;
 
+typedef struct UiWidgetArgs {
+    UiTri fill;
+    UiBool hexpand;
+    UiBool vexpand;
+    UiBool hfill;
+    UiBool vfill;
+    int colspan;
+    int rowspan;
+    const char *name;
+    const char *style_class;
+} UiWidgetArgs;
+
 typedef struct UiContainerArgs {
     UiTri fill;
     UiBool hexpand;
@@ -277,6 +289,12 @@
 UIEXPORT UiObject* ui_document_tab(UiTabbedPane *view);
 
 
+typedef UIWIDGET (*ui_createwidget_func)(UiObject *obj, UiWidgetArgs args, void *userdata);
+UIEXPORT UIWIDGET ui_customwidget_create(UiObject *obj, ui_createwidget_func create_widget, void *userdata, UiWidgetArgs args);
+
+#define ui_customwidget(obj, create_widget, userdata, ...) ui_customwidget_create(obj, create_widget, userdata, (UiWidgetArgs) { __VA_ARGS__ })
+
+
 /* used for macro */
 UIEXPORT void ui_container_begin_close(UiObject *obj);
 UIEXPORT int ui_container_finish(UiObject *obj);

mercurial