Struct unsegen::base::window::Window[][src]

pub struct Window<'w> { /* fields omitted */ }
Expand description

A rectangular view into a terminal buffer, i.e., a grid of grapheme clusters.

Moreover, a window always has a default style that is applied to all characters that are written to it. By default this is a “plain” style that does not change color or text format.

Side note: Grapheme clusters do not always have a width of a singular cell, and thus things can quite complicated. Therefore, Multi-width characters occupy more than once cell in a single window. If any of the cells is overwritten, potentially left-over cells are overwritten with space characters.

Implementations

impl<'w> Window<'w>[src]

pub fn get_extent<D: AxisDimension>(&self) -> PositiveAxisDiff<D>[src]

Get the extent of the window in the specified dimension (i.e., its width or height)

pub fn get_width(&self) -> Width[src]

Get the width (i.e., number of columns) that the window occupies.

pub fn get_height(&self) -> Height[src]

Get the height (i.e., number of rows) that the window occupies.

pub fn create_subwindow<'a, WX: RangeBounds<ColIndex>, WY: RangeBounds<RowIndex>>(
    &'a mut self,
    x_range: WX,
    y_range: WY
) -> Window<'a>
[src]

Create a subview of the window.

Examples:

use unsegen::base::{ColIndex, RowIndex, GraphemeCluster};

let mut win = term.create_root_window();
{
    let mut w = win.create_subwindow(
        ColIndex::new(0) .. ColIndex::new(2),
        RowIndex::new(2) .. RowIndex::new(4)
        );
    w.fill(GraphemeCluster::try_from('A').unwrap());
}
{
    let mut w = win.create_subwindow(
        ColIndex::new(2) .. ColIndex::new(4),
        RowIndex::new(0) .. RowIndex::new(2)
        );
    w.fill(GraphemeCluster::try_from('B').unwrap());
}

Panics:

Panics on invalid ranges, i.e., if: start > end, start < 0, or end > [width of the window]

pub fn split<D: AxisDimension>(
    self,
    split_pos: AxisIndex<D>
) -> Result<(Self, Self), Self>
[src]

Split the window horizontally or vertically into two halves.

If the split position is invalid (i.e., larger than the height/width of the window or negative), the original window is returned untouched as the error value. split_pos defines the first row of the second window.

Examples:

use unsegen::base::*;

let mut wb = WindowBuffer::new(Width::new(5).unwrap(), Height::new(5).unwrap());
{
    let win = wb.as_window();
    let (w1, w2) = win.split(RowIndex::new(3)).unwrap();
    assert_eq!(w1.get_height(), Height::new(3).unwrap());
    assert_eq!(w1.get_width(), Width::new(5).unwrap());
    assert_eq!(w2.get_height(), Height::new(2).unwrap());
    assert_eq!(w2.get_width(), Width::new(5).unwrap());
}
{
    let win = wb.as_window();
    let (w1, w2) = win.split(ColIndex::new(3)).unwrap();
    assert_eq!(w1.get_height(), Height::new(5).unwrap());
    assert_eq!(w1.get_width(), Width::new(3).unwrap());
    assert_eq!(w2.get_height(), Height::new(5).unwrap());
    assert_eq!(w2.get_width(), Width::new(2).unwrap());
}

pub fn fill(&mut self, c: GraphemeCluster)[src]

Fill the window with the specified GraphemeCluster.

The style is defined by the default style of the window. If the grapheme cluster is wider than 1 cell, any left over cells are filled with space characters.

Examples:

use unsegen::base::*;
let mut wb = WindowBuffer::new(Width::new(5).unwrap(), Height::new(5).unwrap());
wb.as_window().fill(GraphemeCluster::try_from('X').unwrap());
// Every cell of wb now contains an 'X'.

wb.as_window().fill(GraphemeCluster::try_from('山').unwrap());
// Every row of wb now contains two '山', while the last column cotains spaces.

pub fn clear(&mut self)[src]

Fill the window with space characters.

The style (i.e., the background color) is defined by the default style of the window.

Examples:

use unsegen::base::*;
let mut wb = WindowBuffer::new(Width::new(5).unwrap(), Height::new(5).unwrap());
wb.as_window().clear();
// Every cell of wb now contains a ' '.

pub fn set_default_style(&mut self, style: Style)[src]

Specify the new default style of the window. This style will be applied to all grapheme clusters written to the window.

Examples:

use unsegen::base::*;
let mut wb = WindowBuffer::new(Width::new(5).unwrap(), Height::new(5).unwrap());
let mut win = wb.as_window();
win.set_default_style(StyleModifier::new().fg_color(Color::Red).bg_color(Color::Blue).apply_to_default());
win.clear();
// wb is now cleared and has a blue background.

pub fn modify_default_style(&mut self, modifier: StyleModifier)[src]

Specify the new default style of the window. This style will be applied to all grapheme clusters written to the window.

Examples:

use unsegen::base::*;
let mut wb = WindowBuffer::new(Width::new(5).unwrap(), Height::new(5).unwrap());
let mut win = wb.as_window();
win.set_default_style(StyleModifier::new().fg_color(Color::Red).bg_color(Color::Blue).apply_to_default());
win.clear();
// wb is now cleared an has a blue background.

win.modify_default_style(StyleModifier::new().bg_color(Color::Yellow));
win.clear();
// wb is now cleared an has a yellow background.

assert_eq!(*win.default_style(),
    StyleModifier::new().fg_color(Color::Red).bg_color(Color::Yellow).apply_to_default())

pub fn default_style(&self) -> &Style[src]

Get the current default style of the window.

Change the default style using modify_default_style or set_default_style.

Trait Implementations

impl<'a> CursorTarget for Window<'a>[src]

fn get_width(&self) -> Width[src]

Return the actual width of the window. Writing to a column outside of this range is not possible. Read more

fn get_height(&self) -> Height[src]

Return the maximum height of the target. Writing to a row outside of this range is not possible. Read more

fn get_cell_mut(
    &mut self,
    x: ColIndex,
    y: RowIndex
) -> Option<&mut StyledGraphemeCluster>
[src]

Get the (mutable) cell at the specified position. The implementor must ensure that in the range for x \in [0, Width) and y \in [0, Height) a valid cluster is returned. Read more

fn get_cell(&self, x: ColIndex, y: RowIndex) -> Option<&StyledGraphemeCluster>[src]

Get the cell at the specified position. The implementor must ensure that in the range for x \in [0, Width) and y \in [0, Height) a valid cluster is returned. Read more

fn get_default_style(&self) -> Style[src]

Return the default style that characters of this target should be printed as. This serves as the base for further style modifications while writing to the target. Read more

fn get_soft_width(&self) -> Width[src]

Return the soft or “desired” width of the target. In most cases this is equal to the width. An example where this is not the case would be a terminal with builtin wrapping of lines where it is some cases desirable for the cursor to wrap at the width of the terminal, even though there is no (conceptual) limit of line length. Read more

impl<'w> Debug for Window<'w>[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<'w> RefUnwindSafe for Window<'w>

impl<'w> Send for Window<'w>

impl<'w> Sync for Window<'w>

impl<'w> Unpin for Window<'w>

impl<'w> !UnwindSafe for Window<'w>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.