[−][src]Crate cursive_aligned_view
Align cursive views
This crate provides an AlignedView
for
gyscos/cursive views which makes it
possible to align the child view (center, left, right, top, bottom). The
AlignedView
uses the required_size
reported by the child view and fills
the rest of the available space with the views background color.
Aligning a child view
The easiest way to align a view is via the Alignable
trait:
use cursive::Cursive; use cursive::view::Boxable; use cursive::views::{Panel, DummyView}; use cursive_aligned_view::Alignable; fn main() { let mut siv = Cursive::default(); let panel = Panel::new(DummyView) .title("Hello, world!") .fixed_width(20) .align_center(); siv.add_fullscreen_layer(panel); // siv.run() }
This is the preferred way as it is chainable and consistent with cursive's
Boxable
and Identifiable
traits.
As an alternative you can use the AlignedView
constructors directly:
use cursive::Cursive; use cursive::view::Boxable; use cursive::views::{Panel, DummyView}; use cursive_aligned_view::AlignedView; fn main() { let mut siv = Cursive::default(); let panel = Panel::new(DummyView) .title("Hello, world!") .fixed_width(20); let aligned = AlignedView::with_center(panel); siv.add_fullscreen_layer(aligned); // siv.run() }
Supported Alignments
Alignment | Construction method |
---|---|
top left | align_top_left |
top center | align_top_center |
top right | align_top_right |
center left | align_center_left |
center | align_center |
center right | align_center_right |
bottom left | align_bottom_left |
bottom center | align_bottom_center |
bottom right | align_bottom_right |
Structs
AlignedView | This struct aligns a child view with a given alignment. |
Traits
Alignable | Use this trait to extend all |