summaryrefslogtreecommitdiff
path: root/src/layout/flex.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-06-17 10:08:16 +0200
committerLaurenz <laurmaedje@gmail.com>2019-06-17 10:08:16 +0200
commitb53ad6b1ec8b2fd05566a83c9b895f265e61d281 (patch)
tree1c6d590ead7180fbef12915cfcd04418c9ea7902 /src/layout/flex.rs
parent236ebab23a106ca817de527ce6b6440d3b66c150 (diff)
Introduce flex layouting 🎈
Diffstat (limited to 'src/layout/flex.rs')
-rw-r--r--src/layout/flex.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/layout/flex.rs b/src/layout/flex.rs
new file mode 100644
index 00000000..faddc95a
--- /dev/null
+++ b/src/layout/flex.rs
@@ -0,0 +1,61 @@
+//! Flexible and lazy layouting of boxes.
+
+use super::{Layouter, LayoutContext, BoxLayout};
+
+
+/// A flex layout consists of a yet unarranged list of boxes.
+#[derive(Debug, Clone)]
+pub struct FlexLayout {
+ /// The sublayouts composing this layout.
+ layouts: Vec<BoxLayout>,
+}
+
+impl FlexLayout {
+ /// Compute the layout.
+ pub fn into_box(self) -> BoxLayout {
+ // TODO: Do the justification.
+ unimplemented!()
+ }
+}
+
+/// Layouts boxes next to each other (inline-style) lazily.
+#[derive(Debug)]
+pub struct FlexLayouter<'a, 'p> {
+ ctx: &'a LayoutContext<'a, 'p>,
+ layouts: Vec<BoxLayout>,
+}
+
+impl<'a, 'p> FlexLayouter<'a, 'p> {
+ /// Create a new flex layouter.
+ pub fn new(ctx: &'a LayoutContext<'a, 'p>) -> FlexLayouter<'a, 'p> {
+ FlexLayouter {
+ ctx,
+ layouts: vec![],
+ }
+ }
+
+ /// Add a sublayout.
+ pub fn add_box(&mut self, layout: BoxLayout) {
+ self.layouts.push(layout);
+ }
+
+ /// Add all sublayouts of another flex layout.
+ pub fn add_flexible(&mut self, layout: FlexLayout) {
+ self.layouts.extend(layout.layouts);
+ }
+}
+
+impl Layouter for FlexLayouter<'_, '_> {
+ type Layout = FlexLayout;
+
+ /// Finish the layouting and create a flexible layout from this.
+ fn finish(self) -> FlexLayout {
+ FlexLayout {
+ layouts: self.layouts
+ }
+ }
+
+ fn is_empty(&self) -> bool {
+ self.layouts.is_empty()
+ }
+}