Module unsegen::container [−][src]
Expand description
Higher level window manager like functionality using containers as the combination of widget and input concepts.
Compose widgets into multi-widget applications using Containers
and ContainerManager
as the
analogon of a window manager.
Example:
use unsegen::base::*; use unsegen::container::*; use unsegen::input::*; use unsegen::widget::builtin::*; use unsegen::widget::*; use std::io::{stdin, stdout}; struct Pager { buffer: LogViewer, } impl Pager { fn new() -> Self { Pager { buffer: LogViewer::new(), } } } impl Container<()> for Pager { fn input(&mut self, input: Input, _: &mut ()) -> Option<Input> { input .chain( ScrollBehavior::new(&mut self.buffer) .backwards_on(Key::Char('k')) .forwards_on(Key::Char('j')), ) .finish() } fn as_widget<'a>(&'a self) -> Box<dyn Widget + 'a> { Box::new(self.buffer.as_widget()) } } #[derive(Clone, PartialEq, Debug)] enum Index { Left, Right, } struct App { left: Pager, right: Pager, } impl ContainerProvider for App { type Context = (); type Index = Index; fn get<'a, 'b: 'a>(&'b self, index: &'a Self::Index) -> &'b dyn Container<Self::Context> { match index { Index::Left => &self.left, Index::Right => &self.right, } } fn get_mut<'a, 'b: 'a>( &'b mut self, index: &'a Self::Index, ) -> &'b mut dyn Container<Self::Context> { match index { Index::Left => &mut self.left, Index::Right => &mut self.right, } } const DEFAULT_CONTAINER: Self::Index = Index::Left; } fn main() { let stdout = stdout(); let stdin = stdin(); let stdin = stdin.lock(); let mut app = App { left: Pager::new(), right: Pager::new(), }; let mut manager = ContainerManager::<App>::from_layout(Box::new(VSplit::new(vec![ (Box::new(Leaf::new(Index::Left)), 0.8), (Box::new(Leaf::new(Index::Right)), 0.2), ]))); let mut term = Terminal::new(stdout.lock()).unwrap(); for input in Input::read_all(stdin) { let input = input.unwrap(); input .chain(manager.active_container_behavior(&mut app, &mut ())) .chain( NavigateBehavior::new(&mut manager.navigatable(&mut app)) .left_on(Key::Char('h')) .right_on(Key::Char('l')), ); // Put more application logic here... { let win = term.create_root_window(); manager.draw( win, &mut app, StyleModifier::new().fg_color(Color::Yellow), RenderingHints::default(), ) } term.present(); } }
Modules
boxdrawing | Utility functions for unicode box characters |
Structs
ActiveContainerBehavior | A |
ContainerManager | Stores the layout of containers and manages and has a concept of an active container. |
HSplit | A |
HorizontalLine | A single line occupying a number of cells in a row. |
LayoutOutput | The result of a layouting operation for containers. |
Leaf | A |
NavigatableContainerManager | A wrapper allowing for user defined modification of the currently active container using
|
Rectangle | A simple rectangle with integer coordinates. Nothing to see here. |
VSplit | A |
VerticalLine | A single line occupying a number of cells in a column. |
Enums
Line | An axis aligned line, either vertical or horizontal. |
Traits
Container | Extension to the widget trait to enable passing input to (active) widgets. The parameter C (i.e., the context) can be used to manipulate global application state. |
ContainerProvider | A ContainerProvider stores the individual components ( |
Layout | A Layouter managing screen real estate for multiple containers |