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

commit68fe57a845b3419d1df63faf185b0731f637120f
parent2087d77d49
authorLucas Galante <[email protected]>
date2026-06-28 07:09
Support dynamic scrollinglist_justification and scrollinglist_font for ListRow buttons

 src/widget/input/button.rs | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/widget/input/button.rs b/src/widget/input/button.rs
index dae2fd6..a4caef8 100644
--- a/src/widget/input/button.rs
+++ b/src/widget/input/button.rs
@@ -220,10 +220,11 @@ impl Element for Button {
         let mut labels = Vec::new();
         if let Some(ref label) = self.base.label {
             let font_size = 12.0;
+            let font_family = self.widget_font().unwrap_or_else(|| "sans-serif".to_string());
             let est_w = if label == "📋" {
                 12.0
             } else {
-                crate::widget::display::measure_text(label, font_size)
+                crate::widget::display::measure_text_width(label, &font_family, font_size)
             };
             let color = if let Some(lc) = self.label_color {
                 [
@@ -240,7 +241,16 @@ impl Element for Button {
                     _ => [0xcc, 0xcc, 0xd4]
                 }
             };
-            let x = match self.justify {
+            let justify = if self.kind == ButtonKind::ListRow {
+                match crate::layout::scrollinglist_justification() {
+                    0 => Justification::Left,
+                    2 => Justification::Right,
+                    _ => Justification::Center,
+                }
+            } else {
+                self.justify
+            };
+            let x = match justify {
                 Justification::Left => self.base.x + 8.0,
                 Justification::Right => self.base.x + self.base.w - est_w - 8.0,
                 Justification::Center => self.base.x + (self.base.w - est_w) / 2.0,
@@ -273,7 +283,11 @@ impl Element for Button {
     }
 
     fn widget_font(&self) -> Option<String> {
-        Some(crate::layout::button_font())
+        if self.kind == ButtonKind::ListRow {
+            Some(crate::layout::scrollinglist_font())
+        } else {
+            Some(crate::layout::button_font())
+        }
     }
 
     fn corner_radius(&self) -> f32 {