Crate cursive_aligned_view
source · [−]Expand description
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, CursiveExt};
use cursive::view::Resizable;
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
Resizable
and Identifiable
traits.
As an alternative you can use the AlignedView
constructors directly:
use cursive::{Cursive, CursiveExt};
use cursive::view::Resizable;
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
This struct aligns a child view with a given alignment.
Traits
Use this trait to extend all cursive::view::View
instances to support
the align_...
methods.