pub struct Painter { /* private fields */ }
Expand description
The TUI Painter :)
It has a style and scope and it paints text on the screen or fills it with background. It can also copy symbols from one screen to another.
Implementations§
source§impl Painter
impl Painter
pub fn new(style: impl Into<Style>, scope: Window) -> Self
sourcepub fn with_scope(&self, scope: Window) -> Painter
pub fn with_scope(&self, scope: Window) -> Painter
Set new scope
sourcepub fn with_new_style(&self, style: Style) -> Painter
pub fn with_new_style(&self, style: Style) -> Painter
Ignore the current style and use the given one
pub fn scope(&self) -> Window
sourcepub fn copy<'a>(
&self,
symbols: impl Iterator<Item = (Point, &'a ScreenStyle, &'a str)>,
screen: &mut Screen
)
pub fn copy<'a>( &self, symbols: impl Iterator<Item = (Point, &'a ScreenStyle, &'a str)>, screen: &mut Screen )
Copy symbols to the screen respecting scope
sourcepub fn paint(
&self,
text: &str,
screen: &mut Screen,
offset: u16,
explicit_carriage_return: bool
) -> Window
pub fn paint( &self, text: &str, screen: &mut Screen, offset: u16, explicit_carriage_return: bool ) -> Window
Render the given text to the screen with a column offset.
The offset allows to continue a line where the previous painting stopped. The offest is zero-based relative to the painter scope.
With the explicit_carriage_return set to true, new line (\n) will not imply carriage return (\r). Set it to true if you fave pre-formatted text where \n should not return carriage. False suitable for most texts in the nix world and no harm in \r\n world. Set it to false if you want text to continue at the beginning after new line.
It handles the text in a special way:
- it works with symbols-graphemes rather than chars
- each grapheme will occupy it’s own spot on the screen (emoji welcome)
- \r moves the cursor to the start of the scope line
- \n moves the cursor to the next line in scope
- if end of scope is reached, wraps around to next line
- it skips symbols that are out of scope
- it returns the actual window scope the text was rendered to which allows the next thing to lay next by