Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-tui/src/layout.rs')
| -rw-r--r-- | helix-tui/src/layout.rs | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/helix-tui/src/layout.rs b/helix-tui/src/layout.rs index 83edc615..e6a84aa0 100644 --- a/helix-tui/src/layout.rs +++ b/helix-tui/src/layout.rs @@ -1,5 +1,3 @@ -//! Layout engine for terminal - use std::cell::RefCell; use std::collections::HashMap; @@ -9,7 +7,6 @@ use cassowary::{Constraint as CassowaryConstraint, Expression, Solver, Variable} use helix_view::graphics::{Margin, Rect}; -/// Enum of all corners #[derive(Debug, Hash, Clone, Copy, PartialEq, Eq)] pub enum Corner { TopLeft, @@ -18,14 +15,12 @@ pub enum Corner { BottomLeft, } -/// Direction a [Rect] should be split #[derive(Debug, Hash, Clone, PartialEq, Eq)] pub enum Direction { Horizontal, Vertical, } -/// Describes requirements of a [Rect] to be split #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum Constraint { // TODO: enforce range 0 - 100 @@ -51,15 +46,13 @@ impl Constraint { } } -/// How content should be aligned -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq)] pub enum Alignment { Left, Center, Right, } -/// Description of a how a [Rect] should be split #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Layout { direction: Direction, @@ -75,14 +68,16 @@ impl Default for Layout { fn default() -> Layout { Layout { direction: Direction::Vertical, - margin: Margin::none(), + margin: Margin { + horizontal: 0, + vertical: 0, + }, constraints: Vec::new(), } } } impl Layout { - /// Returns a layout with the given [Constraint]s. pub fn constraints<C>(mut self, constraints: C) -> Layout where C: Into<Vec<Constraint>>, @@ -91,26 +86,25 @@ impl Layout { self } - /// Returns a layout wit the given margins on all sides. - pub const fn margin(mut self, margin: u16) -> Layout { - self.margin = Margin::all(margin); + pub fn margin(mut self, margin: u16) -> Layout { + self.margin = Margin { + horizontal: margin, + vertical: margin, + }; self } - /// Returns a layout with the given horizontal margins. - pub const fn horizontal_margin(mut self, horizontal: u16) -> Layout { + pub fn horizontal_margin(mut self, horizontal: u16) -> Layout { self.margin.horizontal = horizontal; self } - /// Returns a layout with the given vertical margins. - pub const fn vertical_margin(mut self, vertical: u16) -> Layout { + pub fn vertical_margin(mut self, vertical: u16) -> Layout { self.margin.vertical = vertical; self } - /// Returns a layout with the given [Direction]. - pub const fn direction(mut self, direction: Direction) -> Layout { + pub fn direction(mut self, direction: Direction) -> Layout { self.direction = direction; self } @@ -201,7 +195,7 @@ fn split(area: Rect, layout: &Layout) -> Vec<Rect> { .map(|_| Rect::default()) .collect::<Vec<Rect>>(); - let dest_area = area.inner(layout.margin); + let dest_area = area.inner(&layout.margin); for (i, e) in elements.iter().enumerate() { vars.insert(e.x, (i, 0)); vars.insert(e.y, (i, 1)); |