From 15207d15aef96e1d38bd5fd0ee6bd8b6686efb36 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Fri, 13 Nov 2026 21:03:36 -0700 Subject: messing with metrics thus far, everything is reverse engineered and documented. we're about as confident as we can be of these descriptions, without searching Usenet for historical nuance or reading the xft source. in future work, it will be necessary to pick some specific characters to measure to reverse-engineer the desirable metrics. Force-Push: yes Change-Id: I54c7afb825909688d5a9b3f80974d76a69655796 --- src/main.rs | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 9decfbd..61abb5c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,8 @@ mod x; struct DockConfiguration { thickness: u16, + baseline_offset: i8, + edge_inset: i8, side: Side, background: Color, foreground: Color, @@ -32,7 +34,7 @@ struct Dock { configuration: DockConfiguration, window: Window, bounds: Arc>, - font: Font, + font: Arc, } impl HasWindow for Dock { @@ -51,6 +53,8 @@ fn main() -> xcb::Result<()> { let dock = Dock::new(Arc::clone(&display), DockConfiguration { thickness: 34, + baseline_offset: 3, + edge_inset: 12, side: Side::Bottom, background, foreground, use_rounded_inside_corners: false, @@ -108,8 +112,8 @@ impl Dock { ], })?; - let font = Font::new(Arc::clone(&display), - "FantasqueSansM Nerd Font Mono:style=Regular:size=18")?; + let font = Arc::new(Font::new(Arc::clone(&display), + "FantasqueSansM Nerd Font Mono:style=Regular:size=18")?); let dock = Dock { window, configuration, @@ -220,7 +224,8 @@ impl Dock { self.draw_corners(drawable, &context)?; } - self.draw_text()?; + self.draw_text("playful cool fic tech nonfic", Alignment::Left)?; + self.draw_text("abcy", Alignment::Right)?; Ok(()) } @@ -303,12 +308,27 @@ impl Dock { } - fn draw_text(&self) -> xcb::Result<()> { + fn draw_text(&self, text: &str, alignment: Alignment) -> xcb::Result<()> { let context = FontGraphicContext::new(self.window())?; let color = &self.configuration.foreground; - let text = "playful cool fic tech nonfic"; + let text = self.font.text_span(text)?; - self.font.draw(&context, color, 12, 25, 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; + + match alignment { + Alignment::Left => { + location.x += self.configuration.edge_inset as i32; + } + Alignment::Right => { + location.x += self.bounds.width as i32 - text.draw_size().width as i32; + location.x -= self.configuration.edge_inset as i32; + } + } + + text.draw(&context, color, location)?; Ok(()) } -- cgit 1.4.1