about summary refs log tree commit diff
path: root/src/main.rs
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-11-13 21:03:36 -0700
committerIrene Knapp <ireneista@irenes.space>2026-11-13 21:03:36 -0700
commit15207d15aef96e1d38bd5fd0ee6bd8b6686efb36 (patch)
tree9ba6b372fd1976f4538a059f8da5f1374e1943fc /src/main.rs
parente521722f5fd339ef72ee51af88f3941b71b1d9cf (diff)
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
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs34
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(())
   }