about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-11-21 18:05:36 -0700
committerIrene Knapp <ireneista@irenes.space>2026-11-21 18:05:36 -0700
commit3f9e377d790da460919bd9f6ab82402424744c96 (patch)
treefee055a61df10a7db6f767fdfc9a6ab60755e262 /src
parent6936dc8c1222a84f46b910a1907ff7fc7689b886 (diff)
there is now a concept of horizontal space allocated to modules
well, at draw-time. that's hopefully all that's needed, rather than anything across iterations. time will tell.

Force-Push: yes
Change-Id: I19cd2122777a4dc0d57ff6141055e455c035926c
Diffstat (limited to 'src')
-rw-r--r--src/main.rs50
1 files changed, 36 insertions, 14 deletions
diff --git a/src/main.rs b/src/main.rs
index 3753292..76e7fbb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -43,6 +43,7 @@ struct DockConfiguration {
   thickness: u16,
   baseline_offset: i8,
   edge_inset: i8,
+  intermodule_padding: i8,
   side: Side,
   background: Color,
   foreground: Color,
@@ -61,6 +62,11 @@ struct Dock {
   modules: Vec<(Arc<Mutex<Box<dyn Module>>>, ModuleFraming)>,
 }
 
+struct Parcel {
+  left: u32,
+  right: u32,
+}
+
 struct ModuleFraming {
   alignment: Alignment,
 }
@@ -133,6 +139,7 @@ impl DockConfiguration {
       thickness: 34,
       baseline_offset: 2,
       edge_inset: 12,
+      intermodule_padding: 24,
       side: Side::Bottom,
       background, foreground,
       use_rounded_inside_corners: false,
@@ -185,7 +192,7 @@ impl Dock {
     let facilities = Arc::new(Mutex::new(FacilityMap::new()));
     for facility_type in required_facilities.iter() {
       facilities.lock()?.insert(facility_type.clone(),
-				facility_type.new().await?);
+                                facility_type.new().await?);
     }
 
     let mut modules = Vec::new();
@@ -193,17 +200,17 @@ impl Dock {
       let mut facilities = facilities.lock()?;
 
       modules.push((Arc::new(Mutex::new(TimeModule::new(
-			facilities.borrow_mut())?.as_box())),
-		    ModuleFraming
+                        facilities.borrow_mut())?.as_box())),
+                    ModuleFraming
       {
-	alignment: Alignment::Right,
+        alignment: Alignment::Right,
       }));
 
       modules.push((Arc::new(Mutex::new(BatteryModule::new(
-			facilities.borrow_mut())?.as_box())),
-		    ModuleFraming
+                        facilities.borrow_mut())?.as_box())),
+                    ModuleFraming
       {
-	alignment: Alignment::Right,
+        alignment: Alignment::Right,
       }));
     }
 
@@ -325,14 +332,21 @@ impl Dock {
       self.draw_corners(drawable, &context)?;
     }
 
-    self.draw_text("playful cool fic tech nonfic", Alignment::Left)?;
+    let mut open_parcel = Parcel {
+      left: self.bounds.left as u32
+            + self.configuration.edge_inset as u32,
+      right: (self.bounds.left + self.bounds.width) as u32
+             - self.configuration.edge_inset as u32,
+    };
+
+    self.draw_text(&mut open_parcel, "playful cool fic tech nonfic", Alignment::Left)?;
 
     {
       let mut facilities = self.facilities.lock()?;
 
       for (module, framing) in &self.modules {
-	let text = module.lock()?.format(facilities.borrow_mut())?;
-	self.draw_text(&text, framing.alignment)?;
+        let text = module.lock()?.format(facilities.borrow_mut())?;
+        self.draw_text(&mut open_parcel, &text, framing.alignment)?;
       }
     }
 
@@ -438,7 +452,10 @@ impl Dock {
   }
 
 
-  fn draw_text(&self, text: &str, alignment: Alignment) -> Result<()> {
+  fn draw_text(&self, open_parcel: &mut Parcel, text: &str,
+               alignment: Alignment)
+    -> Result<()>
+  {
     let context = FontGraphicContext::new(self.window())?;
     let color = &self.configuration.foreground;
     let text = self.font.text_span(text)?;
@@ -449,11 +466,16 @@ impl Dock {
 
     match alignment {
       Alignment::Left => {
-        location.x += self.configuration.edge_inset as i32;
+        location.x += open_parcel.left as i32;
+
+        open_parcel.left += text.draw_size().width as u32;
+        open_parcel.left += self.configuration.intermodule_padding as u32;
       }
       Alignment::Right => {
-        location.x += self.bounds.width as i32 - text.draw_size().width as i32;
-        location.x -= self.configuration.edge_inset as i32;
+        location.x += open_parcel.right as i32 - text.draw_size().width as i32;
+
+        open_parcel.right -= text.draw_size().width as u32;
+        open_parcel.right -= self.configuration.intermodule_padding as u32;
       }
     }