[−][src]Module unsegen::widget
Widget abstraction and some basic Widgets useful for creating basic building blocks of text user interfaces.
Example:
use unsegen::base::*; use unsegen::widget::*; use unsegen::widget::builtin::*; use std::io::stdout; struct MyWidget { layout: VerticalLayout, prompt: PromptLine, buffer: LogViewer, } impl Widget for MyWidget { fn space_demand(&self) -> Demand2D { let widgets: Vec<&Widget> = vec![&self.prompt, &self.buffer]; self.layout.space_demand(widgets.as_slice()) } fn draw(&self, window: Window, hints: RenderingHints) { let widgets: Vec<(&Widget, RenderingHints)> = vec![(&self.prompt, hints), (&self.buffer, hints.active(false))]; self.layout.draw(window, widgets.as_slice()); } } fn main() { let stdout = stdout(); let mut term = Terminal::new(stdout.lock()).unwrap(); let mut widget = MyWidget { layout: VerticalLayout::new( SeparatingStyle::AlternatingStyle(StyleModifier::new().invert(true)) ), prompt: PromptLine::with_prompt(" > ".to_owned()), buffer: LogViewer::new(), }; loop { // Put application logic here: read input, chain behavior, react to other stuff { let win = term.create_root_window(); widget.draw(win, RenderingHints::new().active(true)); } term.present(); } }
Re-exports
pub use self::layouts::*; |
pub use self::widget::*; |
Modules
builtin | This module contains several basic widgets that are built into the core library. |
layouts | Basic linear layouting for |
widget | The |
Functions
count_grapheme_clusters | Count the number of grapheme clusters in the given string. |
text_width | Calculate the (monospace) width of the given string. |