add frame container (QT)

Sun, 07 Dec 2025 11:51:01 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 07 Dec 2025 11:51:01 +0100
changeset 959
4b2202df31ec
parent 958
749a8a36d74b
child 960
e88ca7dfa943

add frame container (QT)

application/demo_bindings.c file | annotate | diff | comparison | revisions
ui/gtk/window.c file | annotate | diff | comparison | revisions
ui/qt/container.cpp file | annotate | diff | comparison | revisions
ui/qt/container.h file | annotate | diff | comparison | revisions
ui/qt/window.cpp file | annotate | diff | comparison | revisions
--- a/application/demo_bindings.c	Sun Dec 07 11:27:44 2025 +0100
+++ b/application/demo_bindings.c	Sun Dec 07 11:51:01 2025 +0100
@@ -32,7 +32,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#if !defined(UI_WIN32) && !defined(UI_QT)
+#if !defined(UI_WIN32)
 
 Document* document_create(int id) {
     Document* doc = ui_document_new(sizeof(Document));
@@ -175,18 +175,12 @@
 
 #ifndef UI_WIN32
 
-#ifdef UI_QT
-int main(int argc, char **argv) {
-    return 0;
-}
-#else
 int main(int argc, char **argv) {
     ui_init(NULL, argc, argv);
     ui_onstartup(application_startup, NULL);
     ui_main();
     return 0;
 }
-#endif
 
 #else
 
--- a/ui/gtk/window.c	Sun Dec 07 11:27:44 2025 +0100
+++ b/ui/gtk/window.c	Sun Dec 07 11:51:01 2025 +0100
@@ -397,7 +397,7 @@
     return create_window(title, window_data, TRUE, FALSE, FALSE);
 }
 
-UIEXPORT UiObject *ui_splitview_window(const char *title, UiBool sidebar) {
+UiObject *ui_splitview_window(const char *title, UiBool sidebar) {
     return create_window(title, NULL, sidebar, TRUE, FALSE);
 }
 
--- a/ui/qt/container.cpp	Sun Dec 07 11:27:44 2025 +0100
+++ b/ui/qt/container.cpp	Sun Dec 07 11:51:01 2025 +0100
@@ -82,7 +82,14 @@
     bool fill = layout.fill;
     if(hasStretchedWidget && fill) {
         fill = false;
-        fprintf(stderr, "UiError: container has 2 filled widgets");
+        fprintf(stderr, "UiError: container has 2 filled widgets\n");
+    }
+    
+    if(singleChild) {
+        fill = true;
+        if(hasChild) {
+            fprintf(stderr, "UiError: single child container already has a child\n");
+        }
     }
     
     uic_layout_setup_margin(&layout);
@@ -103,6 +110,7 @@
         hasStretchedWidget = true;
     }
     current = widget;
+    hasChild = true;
 }
 
 UIWIDGET ui_box(UiObject *obj, UiContainerArgs *args, QBoxLayout::Direction dir) {
@@ -239,6 +247,64 @@
 }
 
 
+/* ------------------------------ Frame ------------------------------ */
+
+UIWIDGET ui_frame_create(UiObject *obj, UiFrameArgs *args) {
+    UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj);
+    UiLayout layout = UI_ARGS2LAYOUT(args);
+    
+    bool createBox = true;
+    bool singleChild = false;
+    QBoxLayout::Direction dir = QBoxLayout::TopToBottom;
+    QGroupBox *widget = new QGroupBox();
+    if(args->label) {
+        widget->setTitle(args->label);
+    }
+    
+    switch(args->subcontainer) {
+        default: break;
+        case UI_CONTAINER_HBOX: {
+            dir = QBoxLayout::LeftToRight;
+            break;
+        }
+        case UI_CONTAINER_GRID: {
+            createBox = false;
+            break;
+        }
+        case UI_CONTAINER_NO_SUB: {
+            singleChild = true;
+        }
+    }
+    
+    if(createBox) {
+        QBoxLayout *box = new QBoxLayout(dir);
+        widget->setLayout(box);
+        
+        UiBoxContainer *container = new UiBoxContainer(box);
+        ui_obj_add_container(obj, container);
+
+        container->singleChild = singleChild;
+    } else {
+        QGridLayout *grid = new QGridLayout();
+        widget->setLayout(grid);
+
+        ui_obj_add_container(obj, new UiGridContainer(
+                grid,
+                args->padding,
+                args->columnspacing,
+                args->rowspacing,
+                false,
+                false,
+                false,
+                false));
+    }
+    
+    
+    ctn->add(widget, layout);
+    
+    return widget;
+}
+
 /* ---------------------------- UiSidebar ---------------------------- */
 
 UIWIDGET ui_sidebar_create(UiObject *obj, UiSidebarArgs *args) {
--- a/ui/qt/container.h	Sun Dec 07 11:27:44 2025 +0100
+++ b/ui/qt/container.h	Sun Dec 07 11:51:01 2025 +0100
@@ -39,6 +39,7 @@
 #include <QTabWidget>
 #include <QStackedWidget>
 #include <QSplitter>
+#include <QGroupBox>
 
 #define ui_obj_container(obj) (UiContainerPrivate*)((UiContainerX*)obj->container_end)->container
 
@@ -54,6 +55,8 @@
 public:
     QBoxLayout            *box;
     bool                  hasStretchedWidget = false;
+    bool                  singleChild = false;
+    bool                  hasChild = false;
     QSpacerItem           *space;
     QBoxLayout::Direction direction;
     
--- a/ui/qt/window.cpp	Sun Dec 07 11:27:44 2025 +0100
+++ b/ui/qt/window.cpp	Sun Dec 07 11:51:01 2025 +0100
@@ -77,7 +77,7 @@
     return create_window(title, window_data, false);
 }
 
-UiObject* ui_simple_window(char *title, void *window_data) {
+UiObject* ui_simple_window(const char *title, void *window_data) {
     return create_window(title, window_data, true);
 }
 

mercurial