ui/qt/container.cpp

changeset 959
4b2202df31ec
parent 822
54e43e4efac2
--- 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) {

mercurial