[][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

AlignmentConstruction method
top leftalign_top_left
top centeralign_top_center
top rightalign_top_right
center leftalign_center_left
centeralign_center
center rightalign_center_right
bottom leftalign_bottom_left
bottom centeralign_bottom_center
bottom rightalign_bottom_right

Structs

AlignedView

This struct aligns a child view with a given alignment.

Traits

Alignable

Use this trait to extend all cursive::view::View instances to support the align_... methods.