diff --git a/compositor/shell/shell.mbt b/compositor/shell/shell.mbt index f35955c..a6cd8ab 100644 --- a/compositor/shell/shell.mbt +++ b/compositor/shell/shell.mbt @@ -170,6 +170,16 @@ pub fn DesktopShell::new(display : String) -> DesktopShell { } } +///| Truncate `s` with ".." so it fits `width` px (the renderer's small text is 6 px per char). +fn fit_title(s : String, width : Int) -> String { + let max_chars = width / 6 + if s.length() <= max_chars { + s + } else { + s[:max_chars - 2].to_string() + ".." + } +} + ///| fn inside(r : @scene.Rect, x : Int, y : Int) -> Bool { r.w > 0 && x >= r.x && x < r.x + r.w && y >= r.y && y < r.y + r.h @@ -312,7 +322,7 @@ pub fn DesktopShell::render( translate( [ @ui.fill_rect(@ui.rect(tx, 0, pill_w, p.h), tokens.palette.surface_hover, radius=tokens.radius.reinterpret_as_int()), - @ui.text(tx + 10, p.h / 2, title, tokens.font_size.reinterpret_as_int() - 2, tokens.palette.foreground), + @ui.text(tx + 10, p.h / 2, fit_title(title, pill_w - 20), tokens.font_size.reinterpret_as_int() - 2, tokens.palette.foreground), ], p.x, p.y,