diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 34 |
1 files changed, 27 insertions, 7 deletions
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<Rectangle<u16>>, - font: Font, + font: Arc<Font>, } 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::<i32>::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(()) } |