From c8e87126b038a5f70b7c5a0eac018c0d12486f43 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Fri, 13 Nov 2026 22:08:48 -0700 Subject: reverse-engineer font ascent and descent, and rely on them we now do the baseline computation "properly", during setup, rather than during text rendering. this allows us to be consistent about it; prior to this, the two spans of text we draw would often wind up with different baselines. Force-Push: yes Change-Id: Ic2f34c816fc0767d6e54c5415beb516f99cd3069 --- src/main.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 61abb5c..aa0eb0c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,6 +35,7 @@ struct Dock { window: Window, bounds: Arc>, font: Arc, + baseline_position: i16, } impl HasWindow for Dock { @@ -53,7 +54,7 @@ fn main() -> xcb::Result<()> { let dock = Dock::new(Arc::clone(&display), DockConfiguration { thickness: 34, - baseline_offset: 3, + baseline_offset: 2, edge_inset: 12, side: Side::Bottom, background, foreground, @@ -112,13 +113,20 @@ impl Dock { ], })?; - let font = Arc::new(Font::new(Arc::clone(&display), - "FantasqueSansM Nerd Font Mono:style=Regular:size=18")?); + let font = Font::new(Arc::clone(&display), + "FantasqueSansM Nerd Font Mono:style=Regular:size=18")?; + + let font_height = font.ascent() + font.descent(); + let vertical_padding = (dock_bounds.height - font_height) / 2; + let baseline_position = font.ascent() as i16 + + vertical_padding as i16 + + configuration.baseline_offset as i16; let dock = Dock { window, configuration, bounds: Arc::new(dock_bounds), - font + font, + baseline_position }; dock.set_string_property(&xcb::x::ATOM_WM_NAME, b"sandbar")?; @@ -225,7 +233,7 @@ impl Dock { } self.draw_text("playful cool fic tech nonfic", Alignment::Left)?; - self.draw_text("abcy", Alignment::Right)?; + self.draw_text("2026", Alignment::Right)?; Ok(()) } @@ -314,9 +322,8 @@ impl Dock { let text = self.font.text_span(text)?; let mut location = Point::::zero(); - location = location.add_offset(&text.draw_offset()); - location.y += ((self.bounds.height - text.draw_size().height) / 2) as i32; - location.y += self.configuration.baseline_offset as i32; + location.x += text.draw_offset().x as i32; + location.y += self.baseline_position as i32; match alignment { Alignment::Left => { -- cgit 1.4.1