pub struct Plane { /* private fields */ }Expand description
A drawable text surface, composed of Cells.
Implementations§
Source§impl Plane
§constructors
impl Plane
§constructors
Sourcepub fn from_cli(notcurses: &Notcurses) -> Result<Plane>
pub fn from_cli(notcurses: &Notcurses) -> Result<Plane>
Returns the cli Plane for the provided notcurses instance.
Returns an error if there’s already one cli plane instantiated.
Sourcepub fn from_ncplane(ncplane: &mut NcPlane, notcurses: &Notcurses) -> Plane
pub fn from_ncplane(ncplane: &mut NcPlane, notcurses: &Notcurses) -> Plane
Returns a new Plane from an NcPlane, associated to the notcurses context.
Sourcepub fn builder() -> PlaneBuilder
pub fn builder() -> PlaneBuilder
Returns a new PlaneBuilder.
Sourcepub fn new(nc: &Notcurses) -> Result<Self>
pub fn new(nc: &Notcurses) -> Result<Self>
Returns a new root plane with default options.
The plane will be positioned at (0, 0) and have the size of the terminal.
Sourcepub fn new_at(nc: &Notcurses, position: impl Into<Position>) -> Result<Self>
pub fn new_at(nc: &Notcurses, position: impl Into<Position>) -> Result<Self>
Returns a new root plane at a specific position.
The plane will have the size of the terminal.
Sourcepub fn new_sized(nc: &Notcurses, size: impl Into<Size>) -> Result<Self>
pub fn new_sized(nc: &Notcurses, size: impl Into<Size>) -> Result<Self>
Returns a new root plane with a specific size.
sizemust be greater than0in both dimensions.- The plane will be positioned at
(0, 0).
Sourcepub fn new_sized_at(
nc: &Notcurses,
size: impl Into<Size>,
position: impl Into<Position>,
) -> Result<Self>
pub fn new_sized_at( nc: &Notcurses, size: impl Into<Size>, position: impl Into<Position>, ) -> Result<Self>
Returns a new root plane with a specific size and position.
size must be greater than 0 in both dimensions.
Sourcepub fn new_child(&mut self) -> Result<Plane>
pub fn new_child(&mut self) -> Result<Plane>
Returns a new child plane with default options.
The plane will be positioned at (0, 0) and have the size of the terminal.
Sourcepub fn new_child_at(&mut self, position: impl Into<Position>) -> Result<Plane>
pub fn new_child_at(&mut self, position: impl Into<Position>) -> Result<Plane>
Returns a new child plane at a specific position.
The plane will be terminal sized.
Sourcepub fn new_child_sized(&mut self, size: impl Into<Size>) -> Result<Plane>
pub fn new_child_sized(&mut self, size: impl Into<Size>) -> Result<Plane>
Returns a new child plane with a specific size.
sizemust be greater than0in both dimensions.- The plane will be positioned at
(0, 0).
Sourcepub fn new_child_sized_at(
&mut self,
size: impl Into<Size>,
position: impl Into<Position>,
) -> Result<Self>
pub fn new_child_sized_at( &mut self, size: impl Into<Size>, position: impl Into<Position>, ) -> Result<Self>
Returns a new child plane with a specific position and size.
size must be greater than 0 in both dimensions.
Sourcepub fn duplicate(&self) -> Plane
pub fn duplicate(&self) -> Plane
Duplicates this Plane.
The new plane will have the same geometry, the same rendering state, and all the same duplicated content.
The new plane will be immediately above the old one on the z-axis.
The new plane will be bound to the same parent, but since child planes are not duplicated, it will not have any children planes.
Sourcepub fn into_ref_mut(&mut self) -> &mut NcPlane
pub fn into_ref_mut(&mut self) -> &mut NcPlane
Returns an exclusive reference to the inner NcPlane.
Source§impl Plane
§rendering
impl Plane
§rendering
Sourcepub fn render(&mut self) -> Result<()>
pub fn render(&mut self) -> Result<()>
Renders and rasterizes the pile of which this Plane is part.
Sourcepub fn render_only(&mut self) -> Result<()>
pub fn render_only(&mut self) -> Result<()>
Just renders the pile of which this Plane is part, without rasterizing.
Rendering this pile again will blow away the render.
To actually write out the render, call rasterize afterwards.
Source§impl Plane
§size, geometry
impl Plane
§size, geometry
Sourcepub fn geometry_best(&self) -> PlaneGeometry
pub fn geometry_best(&self) -> PlaneGeometry
Returns the geometry of the plane, using the best blitter available.
Sourcepub fn geometry_with(&self, blitter: Blitter) -> PlaneGeometry
pub fn geometry_with(&self, blitter: Blitter) -> PlaneGeometry
Returns the geometry of the plane, using the provided blitter.
Sourcepub fn resize(
&mut self,
size: impl Into<Size>,
keep: impl Into<Position>,
keep_size: impl Into<Size>,
offset: impl Into<Position>,
) -> Result<()>
pub fn resize( &mut self, size: impl Into<Size>, keep: impl Into<Position>, keep_size: impl Into<Size>, offset: impl Into<Position>, ) -> Result<()>
Resizes the plane to a new size.
An area of the plane to keep unchanged is defined by keep and keep_len.
Note that
keepposition is relative to the plane.offsetposition is relative tokeep, placing the upper-left-corner of the resized plane.
§Errors
- if
keepfalls outside of the plane. - if
keep_sizeis zero in just one dimension. - if
sizeis smaller thankeep_sizein any dimension.
Source§impl Plane
§area positioning
impl Plane
§area positioning
Sourcepub fn position(&self) -> Position
pub fn position(&self) -> Position
Returns the current position of this plane, relative to its parent.
In the case of a root (parentless) plane, it will be the same as
root_position.
Sourcepub fn root_position(&self) -> Position
pub fn root_position(&self) -> Position
Returns the root position of this plane, which is relative to the root of the pile this plane is part of.
Sourcepub fn move_to(&mut self, position: impl Into<Position>) -> Result<()>
pub fn move_to(&mut self, position: impl Into<Position>) -> Result<()>
Moves this plane relative to its parent (or to its pile, if it’s a root plane).
Sourcepub fn move_rel(&mut self, offset: impl Into<Position>) -> Result<()>
pub fn move_rel(&mut self, offset: impl Into<Position>) -> Result<()>
Moves this plane relative to its current position.
- Negative values move up and left, respectively.
- Pass 0 to hold an axis constant.
Sourcepub fn place_within(&mut self) -> Result<()>
pub fn place_within(&mut self) -> Result<()>
Moves the plane such that it is entirely within its parent, if possible.
No resizing is performed.
Sourcepub fn translate_root(&self, position: impl Into<Position>) -> (Position, bool)
pub fn translate_root(&self, position: impl Into<Position>) -> (Position, bool)
Translates a position relative to the root,
into a position relative to this plane, and checks if it falls inside.
Fields of the returned tuple:
.0: The translatedposition, from root to self,.1: Is true whenpositionis inside this plane, or false otherwise.
§Example
assert_eq![
Plane::new_at(&mut nc, (8, 8))?.translate_root(Position::new(7, 7)),
(Position::new(-1, -1), false),
];Source§impl Plane
§z-buffer positioning
impl Plane
§z-buffer positioning
Sourcepub fn move_family_top(&mut self)
pub fn move_family_top(&mut self)
Relocates this plane and its children at the top of the z-buffer.
Relative order will be maintained between the reinserted planes.
For a plane E bound to C, with z-ordering A B C D E, moving the C family to the top results in C E A B D.
Sourcepub fn move_bottom(&mut self)
pub fn move_bottom(&mut self)
Relocates this plane at the bottom of the z-buffer of its pile.
Sourcepub fn move_family_bottom(&mut self)
pub fn move_family_bottom(&mut self)
Relocates this plane and its children at the bottom of the z-buffer.
Relative order will be maintained between the reinserted planes.
For a plane E bound to C, with z-ordering A B C D E, moving the C family to the bottom results in A B D C E.
Sourcepub fn move_above(&mut self, other: &mut Plane) -> Result<()>
pub fn move_above(&mut self, other: &mut Plane) -> Result<()>
Relocates this plane above other plane, in the z-buffer.
Errors if the current plane is already in the desired location, or if both planes are the same.
Sourcepub fn move_family_above(&mut self, other: &mut Plane) -> Result<()>
pub fn move_family_above(&mut self, other: &mut Plane) -> Result<()>
Relocates this plane and its children above other plane, in the z-buffer.
Errors if the current plane is already in the desired location, or if both planes are the same.
Sourcepub fn move_below(&mut self, other: &mut Plane) -> Result<()>
pub fn move_below(&mut self, other: &mut Plane) -> Result<()>
Relocates this plane below other plane, in the z-buffer.
Errors if the current plane is already in the desired location, or if both planes are the same.
Sourcepub fn move_family_below(&mut self, other: &mut Plane) -> Result<()>
pub fn move_family_below(&mut self, other: &mut Plane) -> Result<()>
Relocates this plane abnd its children below the other plane, in the z-buffer.
Errors if the current plane is already in the desired location, or if both planes are the same.
Sourcepub fn reparent(&mut self, new_parent: &mut Plane)
pub fn reparent(&mut self, new_parent: &mut Plane)
Unbounds this plane from its parent and makes it a child of new_parent.
Any child planes of this plane are reparented to the previous parent.
If this plane is equal to new_parent it becomes the root of a new pile,
unless it’s already the root of a pile, in which case this is a no-op.
Sourcepub fn reparent_family(&mut self, new_parent: &mut Plane)
pub fn reparent_family(&mut self, new_parent: &mut Plane)
Unbounds this plane from its parent and makes it a child of new_parent,
including its child planes, maintaining their z-order.
If this plane is equal to new_parent it becomes the root of a new pile,
unless it’s already the root of a pile, in which case this is a no-op.
Source§impl Plane
§alignment, scrolling and growing
impl Plane
§alignment, scrolling and growing
Sourcepub fn halign(&self, horizontal: Align, width: u32) -> Result<u32>
pub fn halign(&self, horizontal: Align, width: u32) -> Result<u32>
Returns the column at which width columns ought start
in order to be aligned according to h alignment within this plane.
Returns u32::MAX if Align::Unaligned.
Sourcepub fn valign(&self, vertical: Align, height: u32) -> Result<u32>
pub fn valign(&self, vertical: Align, height: u32) -> Result<u32>
Returns the row at which rows rows ought start
in order to be aligned according to v alignment within this plane.
Sourcepub fn center_abs(&self) -> (u32, u32)
pub fn center_abs(&self) -> (u32, u32)
Finds the center coordinate of a plane.
In the case of an even number of rows/columns the top/left is preferred (in such a case, there will be one more cell to the bottom/right of the center than the top/left). The center is then modified relative to the plane’s origin.
Sourcepub fn is_autogrow(&self) -> bool
pub fn is_autogrow(&self) -> bool
Returns true if this plane has autogrow enabled, or false otherwise.
Sourcepub fn set_autogrow(&mut self, autogrow: bool) -> bool
pub fn set_autogrow(&mut self, autogrow: bool) -> bool
(Un)Sets the autogrow behaviour of this plane.
Returns true if scrolling was previously enabled or false otherwise.
By default, planes are created with autogrow disabled.
Normally, once output reaches the right boundary of a plane, it is impossible to place more output unless the cursor is first moved.
If scrolling is enabled, the cursor will automatically move down and to the left in this case, but upon reaching the bottom right corner of the plane, it is impossible to place more output without a scrolling event.
If autogrow is in play, the plane will automatically be enlarged to accommodate output. If scrolling is disabled, growth takes place to the right; it otherwise takes place at the bottom.
The plane only grows in one dimension.
Sourcepub fn is_scrolling(&self) -> bool
pub fn is_scrolling(&self) -> bool
Returns true if this plane has scrolling enabled or false otherwise.
Sourcepub fn set_scrolling(&mut self, scrolling: bool) -> bool
pub fn set_scrolling(&mut self, scrolling: bool) -> bool
Sets the scrolling behaviour of this plane.
Returns true if scrolling was previously enabled or false otherwise.
Sourcepub fn scroll(&mut self, scroll: u32) -> Result<u32>
pub fn scroll(&mut self, scroll: u32) -> Result<u32>
Sends a number of scroll events to the current plane.
Returns an error if the current plane is not a scrolling plane, and otherwise returns the number of lines scrolled.
Sourcepub fn scroll_child(&mut self, child: &Plane) -> Result<u32>
pub fn scroll_child(&mut self, child: &Plane) -> Result<u32>
Scrolls the current plane until child is no longer hidden beneath it.
Returns an error if child is not a child of this plane, or if this
plane is not scrolling, or child is fixed.
Returns the number of scrolling events otherwise (might be 0).
Source§impl Plane
§cursor related methods
impl Plane
§cursor related methods
Sourcepub fn cursor_home(&mut self)
pub fn cursor_home(&mut self)
Moves the cursor to the home position (0, 0).
Sourcepub fn cursor_move_to(&mut self, position: impl Into<Position>) -> Result<()>
pub fn cursor_move_to(&mut self, position: impl Into<Position>) -> Result<()>
Moves the cursor to the specified position within this plane.
The cursor doesn’t need to be visible.
Errors if the coordinates exceed the plane’s dimensions, and the cursor will remain unchanged in that case.
Sourcepub fn cursor_move_to_row(&mut self, row: u32) -> Result<()>
pub fn cursor_move_to_row(&mut self, row: u32) -> Result<()>
Moves the cursor to the specified row within this plane.
The cursor doesn’t need to be visible.
Errors if the row number exceed the plane’s rows, and the cursor will remain unchanged in that case.
Sourcepub fn cursor_move_to_col(&mut self, column: u32) -> Result<()>
pub fn cursor_move_to_col(&mut self, column: u32) -> Result<()>
Moves the cursor to the specified column within this plane.
The cursor doesn’t need to be visible.
Errors if the column number exceed the plane’s columns, and the cursor will remain unchanged in that case.
Source§impl Plane
§text and cells
impl Plane
§text and cells
Sourcepub fn erase(&mut self)
pub fn erase(&mut self)
Erases every Cell in this plane.
The cursor is homed. Resets all attributes to normal, all colors to the default color, and all cells to undrawn.
Sourcepub fn erase_region(
&mut self,
beg_x: Option<u32>,
beg_y: Option<u32>,
len_x: i32,
len_y: i32,
) -> Result<()>
pub fn erase_region( &mut self, beg_x: Option<u32>, beg_y: Option<u32>, len_x: i32, len_y: i32, ) -> Result<()>
Erases every Cell in the region beginning at some (beg_x, beg_y)
and having some size (len_x, len_y) for non-zero lengths.
If beg_x and/or beg_y are None, the current cursor position
along that axis is used.
- A negative
len_xmeans to move left from the origin, a positivelen_xmoves right. - A negative
len_ymeans to move up from the origin, and a positivelen_ymoves down.
A value of 0 for the length erases everything along that dimension.
§Errors
It is an error if the starting coordinate is not in the plane, but the ending coordinate may be outside the plane.
Sourcepub fn contents_region(
&mut self,
beg_x: Option<u32>,
beg_y: Option<u32>,
len_x: Option<u32>,
len_y: Option<u32>,
) -> Result<String>
pub fn contents_region( &mut self, beg_x: Option<u32>, beg_y: Option<u32>, len_x: Option<u32>, len_y: Option<u32>, ) -> Result<String>
Returns a String from the graphemes of the selected region of the plane.
Starts at the plane’s beg_x * beg_y coordinates (which must lie on
the plane), continuing for len_x x len_y cells.
Use None for either or all of beg_y and beg_x in order to
use the current cursor position along that axis.
Use None for either or both of len_y and len_x in order to
go through the boundary of the plane in that axis (same as 0).
Sourcepub fn putstr(&mut self, string: &str) -> Result<u32>
pub fn putstr(&mut self, string: &str) -> Result<u32>
Writes a string to the current cursor position, using the current style.
Returns the number of columns the cursor has advanced.
§Errors
- if the position falls outside the plane’s area.
- if a glyph can’t fit in the current line, unless scrolling is enabled.
§Example
assert_eq![11, plane.putstr("hello world")?];Sourcepub fn putstrln(&mut self, string: &str) -> Result<u32>
pub fn putstrln(&mut self, string: &str) -> Result<u32>
Writes a string to the current cursor position, ending in newline,
and using the current style.
Returns the number of columns the cursor has advanced.
§Errors
- if the position falls outside the plane’s area.
- if a glyph can’t fit in the current line, unless scrolling is enabled.
§Example
plane.set_scrolling(true);
assert_eq![12, plane.putstrln("hello world")?];Sourcepub fn putln(&mut self) -> Result<u32>
pub fn putln(&mut self) -> Result<u32>
Writes a newline to the current cursor position.
A newline counts as 1 column advanced.
Sourcepub fn putstr_aligned(
&mut self,
y: Option<u32>,
horizontal: Align,
string: &str,
) -> Result<u32>
pub fn putstr_aligned( &mut self, y: Option<u32>, horizontal: Align, string: &str, ) -> Result<u32>
Writes a string to some y, and a horizontal alignment,
using the current style.
Returns the number of columns the cursor has advanced.
§Errors
- if the position falls outside the plane’s area.
- if a glyph can’t fit in the current line, unless scrolling is enabled.
Sourcepub fn putstr_stained(&mut self, string: &str) -> Result<u32>
pub fn putstr_stained(&mut self, string: &str) -> Result<u32>
Writes a string to the current position, using the pre-existing style.
Returns the number of columns the cursor has advanced.
§Errors
- if the position falls outside the plane’s area.
- if a glyph can’t fit in the current line, unless scrolling is enabled.
Sourcepub fn putstr_aligned_stained(
&mut self,
y: Option<u32>,
horizontal: Align,
string: &str,
) -> Result<u32>
pub fn putstr_aligned_stained( &mut self, y: Option<u32>, horizontal: Align, string: &str, ) -> Result<u32>
Writes a string to y, and horizontal alignment,
using the pre-existing style.
Returns the number of columns the cursor has advanced.
§Errors
- if the position falls outside the plane’s area.
- if a glyph can’t fit in the current line, unless scrolling is enabled.
Sourcepub fn putstr_at(
&mut self,
position: impl Into<Position>,
string: &str,
) -> Result<u32>
pub fn putstr_at( &mut self, position: impl Into<Position>, string: &str, ) -> Result<u32>
Writes a string to position, using the current style.
Returns the number of columns the cursor has advanced.
§Errors
- if the position falls outside the plane’s area.
- if a glyph can’t fit in the current line, unless scrolling is enabled.
Sourcepub fn putstr_at_xy(
&mut self,
x: Option<u32>,
y: Option<u32>,
string: &str,
) -> Result<u32>
pub fn putstr_at_xy( &mut self, x: Option<u32>, y: Option<u32>, string: &str, ) -> Result<u32>
Writes a string to some y, some x, or both, using the current style.
Returns the number of columns the cursor has advanced.
It wont move over a axis that is set to None.
§Errors
- if the position falls outside the plane’s area.
- if a glyph can’t fit in the current line, unless scrolling is enabled.
Sourcepub fn putstr_len(&mut self, len: usize, string: &str) -> Result<u32>
pub fn putstr_len(&mut self, len: usize, string: &str) -> Result<u32>
Writes a string to the current cursor position, using the current style,
and no more than len bytes will be written.
Returns the number of columns the cursor has advanced.
§Errors
- if the position falls outside the plane’s area.
- if a glyph can’t fit in the current line, unless scrolling is enabled.
Sourcepub fn putstr_len_at(
&mut self,
position: impl Into<Position>,
len: usize,
string: &str,
) -> Result<u32>
pub fn putstr_len_at( &mut self, position: impl Into<Position>, len: usize, string: &str, ) -> Result<u32>
Writes a string to some position, using the current style,
and no more than len bytes will be written.
Returns the number of columns the cursor has advanced.
§Errors
- if the position falls outside the plane’s area.
- if a glyph can’t fit in the current line, unless scrolling is enabled.
Sourcepub fn putstr_len_at_xy(
&mut self,
x: Option<u32>,
y: Option<u32>,
len: usize,
string: &str,
) -> Result<u32>
pub fn putstr_len_at_xy( &mut self, x: Option<u32>, y: Option<u32>, len: usize, string: &str, ) -> Result<u32>
Writes a string to some y, some x, using the current style,
and no more than len bytes will be written.
Returns the number of columns the cursor has advanced.
§Errors
- if the position falls outside the plane’s area.
- if a glyph can’t fit in the current line, unless scrolling is enabled.
Sourcepub fn putstr_len_aligned(
&mut self,
y: Option<u32>,
horizontal: Align,
len: usize,
string: &str,
) -> Result<u32>
pub fn putstr_len_aligned( &mut self, y: Option<u32>, horizontal: Align, len: usize, string: &str, ) -> Result<u32>
Writes a string to some y, and a horizontal alignment,
using the current style, and no more than len bytes will be written.
Returns the number of columns the cursor has advanced.
§Errors
- if the position falls outside the plane’s area.
- if a glyph can’t fit in the current line, unless scrolling is enabled.
Sourcepub fn polyfill_xy(
&mut self,
position: impl Into<Position>,
cell: &Cell,
) -> Result<usize>
pub fn polyfill_xy( &mut self, position: impl Into<Position>, cell: &Cell, ) -> Result<usize>
Considers the glyph at position as the fill target,
and copies cell to it and to all cardinally-connected cells.
Returns the number of cells polyfilled.
Errors if the position falls outside the plane’s area.
Source§impl Plane
§colors, palette & styles
impl Plane
§colors, palette & styles
Sourcepub fn set_channels(&mut self, channels: impl Into<Channels>)
pub fn set_channels(&mut self, channels: impl Into<Channels>)
Sets the channels.
Sourcepub fn set_fg(&mut self, foreground: impl Into<Channel>) -> Channels
pub fn set_fg(&mut self, foreground: impl Into<Channel>) -> Channels
Sets the foreground channel. Returns the updated channels.
Sourcepub fn set_bg(&mut self, background: impl Into<Channel>) -> Channels
pub fn set_bg(&mut self, background: impl Into<Channel>) -> Channels
Sets the background channel. Returns the updated channels.
Sourcepub fn unset_bg(&mut self) -> Channels
pub fn unset_bg(&mut self) -> Channels
Sets the background channel to the default. Returns the updated channels.
Sourcepub fn unset_fg(&mut self) -> Channels
pub fn unset_fg(&mut self) -> Channels
Sets the foreground channel to the default. Returns the updated channels.
Sourcepub fn set_fg_palindex(&mut self, palindex: impl Into<u8>)
pub fn set_fg_palindex(&mut self, palindex: impl Into<u8>)
Sets this Plane’s foreground Palette index.
Also sets the foreground palette index bit, sets it foreground-opaque, and clears the foreground default color bit.
Sourcepub fn set_bg_palindex(&mut self, palindex: impl Into<u8>)
pub fn set_bg_palindex(&mut self, palindex: impl Into<u8>)
Sets this Plane’s background Palette index.
Also sets the background palette index bit, sets it foreground-opaque, and clears the foreground default color bit.
Sourcepub fn off_styles(&mut self, styles: impl Into<Style>)
pub fn off_styles(&mut self, styles: impl Into<Style>)
Removes the specified styles from this Plane’s existing spec.
Sourcepub fn on_styles(&mut self, styles: impl Into<Style>)
pub fn on_styles(&mut self, styles: impl Into<Style>)
Adds the specified styles to this NcPlane’s existing spec.
Sourcepub fn set_styles(&mut self, styles: impl Into<Style>)
pub fn set_styles(&mut self, styles: impl Into<Style>)
Sets just the specified styles for this NcPlane.
Source§impl Plane
§base cell
impl Plane
§base cell
Sourcepub fn set_base(
&mut self,
egc: &str,
style: Style,
channels: impl Into<Channels>,
) -> Result<usize>
pub fn set_base( &mut self, egc: &str, style: Style, channels: impl Into<Channels>, ) -> Result<usize>
Sets the plane’s base Cell from its components.
Returns the number of bytes copied out of egc.
The base cell shows anywhere in the plane with an empty egc.
Note that erasing the plane does not reset the base cell.
Sourcepub fn set_base_styles(&mut self, styles: Style) -> Result<Style>
pub fn set_base_styles(&mut self, styles: Style) -> Result<Style>
Sets the plane’s base cell’s styles,
Returns the previous value.
Sourcepub fn set_base_channels(
&mut self,
channels: impl Into<Channels>,
) -> Result<Channels>
pub fn set_base_channels( &mut self, channels: impl Into<Channels>, ) -> Result<Channels>
Sets the plane’s base cell’s foreground & background channels.
Returns the previous value.