about summary refs log tree commit diff
path: root/src/x/text_line.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/x/text_line.rs')
-rw-r--r--src/x/text_line.rs40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/x/text_line.rs b/src/x/text_line.rs
index 579f96f..26ee8bf 100644
--- a/src/x/text_line.rs
+++ b/src/x/text_line.rs
@@ -1,5 +1,7 @@
 use crate::error::Result;
-use crate::x::{ Font, FontList, TextSpan };
+use crate::geometry::{ Alignment, Point };
+use crate::layout::Parcel;
+use crate::x::{ Color, Font, FontGraphicContext, FontList, TextSpan };
 
 use std::sync::{ Arc, Mutex };
 
@@ -53,5 +55,41 @@ impl TextLine {
   pub fn spans(&self) -> impl Iterator<Item=&TextSpan> + DoubleEndedIterator {
     self.spans.iter()
   }
+
+  pub fn layout_and_draw(&self, open_parcel: &mut Parcel,
+                         alignment: Alignment, context: &FontGraphicContext,
+                         color: &Color, baseline_position: i16)
+    -> Result<()>
+  {
+    let mut location = Point::<i32>::zero();
+    location.y += baseline_position as i32;
+
+    match alignment {
+      Alignment::Left => {
+        location.x += open_parcel.left as i32;
+      }
+      Alignment::Right => {
+        location.x += open_parcel.right as i32;
+      }
+    }
+
+    /* A reversed iterator is a different type, so we need two of this loop. */
+    match alignment {
+      Alignment::Left => {
+        for span in self.spans() {
+          span.layout_and_draw(open_parcel, &mut location,
+                               alignment, context, color)?;
+        }
+      }
+      Alignment::Right => {
+        for span in self.spans().rev() {
+          span.layout_and_draw(open_parcel, &mut location,
+                                    alignment, context, color)?;
+        }
+      }
+    }
+
+    Ok(())
+  }
 }