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.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/helix-tui/src/layout.rs b/helix-tui/src/layout.rs
index 50a16415..83edc615 100644
--- a/helix-tui/src/layout.rs
+++ b/helix-tui/src/layout.rs
@@ -1,3 +1,5 @@
+//! Layout engine for terminal
+
use std::cell::RefCell;
use std::collections::HashMap;
@@ -7,6 +9,7 @@ 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,
@@ -15,12 +18,14 @@ 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
@@ -46,6 +51,7 @@ impl Constraint {
}
}
+/// How content should be aligned
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Alignment {
Left,
@@ -53,6 +59,7 @@ pub enum Alignment {
Right,
}
+/// Description of a how a [Rect] should be split
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Layout {
direction: Direction,
@@ -75,6 +82,7 @@ impl Default for Layout {
}
impl Layout {
+ /// Returns a layout with the given [Constraint]s.
pub fn constraints<C>(mut self, constraints: C) -> Layout
where
C: Into<Vec<Constraint>>,
@@ -83,21 +91,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);
self
}
+ /// Returns a layout with the given horizontal margins.
pub const 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 {
self.margin.vertical = vertical;
self
}
+ /// Returns a layout with the given [Direction].
pub const fn direction(mut self, direction: Direction) -> Layout {
self.direction = direction;
self