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

commit6c90e1e399d1efb37c4afd973f1cf9d3e39f91c4
parent2e1ffca270
authorLucas Galante <[email protected]>
date2026-06-15 22:37
Revert window_runner text scale factor to 1.0 and implement automated TextItem::new constructor

 src/backend/window_runner.rs    |  4 ++--
 src/widget/display/list_item.rs | 51 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/src/backend/window_runner.rs b/src/backend/window_runner.rs
index a2e13f1..0b7f2da 100644
--- a/src/backend/window_runner.rs
+++ b/src/backend/window_runner.rs
@@ -884,7 +884,7 @@ pub trait Application: Sized + 'static {
                 buffer: &ti.buffer,
                 left: (ti.x * scale_f32).round(),
                 top: (ti.y * scale_f32).round(),
-                scale: scale_f32,
+                scale: 1.0,
                 bounds: item_bounds,
                 default_color: ti.color,
                 custom_glyphs: &[],
@@ -1259,7 +1259,7 @@ impl<A: Application> EngineState<A> {
                     buffer: &ti.buffer,
                     left: (ti.x * scale_f32).round(),
                     top: (ti.y * scale_f32).round(),
-                    scale: scale_f32,
+                    scale: 1.0,
                     bounds,
                     default_color: ti.color,
                     custom_glyphs: &[],
diff --git a/src/widget/display/list_item.rs b/src/widget/display/list_item.rs
index c85fd45..31ec337 100644
--- a/src/widget/display/list_item.rs
+++ b/src/widget/display/list_item.rs
@@ -11,6 +11,57 @@ pub struct TextItem {
     pub bounds: Option<[f32; 4]>,
 }
 
+impl TextItem {
+    pub fn new(
+        fs: &mut glyphon::FontSystem,
+        text: &str,
+        size: f32,
+        x: f32,
+        y: f32,
+        color: glyphon::Color,
+        font: Option<&str>,
+        bounds: Option<[f32; 4]>,
+    ) -> Self {
+        let scale = crate::scale::scale_factor();
+        let mut font_size = size;
+        let mut family_name = None;
+
+        if let Some(font_str) = font {
+            let (parsed_family, parsed_size) = crate::layout::parse_font_string(font_str);
+            if let Some(ps) = parsed_size {
+                font_size = ps;
+            }
+            family_name = Some(parsed_family);
+        }
+
+        let physical_size = font_size * scale;
+        let metrics = glyphon::Metrics::new(physical_size, physical_size * 1.4);
+        let mut buffer = glyphon::Buffer::new(fs, metrics);
+        let mut attrs = glyphon::Attrs::new();
+
+        if let Some(ref fam) = family_name {
+            let family = match fam.as_str() {
+                "monospace" => glyphon::Family::Name(crate::layout::get_system_monospace_font()),
+                "sans-serif" => glyphon::Family::SansSerif,
+                "serif" => glyphon::Family::Serif,
+                _ => glyphon::Family::Name(fam),
+            };
+            attrs = attrs.family(family);
+        }
+
+        buffer.set_text(fs, text, attrs, glyphon::Shaping::Advanced);
+        buffer.shape_until_scroll(fs, true);
+
+        Self {
+            buffer,
+            x,
+            y,
+            color,
+            bounds,
+        }
+    }
+}
+
 #[derive(Debug, Clone)]
 pub struct InteractiveListItem {
     base: Widget,