[−][src]Struct cursive::Printer
Convenient interface to draw on a subset of the screen.
The area it can print on is defined by offset
and size
.
The part of the content it will print is defined by content_offset
and 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
impl<'a, 'b> Printer<'a, 'b>
[src]
pub fn clear(&self)
[src]
Clear the screen.
It will discard anything drawn before.
Users rarely need to call this directly.
pub fn print_styled<S>(&self, start: S, text: SpannedStr<'_, Style>) where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
Prints some styled text at the given position.
pub fn print<S>(&self, start: S, text: &str) where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
Prints some text at the given position
pub fn print_vline<T>(&self, start: T, height: usize, c: &str) where
T: Into<XY<usize>>,
[src]
T: Into<XY<usize>>,
Prints a vertical line using the given character.
pub fn print_line<T>(
&self,
orientation: Orientation,
start: T,
length: usize,
c: &str
) where
T: Into<XY<usize>>,
[src]
&self,
orientation: Orientation,
start: T,
length: usize,
c: &str
) where
T: Into<XY<usize>>,
Prints a line using the given character.
pub fn print_hline<T>(&self, start: T, width: usize, c: &str) where
T: Into<XY<usize>>,
[src]
T: Into<XY<usize>>,
Prints a horizontal line using the given character.
pub fn with_color<F>(&self, c: ColorStyle, f: F) where
F: FnOnce(&Printer<'_, '_>),
[src]
F: FnOnce(&Printer<'_, '_>),
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!"); });
pub fn with_style<F, T>(&self, style: T, f: F) where
F: FnOnce(&Printer<'_, '_>),
T: Into<Style>,
[src]
F: FnOnce(&Printer<'_, '_>),
T: Into<Style>,
Call the given closure with a styled printer, that will apply the given style on prints.
pub fn with_effect<F>(&self, effect: Effect, f: F) where
F: FnOnce(&Printer<'_, '_>),
[src]
F: FnOnce(&Printer<'_, '_>),
Call the given closure with a modified printer that will apply the given effect on prints.
pub fn with_theme<F>(&self, theme: &Theme, f: F) where
F: FnOnce(&Printer<'_, '_>),
[src]
F: FnOnce(&Printer<'_, '_>),
Call the given closure with a modified printer that will apply the given theme on prints.
pub fn theme<'c>(&self, theme: &'c Theme) -> Printer<'c, 'b> where
'a: 'c,
[src]
'a: 'c,
Create a new sub-printer with the given theme.
pub fn with_effects<F>(&self, effects: EnumSet<Effect>, f: F) where
F: FnOnce(&Printer<'_, '_>),
[src]
F: FnOnce(&Printer<'_, '_>),
Call the given closure with a modified printer that will apply each given effect on prints.
pub fn print_box<T, S>(&self, start: T, size: S, invert: bool) where
S: Into<XY<usize>>,
T: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
T: Into<XY<usize>>,
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);
pub fn with_high_border<F>(&self, invert: bool, f: F) where
F: FnOnce(&Printer<'_, '_>),
[src]
F: FnOnce(&Printer<'_, '_>),
Runs the given function using a color depending on the theme.
- If the theme's borders is
None
, return without callingf
. - If the theme's borders is "outset" and
invert
isfalse
, useColorStyle::Tertiary
. - Otherwise, use
ColorStyle::Primary
.
pub fn with_low_border<F>(&self, invert: bool, f: F) where
F: FnOnce(&Printer<'_, '_>),
[src]
F: FnOnce(&Printer<'_, '_>),
Runs the given function using a color depending on the theme.
- If the theme's borders is
None
, return without callingf
. - If the theme's borders is "outset" and
invert
istrue
, useColorStyle::tertiary()
. - Otherwise, use
ColorStyle::primary()
.
pub fn with_selection<F>(&self, selection: bool, f: F) where
F: FnOnce(&Printer<'_, '_>),
[src]
F: FnOnce(&Printer<'_, '_>),
Apply a selection style and call the given function.
- If
selection
isfalse
, simply usesColorStyle::primary()
. - If
selection
istrue
:- If the printer currently has the focus,
uses
ColorStyle::highlight()
. - Otherwise, uses
ColorStyle::highlight_inactive()
.
- If the printer currently has the focus,
uses
pub fn print_hdelim<T>(&self, start: T, len: usize) where
T: Into<XY<usize>>,
[src]
T: Into<XY<usize>>,
Prints a horizontal delimiter with side border ├
and ┤
.
pub fn offset<S>(&self, offset: S) -> Printer<'a, 'b> where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
Returns a sub-printer with the given offset.
It will print in an area slightly to the bottom/right.
pub fn focused(&self, focused: bool) -> Printer<'a, 'b>
[src]
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.
pub fn enabled(&self, enabled: bool) -> Printer<'a, 'b>
[src]
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.
pub fn windowed(&self, viewport: Rect) -> Printer<'a, 'b>
[src]
Returns a new sub-printer for the given viewport.
This is a combination of offset + cropped.
pub fn cropped<S>(&self, size: S) -> Printer<'a, 'b> where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
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.
pub fn cropped_centered<S>(&self, size: S) -> Printer<'a, 'b> where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
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.
pub fn shrinked<S>(&self, borders: S) -> Printer<'a, 'b> where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
Returns a new sub-printer with a shrinked area.
The printer size will be reduced by the given border from the bottom-right.
pub fn shrinked_centered<S>(&self, borders: S) -> Printer<'a, 'b> where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
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.
pub fn content_offset<S>(&self, offset: S) -> Printer<'a, 'b> where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
Returns a new sub-printer with a content offset.
This is useful for parent views that only show a subset of their
child, like ScrollView
.
pub fn inner_size<S>(&self, size: S) -> Printer<'a, 'b> where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
Returns a sub-printer with a different inner size.
This will not change the actual output size, but will appear bigger to users of this printer.
Useful to give to children who think they're big, but really aren't.
Trait Implementations
Auto Trait Implementations
impl<'a, 'b> !RefUnwindSafe for Printer<'a, 'b>
[src]
impl<'a, 'b> !Send for Printer<'a, 'b>
[src]
impl<'a, 'b> !Sync for Printer<'a, 'b>
[src]
impl<'a, 'b> Unpin for Printer<'a, 'b>
[src]
impl<'a, 'b> !UnwindSafe for Printer<'a, 'b>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Erased for T
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
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]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.