git.lucas.co / cce-ui
GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git

commitbab9e97f1fc6fb891876f67b229cf48ff130f0c1
parenteaf248fc4c
authorLucas Galante <[email protected]>
date2026-07-05 00:56
Support row-based side-by-side control groups in ColumnLayout and refactor ControlPanel to use H-rows

 src/widget/container/control_panel.rs | 59 +++++++++++++++++++++--------------
 src/widget/layout_helper.rs           | 17 ++++++++++
 2 files changed, 53 insertions(+), 23 deletions(-)

diff --git a/src/widget/container/control_panel.rs b/src/widget/container/control_panel.rs
index 4489f20..2d55c22 100644
--- a/src/widget/container/control_panel.rs
+++ b/src/widget/container/control_panel.rs
@@ -149,18 +149,28 @@ impl Element for ControlPanel {
                 }
             }
 
-            if let Some(c) = create_btn {
-                col.add_widget(&mut *c, 28.0);
-            }
-            if let Some(t) = tile_btn {
-                col.add_widget(&mut *t, 28.0);
-            }
-            if let Some(w_sp) = width_spin {
-                col.add_widget(&mut *w_sp, 20.0);
+            if let (Some(c), Some(t)) = (create_btn, tile_btn) {
+                col.add_row(&[c, t], 28.0, 12.0);
+            } else {
+                if let Some(c) = create_btn {
+                    col.add_widget(&mut *c, 28.0);
+                }
+                if let Some(t) = tile_btn {
+                    col.add_widget(&mut *t, 28.0);
+                }
             }
-            if let Some(h_sp) = height_spin {
-                col.add_widget(&mut *h_sp, 20.0);
+
+            if let (Some(w_sp), Some(h_sp)) = (width_spin, height_spin) {
+                col.add_row(&[w_sp, h_sp], 20.0, 12.0);
+            } else {
+                if let Some(w_sp) = width_spin {
+                    col.add_widget(&mut *w_sp, 20.0);
+                }
+                if let Some(h_sp) = height_spin {
+                    col.add_widget(&mut *h_sp, 20.0);
+                }
             }
+
             if let Some(t_dd) = type_dd {
                 col.add_widget(&mut *t_dd, 20.0);
             }
@@ -176,29 +186,32 @@ impl Element for ControlPanel {
             if let Some(sl) = slider {
                 col.add_widget(&mut *sl, 20.0);
             }
+
             if let Some(w_s) = win_sec {
                 col.add_widget(&mut *w_s, 20.0);
             }
-            if let Some(bp_t) = backplate_toggle {
-                col.add_widget(&mut *bp_t, 20.0);
-            }
-            if let Some(mb_t) = menubar_toggle {
-                col.add_widget(&mut *mb_t, 20.0);
-            }
-            if let Some(sb_t) = statusbar_toggle {
-                col.add_widget(&mut *sb_t, 20.0);
+            let toggles = [backplate_toggle, menubar_toggle, statusbar_toggle];
+            let active_toggles: Vec<*mut dyn Element> = toggles.iter().filter_map(|&t| t).collect();
+            if !active_toggles.is_empty() {
+                col.add_row(&active_toggles, 20.0, 10.0);
             }
+
             if let Some(b_s) = border_sec {
                 col.add_widget(&mut *b_s, 20.0);
             }
             if let Some(bs_dd) = border_style_dd {
                 col.add_widget(&mut *bs_dd, 20.0);
             }
-            if let Some(bw_sp) = border_width_spin {
-                col.add_widget(&mut *bw_sp, 20.0);
-            }
-            if let Some(bd_sp) = bevel_depth_spin {
-                col.add_widget(&mut *bd_sp, 20.0);
+
+            if let (Some(bw_sp), Some(bd_sp)) = (border_width_spin, bevel_depth_spin) {
+                col.add_row(&[bw_sp, bd_sp], 20.0, 12.0);
+            } else {
+                if let Some(bw_sp) = border_width_spin {
+                    col.add_widget(&mut *bw_sp, 20.0);
+                }
+                if let Some(bd_sp) = bevel_depth_spin {
+                    col.add_widget(&mut *bd_sp, 20.0);
+                }
             }
             if let Some(bs_btn) = bevel_shape_btn {
                 col.add_widget(&mut *bs_btn, 28.0);
diff --git a/src/widget/layout_helper.rs b/src/widget/layout_helper.rs
index e1d086c..ec90102 100644
--- a/src/widget/layout_helper.rs
+++ b/src/widget/layout_helper.rs
@@ -26,6 +26,23 @@ impl ColumnLayout {
         self.current_y += height + self.gap;
     }
 
+    pub fn add_row(&mut self, widgets: &[*mut dyn Element], height: f32, gap: f32) {
+        let count = widgets.len();
+        if count == 0 {
+            return;
+        }
+        let total_width = self.width - 2.0 * self.margin;
+        let widget_w = (total_width - (count as f32 - 1.0) * gap) / count as f32;
+        let mut curr_x = self.x + self.margin;
+        for &widget_ptr in widgets {
+            unsafe {
+                (*widget_ptr).set_rect(curr_x, self.current_y, widget_w, height);
+            }
+            curr_x += widget_w + gap;
+        }
+        self.current_y += height + self.gap;
+    }
+
     pub fn current_y(&self) -> f32 {
         self.current_y - self.gap + self.margin
     }