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]
impl<'w> Window<'w>
[src]pub fn get_extent<D: AxisDimension>(&self) -> PositiveAxisDiff<D>
[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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
impl<'a> CursorTarget for Window<'a>
[src]fn get_width(&self) -> Width
[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]
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]
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]
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]
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]
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