pub struct Printer<'a, 'b> {
    pub offset: XY<usize>,
    pub output_size: XY<usize>,
    pub size: XY<usize>,
    pub content_offset: XY<usize>,
    pub focused: bool,
    pub enabled: bool,
    pub theme: &'a Theme,
    /* private fields */
}
Expand description

Convenient interface to draw on a subset of the screen.

The printing area is defined by offset and size.
The content that will be printed is defined by Self::content_offset and Self::size.

If the printer is asked to print outside of the printing area, then the string to be printed shall be truncated without throwing errors. Refer to the crate::traits::View to understand how to change its size.

Fields

offset: XY<usize>

Offset into the window this printer should start drawing at.

A print request at x will really print at x + offset.

output_size: XY<usize>

Size of the area we are allowed to draw on.

Anything outside of this should be discarded.
The view being drawn can ingore this, but anything further than that will be ignored.

size: XY<usize>

Size allocated to the view.

This should be the same value as the one given in the last call to View::layout.

content_offset: XY<usize>

Offset into the view for this printer.

The view being drawn can ignore this, but anything to the top-left of this will actually be ignored, so it can be used to skip this part.

A print request x, will really print at x - content_offset.

focused: bool

Whether the view to draw is currently focused or not.

enabled: bool

Whether the view to draw is currently enabled or not.

theme: &'a Theme

Currently used theme

Implementations

Clear the screen.

It will discard anything drawn before.

Users rarely need to call this directly.

Prints some styled text at the given position.

Prints some text at the given position.

Parameters
  • start is the offset used to print the text in the view.
  • text is a string to print on the screen. It must be a single line, no line wrapping will be done.
Description

Prints some text at the given position. The text could be truncated if it exceed the drawing area size.

Example
use cursive::{Printer, Vec2, View, XY};

pub struct CustomView {
    word: String,
}

impl CustomView {
    pub fn new() -> Self {
        Self {
            word: String::from("Eh, tu connais Rust?"),
        }
    }
}

impl View for CustomView {
    fn draw(&self, printer: &Printer<'_, '_>) {
        printer.print(XY::new(0, 0), &self.word);
    }
}

Prints a vertical line using the given character.

Prints a line using the given character.

Prints a horizontal line using the given character.

Returns the color currently used by the parent view.

Call the given closure with a colored printer, that will apply the given color on prints.

Examples
printer.with_color(theme::ColorStyle::highlight(), |printer| {
    printer.print((0, 0), "This text is highlighted!");
});

Call the given closure with a styled printer, that will apply the given style on prints.

Call the given closure with a modified printer that will apply the given effect on prints.

Call the given closure with a modified printer that will apply the given theme on prints.

Create a new sub-printer with the given theme.

Call the given closure with a modified printer that will apply each given effect on prints.

Prints a rectangular box.

If invert is true, and the theme uses Outset borders, then the box will use an “inset” style instead.

Examples
printer.print_box((0, 0), (6, 4), false);

Runs the given function using a color depending on the theme.

Runs the given function using a color depending on the theme.

Apply a selection style and call the given function.

Prints a horizontal delimiter with side border and .

Returns a sub-printer with the given offset.

It will print in an area slightly to the bottom/right.

Returns a new sub-printer inheriting the given focus.

If self is focused and focused == true, the child will be focused.

Otherwise, he will be unfocused.

Returns a new sub-printer inheriting the given enabled state.

If self is enabled and enabled == true, the child will be enabled.

Otherwise, he will be disabled.

Returns a new sub-printer for the given viewport.
This is a combination of offset + cropped.

Returns a new sub-printer with a cropped area.

The new printer size will be the minimum of size and its current size.
Any size reduction happens at the bottom-right.

Returns a new sub-printer with a cropped area.

The new printer size will be the minimum of size and its current size.
The view will stay centered.
Note that if shrinking by an odd number, the view will round to the top-left.

Returns a new sub-printer with a shrinked area.

The printer size will be reduced by the given border from the bottom-right.

Returns a new sub-printer with a shrinked area.

The printer size will be reduced by the given border, and will stay centered.
Note that if shrinking by an odd number, the view will round to the top-left.

Returns a new sub-printer with a content offset.

This is useful for parent views that only show a subset of their child, like crate::views::ScrollView.

Returns a sub-printer with a different inner size.

This will not change the actual output size, but will appear bigger (or smaller) to users of this printer.
Useful to give to children who think they’re big, but really aren’t.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Calls the given closure and return the result. Read more

Calls the given closure on self.

Calls the given closure on self.

Calls the given closure if condition == true.