summaryrefslogtreecommitdiff
path: root/src/layout/mod.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-10-10 23:36:17 +0200
committerLaurenz <laurmaedje@gmail.com>2019-10-10 23:38:03 +0200
commit8f788f9a4f5e970bbe6147987b711470d57aca8d (patch)
treecc89008dfdfc62ecf4eb2517d92ec7c7095fa573 /src/layout/mod.rs
parent61470fba68e9f19b481034427add5f3d8cfbc0a8 (diff)
Add standard `align` function and support right-alignment ➡️
Diffstat (limited to 'src/layout/mod.rs')
-rw-r--r--src/layout/mod.rs28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 6b040089..e5fdc42d 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -52,11 +52,20 @@ pub struct LayoutSpace {
pub dimensions: Size2D,
/// Padding that should be respected on each side.
pub padding: SizeBox,
+ /// The alignment to use for the content.
+ pub alignment: Alignment,
/// Whether to shrink the dimensions to fit the content or the keep the
/// original ones.
pub shrink_to_fit: bool,
}
+/// Where to align content.
+#[derive(Debug, Copy, Clone, Eq, PartialEq)]
+pub enum Alignment {
+ Left,
+ Right,
+}
+
impl LayoutSpace {
/// The actually usable area.
pub fn usable(&self) -> Size2D {
@@ -157,6 +166,7 @@ impl<'a, 'p> Layouter<'a, 'p> {
space: LayoutSpace {
dimensions: self.box_layouter.remaining(),
padding: SizeBox::zero(),
+ alignment: self.box_layouter.ctx.space.alignment,
shrink_to_fit: true,
},
flex_spacing: (self.style.line_spacing - 1.0) * Size::pt(self.style.font_size),
@@ -173,6 +183,7 @@ impl<'a, 'p> Layouter<'a, 'p> {
space: LayoutSpace {
dimensions: self.box_layouter.remaining(),
padding: SizeBox::zero(),
+ alignment: self.box_layouter.ctx.space.alignment,
shrink_to_fit: true,
},
})?;
@@ -196,8 +207,8 @@ impl<'a, 'p> Layouter<'a, 'p> {
/// Manipulates and optimizes a list of actions.
#[derive(Debug, Clone)]
pub struct ActionList {
+ pub origin: Size2D,
actions: Vec<LayoutAction>,
- origin: Size2D,
active_font: (usize, f32),
}
@@ -232,15 +243,12 @@ impl ActionList {
}
}
- /// Move the origin for the upcomming actions. Absolute moves will be
- /// changed by that origin.
- pub fn set_origin(&mut self, origin: Size2D) {
- self.origin = origin;
- }
-
- /// Reset the origin to zero.
- pub fn reset_origin(&mut self) {
- self.origin = Size2D::zero();
+ /// Add all actions from a box layout at a position. A move to the position
+ /// is generated and all moves inside the box layout are translated as necessary.
+ pub fn add_box_absolute(&mut self, position: Size2D, layout: BoxLayout) {
+ self.actions.push(LayoutAction::MoveAbsolute(position));
+ self.origin = position;
+ self.extend(layout.actions);
}
/// Whether there are any actions in this list.