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

commit42b9ca1ad4f47a208b6507e7ba947092a8274ade
parent751e18bb8f
authorLucas Galante <[email protected]>
date2026-07-06 14:31
Allow ButtonStrip to inherit menubar font and configure MenuBar menus to use it

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

diff --git a/src/widget/container/menu.rs b/src/widget/container/menu.rs
index d6a60b9..886ccf1 100644
--- a/src/widget/container/menu.rs
+++ b/src/widget/container/menu.rs
@@ -69,7 +69,7 @@ impl MenuBar {
             blur: false,
             color: None,
             title: String::new(),
-            menus: ButtonStrip::new(x, y, w, h),
+            menus: ButtonStrip::new(x, y, w, h).with_inherit_menubar_font(true),
             menu_items: Vec::new(),
             vertical_items: Vec::new(),
             menu_dropdowns: Vec::new(),
diff --git a/src/widget/input/button_strip.rs b/src/widget/input/button_strip.rs
index 0a740ed..4bdddea 100644
--- a/src/widget/input/button_strip.rs
+++ b/src/widget/input/button_strip.rs
@@ -16,6 +16,7 @@ pub struct ButtonStrip {
     pub last_padding: Option<f32>,
     pub last_font: Option<String>,
     pub last_scale: Option<f32>,
+    pub inherit_menubar_font: bool,
 }
 
 impl ButtonStrip {
@@ -33,6 +34,29 @@ impl ButtonStrip {
             last_padding: None,
             last_font: None,
             last_scale: None,
+            inherit_menubar_font: false,
+        }
+    }
+
+    pub fn with_inherit_menubar_font(mut self, inherit: bool) -> Self {
+        self.inherit_menubar_font = inherit;
+        self.generate_rotated_labels();
+        self
+    }
+
+    fn current_font(&self) -> String {
+        if self.inherit_menubar_font {
+            crate::layout::menubar_font()
+        } else {
+            crate::layout::button_strip_font()
+        }
+    }
+
+    fn current_font_parsed(&self) -> (String, f32) {
+        if self.inherit_menubar_font {
+            crate::layout::menubar_font_parsed()
+        } else {
+            crate::layout::button_strip_font_parsed()
         }
     }
 
@@ -77,7 +101,7 @@ impl ButtonStrip {
     pub fn generate_rotated_labels(&mut self) {
         let current_padding = crate::layout::button_padding();
         self.last_padding = Some(current_padding);
-        let current_font = crate::layout::button_strip_font();
+        let current_font = self.current_font();
         self.last_font = Some(current_font);
 
         self.tab_text_quads.clear();
@@ -94,7 +118,7 @@ impl ButtonStrip {
         let inactive_g = (active_g as f32 * 0.78) as u8;
         let inactive_b = (active_b as f32 * 0.78) as u8;
 
-        let (font_fam, font_size) = crate::layout::button_strip_font_parsed();
+        let (font_fam, font_size) = self.current_font_parsed();
         let scale = crate::scale::scale_factor().max(1.0);
         self.last_scale = Some(scale);
 
@@ -194,7 +218,7 @@ impl ButtonStrip {
         let get_button_weight = |i: usize| -> f32 {
             let label = &self.buttons[i];
             let trimmed = label.trim();
-            let font_info = crate::layout::button_strip_font_parsed();
+            let font_info = self.current_font_parsed();
             let font_fam = font_info.0;
             let font_size = font_info.1;
             let padding = crate::layout::button_padding();
@@ -264,7 +288,7 @@ impl Element for ButtonStrip {
     fn tick(&mut self, _dt: f32, _ctx: &mut UiContext) -> bool {
         let mut changed = false;
         let current_padding = crate::layout::button_padding();
-        let current_font = crate::layout::button_strip_font();
+        let current_font = self.current_font();
         let current_scale = crate::scale::scale_factor().max(1.0);
         if self.last_padding != Some(current_padding)
             || self.last_font.as_ref() != Some(&current_font)
@@ -385,7 +409,7 @@ impl Element for ButtonStrip {
 
     fn text_labels(&self) -> Vec<TextLabel> {
         let mut labels = Vec::new();
-        let font_info = crate::layout::button_strip_font_parsed();
+        let font_info = self.current_font_parsed();
         let font_fam = font_info.0;
         let font_size = font_info.1;
         for (i, btn_label) in self.buttons.iter().enumerate() {
@@ -466,7 +490,7 @@ impl Element for ButtonStrip {
     }
 
     fn widget_font(&self) -> Option<String> {
-        Some(crate::layout::button_strip_font())
+        Some(self.current_font())
     }
 }