mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Add some doc.
This commit is contained in:
parent
781d9c1a03
commit
a77a40558f
13
src/align.rs
13
src/align.rs
@ -1,11 +1,13 @@
|
|||||||
//! Tools to control view alignment
|
//! Tools to control view alignment
|
||||||
|
|
||||||
|
/// Specifies the alignment along both horizontal and vertical directions.
|
||||||
pub struct Align {
|
pub struct Align {
|
||||||
pub h: HAlign,
|
pub h: HAlign,
|
||||||
pub v: VAlign,
|
pub v: VAlign,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Align {
|
impl Align {
|
||||||
|
/// Creates a new Align object from the given horizontal and vertical alignments.
|
||||||
pub fn new(h: HAlign, v: VAlign) -> Self {
|
pub fn new(h: HAlign, v: VAlign) -> Self {
|
||||||
Align {
|
Align {
|
||||||
h: h,
|
h: h,
|
||||||
@ -13,33 +15,40 @@ impl Align {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a top-left alignment.
|
||||||
pub fn top_left() -> Self {
|
pub fn top_left() -> Self {
|
||||||
Align::new(HAlign::Left, VAlign::Top)
|
Align::new(HAlign::Left, VAlign::Top)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a top-right alignment.
|
||||||
pub fn top_right() -> Self {
|
pub fn top_right() -> Self {
|
||||||
Align::new(HAlign::Right, VAlign::Top)
|
Align::new(HAlign::Right, VAlign::Top)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a bottom-left alignment.
|
||||||
pub fn bot_left() -> Self {
|
pub fn bot_left() -> Self {
|
||||||
Align::new(HAlign::Left, VAlign::Bottom)
|
Align::new(HAlign::Left, VAlign::Bottom)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a bottom-right alignment.
|
||||||
pub fn bot_right() -> Self {
|
pub fn bot_right() -> Self {
|
||||||
Align::new(HAlign::Right, VAlign::Top)
|
Align::new(HAlign::Right, VAlign::Top)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates an alignment centered both horizontally and vertically.
|
||||||
pub fn center() -> Self {
|
pub fn center() -> Self {
|
||||||
Align::new(HAlign::Center, VAlign::Center)
|
Align::new(HAlign::Center, VAlign::Center)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Horizontal alignment
|
||||||
pub enum HAlign {
|
pub enum HAlign {
|
||||||
Left,
|
Left,
|
||||||
Center,
|
Center,
|
||||||
Right,
|
Right,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Vertical alignment
|
||||||
pub enum VAlign {
|
pub enum VAlign {
|
||||||
Top,
|
Top,
|
||||||
Center,
|
Center,
|
||||||
@ -47,6 +56,8 @@ pub enum VAlign {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HAlign {
|
impl HAlign {
|
||||||
|
/// To draw a view with size `content` in a printer with size `container`, this returns the
|
||||||
|
/// offset to start printing the view at.
|
||||||
pub fn get_offset(&self, content: usize, container: usize) -> usize {
|
pub fn get_offset(&self, content: usize, container: usize) -> usize {
|
||||||
match *self {
|
match *self {
|
||||||
HAlign::Left => 0,
|
HAlign::Left => 0,
|
||||||
@ -57,6 +68,8 @@ impl HAlign {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl VAlign {
|
impl VAlign {
|
||||||
|
/// To draw a view with size `content` in a printer with size `container`, this returns the
|
||||||
|
/// offset to start printing the view at.
|
||||||
pub fn get_offset(&self, content: usize, container: usize) -> usize {
|
pub fn get_offset(&self, content: usize, container: usize) -> usize {
|
||||||
match *self {
|
match *self {
|
||||||
VAlign::Top => 0,
|
VAlign::Top => 0,
|
||||||
|
@ -68,6 +68,7 @@ pub enum Key {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Key {
|
impl Key {
|
||||||
|
/// Returns the Key enum corresponding to the given ncurses event.
|
||||||
pub fn from_ncurses(ch: i32) -> Self {
|
pub fn from_ncurses(ch: i32) -> Self {
|
||||||
match ch {
|
match ch {
|
||||||
// Tab is '\t'
|
// Tab is '\t'
|
||||||
@ -173,6 +174,7 @@ pub enum Event {
|
|||||||
KeyEvent(Key),
|
KeyEvent(Key),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generic trait to convert a value to an event.
|
||||||
pub trait ToEvent {
|
pub trait ToEvent {
|
||||||
fn to_event(self) -> Event;
|
fn to_event(self) -> Event;
|
||||||
}
|
}
|
||||||
|
@ -62,12 +62,16 @@ impl Dialog {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the horizontal alignment for the buttons, if any.
|
||||||
|
/// Only works if the buttons are as a row at the bottom of the dialog.
|
||||||
pub fn h_align(mut self, h: HAlign) -> Self {
|
pub fn h_align(mut self, h: HAlign) -> Self {
|
||||||
self.align.h = h;
|
self.align.h = h;
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the vertical alignment for the buttons, if any.
|
||||||
|
/// Only works if the buttons are as a column to the right of the dialog.
|
||||||
pub fn v_align(mut self, v: VAlign) -> Self {
|
pub fn v_align(mut self, v: VAlign) -> Self {
|
||||||
self.align.v = v;
|
self.align.v = v;
|
||||||
|
|
||||||
|
@ -56,18 +56,22 @@ impl <T: 'static> SelectView<T> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the alignment for this view.
|
||||||
pub fn align(mut self, align: Align) -> Self {
|
pub fn align(mut self, align: Align) -> Self {
|
||||||
self.align = align;
|
self.align = align;
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the vertical alignment for this view.
|
||||||
|
/// (If the ciew is given too much space vertically.)
|
||||||
pub fn v_align(mut self, v: VAlign) -> Self {
|
pub fn v_align(mut self, v: VAlign) -> Self {
|
||||||
self.align.v = v;
|
self.align.v = v;
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the horizontal alignment for this view.
|
||||||
pub fn h_align(mut self, h: HAlign) -> Self {
|
pub fn h_align(mut self, h: HAlign) -> Self {
|
||||||
self.align.h = h;
|
self.align.h = h;
|
||||||
|
|
||||||
|
@ -63,18 +63,21 @@ impl TextView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the horizontal alignment for this view.
|
||||||
pub fn h_align(mut self, h: HAlign) -> Self {
|
pub fn h_align(mut self, h: HAlign) -> Self {
|
||||||
self.align.h = h;
|
self.align.h = h;
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the vertical alignment for this view.
|
||||||
pub fn v_align(mut self, v: VAlign) -> Self {
|
pub fn v_align(mut self, v: VAlign) -> Self {
|
||||||
self.align.v = v;
|
self.align.v = v;
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the alignment for this view.
|
||||||
pub fn align(mut self, a: Align) -> Self {
|
pub fn align(mut self, a: Align) -> Self {
|
||||||
self.align = a;
|
self.align = a;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user