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

commitbfca7ba08bd1c2657582ff7568dcad4fbbc004f3
parent19a3961e97
authorLucas Galante <[email protected]>
date2026-06-21 09:31
layout: fix text cutoff in menubar buttons by using actual menubar font-size and button_padding

 src/widget/container/menu.rs     | 13 +++++++------
 src/widget/input/button_strip.rs | 14 +++++++-------
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/widget/container/menu.rs b/src/widget/container/menu.rs
index 9169c05..0c5a465 100644
--- a/src/widget/container/menu.rs
+++ b/src/widget/container/menu.rs
@@ -354,7 +354,6 @@ impl Element for MenuBar {
         let font_setting = crate::layout::menubar_font();
         let (_, font_size_opt) = crate::layout::parse_font_string(&font_setting);
         let font_size = font_size_opt.unwrap_or(12.0);
-        let char_w = 7.5 * (font_size / 12.0);
 
         if self.vertical {
             let mut cy = 16.0;
@@ -381,7 +380,7 @@ impl Element for MenuBar {
             let mut dummy = crate::context::UiContext::new();
             self.menus.set_parent(Some(parent_ptr), &mut dummy);
         } else {
-            let padding_x = crate::layout::paginator_tab_padding_x();
+            let padding = crate::layout::button_padding();
             let mut cx = 8.0;
             if self.center_items {
                 let mut total_width = 8.0;
@@ -390,11 +389,12 @@ impl Element for MenuBar {
                     if !self.context_options.is_empty() {
                         display_title.push_str(" ▼");
                     }
-                    total_width += display_title.len() as f32 * char_w + 24.0;
+                    total_width += TextLabel::estimate_width(&display_title, font_size) + 24.0;
                 }
                 let mut btn_strip_w = 0.0;
                 for btn_label in &self.menus.buttons {
-                    btn_strip_w += btn_label.len() as f32 * char_w + 2.0 * padding_x;
+                    let text_w = TextLabel::estimate_width(btn_label, font_size);
+                    btn_strip_w += text_w + 2.0 * padding;
                 }
                 total_width += btn_strip_w;
                 if self.base.w > total_width {
@@ -406,11 +406,12 @@ impl Element for MenuBar {
                 if !self.context_options.is_empty() {
                     display_title.push_str(" ▼");
                 }
-                cx += display_title.len() as f32 * char_w + 24.0;
+                cx += TextLabel::estimate_width(&display_title, font_size) + 24.0;
             }
             let mut btn_strip_w = 0.0;
             for btn_label in &self.menus.buttons {
-                btn_strip_w += btn_label.len() as f32 * char_w + 2.0 * padding_x;
+                let text_w = TextLabel::estimate_width(btn_label, font_size);
+                btn_strip_w += text_w + 2.0 * padding;
             }
             let menus_x = (clamped_x + cx).clamp(clamped_x, clamped_x + clamped_w);
             let menus_w = btn_strip_w.min(clamped_x + clamped_w - menus_x);
diff --git a/src/widget/input/button_strip.rs b/src/widget/input/button_strip.rs
index c0aad8d..3621a5a 100644
--- a/src/widget/input/button_strip.rs
+++ b/src/widget/input/button_strip.rs
@@ -180,6 +180,8 @@ impl ButtonStrip {
         let get_button_weight = |i: usize| -> f32 {
             let label = &self.buttons[i];
             let trimmed = label.trim();
+            let font_size = crate::layout::menubar_font_parsed().1;
+            let padding = crate::layout::button_padding();
             if self.vertical {
                 let space_idx = trimmed.find(' ');
                 let has_icon = space_idx.map(|idx| trimmed.split_at(idx).0.trim().chars().count() == 1).unwrap_or(false);
@@ -188,14 +190,12 @@ impl ButtonStrip {
                 } else {
                     trimmed
                 };
-                let padding_y = crate::layout::button_padding();
-                let y_offset = if has_icon { 2.0 * padding_y + 12.0 } else { 0.0 };
-                let text_w = TextLabel::estimate_width(label_text, 12.0);
-                (text_w + y_offset + 2.0 * padding_y).max(1.0)
+                let y_offset = if has_icon { 2.0 * padding + 12.0 } else { 0.0 };
+                let text_w = TextLabel::estimate_width(label_text, font_size);
+                (text_w + y_offset + 2.0 * padding).max(1.0)
             } else {
-                let padding_x = crate::layout::paginator_tab_padding_x();
-                let text_w = TextLabel::estimate_width(label, 12.0);
-                (text_w + 2.0 * padding_x).max(1.0)
+                let text_w = TextLabel::estimate_width(label, font_size);
+                (text_w + 2.0 * padding).max(1.0)
             }
         };