pub struct Printer<'a, 'b> {
pub offset: Vec2,
pub output_size: Vec2,
pub size: Vec2,
pub content_offset: Vec2,
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 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: Vec2
Offset into the window this printer should start drawing at.
A print request at x
will really print at x + offset
.
output_size: Vec2
Size of the area we are allowed to draw on.
Anything outside of this should be discarded.
size: Vec2
Size allocated to the view.
This should be the same value as the one given in the last call to
View::layout
.
content_offset: Vec2
Offset into the view for this printer.
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
sourceimpl<'a, 'b> Printer<'a, 'b>
impl<'a, 'b> Printer<'a, 'b>
sourcepub fn clear(&self)
pub fn clear(&self)
Clear the screen.
It will discard anything drawn before.
Users rarely need to call this directly.
sourcepub fn print_styled<S>(&self, start: S, text: SpannedStr<'_, Style>)where
S: Into<Vec2>,
pub fn print_styled<S>(&self, start: S, text: SpannedStr<'_, Style>)where
S: Into<Vec2>,
Prints some styled text at the given position.
sourcepub fn print<S: Into<Vec2>>(&self, start: S, text: &str)
pub fn print<S: Into<Vec2>>(&self, start: S, text: &str)
Prints some text at the given position
sourcepub fn print_vline<T: Into<Vec2>>(&self, start: T, height: usize, c: &str)
pub fn print_vline<T: Into<Vec2>>(&self, start: T, height: usize, c: &str)
Prints a vertical line using the given character.
sourcepub fn print_line<T: Into<Vec2>>(
&self,
orientation: Orientation,
start: T,
length: usize,
c: &str
)
pub fn print_line<T: Into<Vec2>>(
&self,
orientation: Orientation,
start: T,
length: usize,
c: &str
)
Prints a line using the given character.
sourcepub fn print_hline<T: Into<Vec2>>(&self, start: T, width: usize, c: &str)
pub fn print_hline<T: Into<Vec2>>(&self, start: T, width: usize, c: &str)
Prints a horizontal line using the given character.
sourcepub fn with_color<F>(&self, c: ColorStyle, f: F)where
F: FnOnce(&Printer<'_, '_>),
pub fn with_color<F>(&self, c: ColorStyle, f: F)where
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!");
});
sourcepub fn with_style<F, T>(&self, style: T, f: F)where
F: FnOnce(&Printer<'_, '_>),
T: Into<Style>,
pub fn with_style<F, T>(&self, style: T, f: F)where
F: FnOnce(&Printer<'_, '_>),
T: Into<Style>,
Call the given closure with a styled printer, that will apply the given style on prints.
sourcepub fn with_effect<F>(&self, effect: Effect, f: F)where
F: FnOnce(&Printer<'_, '_>),
pub fn with_effect<F>(&self, effect: Effect, f: F)where
F: FnOnce(&Printer<'_, '_>),
Call the given closure with a modified printer that will apply the given effect on prints.
sourcepub fn with_theme<F>(&self, theme: &Theme, f: F)where
F: FnOnce(&Printer<'_, '_>),
pub fn with_theme<F>(&self, theme: &Theme, f: F)where
F: FnOnce(&Printer<'_, '_>),
Call the given closure with a modified printer that will apply the given theme on prints.
sourcepub fn theme<'c>(&self, theme: &'c Theme) -> Printer<'c, 'b>where
'a: 'c,
pub fn theme<'c>(&self, theme: &'c Theme) -> Printer<'c, 'b>where
'a: 'c,
Create a new sub-printer with the given theme.
sourcepub fn with_effects<F>(&self, effects: EnumSet<Effect>, f: F)where
F: FnOnce(&Printer<'_, '_>),
pub fn with_effects<F>(&self, effects: EnumSet<Effect>, f: F)where
F: FnOnce(&Printer<'_, '_>),
Call the given closure with a modified printer that will apply each given effect on prints.
sourcepub fn print_box<T: Into<Vec2>, S: Into<Vec2>>(
&self,
start: T,
size: S,
invert: bool
)
pub fn print_box<T: Into<Vec2>, S: Into<Vec2>>(
&self,
start: T,
size: S,
invert: bool
)
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);
sourcepub fn with_high_border<F>(&self, invert: bool, f: F)where
F: FnOnce(&Printer<'_, '_>),
pub fn with_high_border<F>(&self, invert: bool, f: F)where
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
.
sourcepub fn with_low_border<F>(&self, invert: bool, f: F)where
F: FnOnce(&Printer<'_, '_>),
pub fn with_low_border<F>(&self, invert: bool, f: F)where
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()
.
sourcepub fn with_selection<F: FnOnce(&Printer<'_, '_>)>(&self, selection: bool, f: F)
pub fn with_selection<F: FnOnce(&Printer<'_, '_>)>(&self, selection: bool, f: F)
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
sourcepub fn print_hdelim<T>(&self, start: T, len: usize)where
T: Into<Vec2>,
pub fn print_hdelim<T>(&self, start: T, len: usize)where
T: Into<Vec2>,
Prints a horizontal delimiter with side border ├
and ┤
.
sourcepub fn offset<S>(&self, offset: S) -> Printer<'_, '_>where
S: Into<Vec2>,
pub fn offset<S>(&self, offset: S) -> Printer<'_, '_>where
S: Into<Vec2>,
Returns a sub-printer with the given offset.
It will print in an area slightly to the bottom/right.
sourcepub fn focused(&self, focused: bool) -> Self
pub fn focused(&self, focused: bool) -> Self
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.
sourcepub fn enabled(&self, enabled: bool) -> Self
pub fn enabled(&self, enabled: bool) -> Self
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.
sourcepub fn cropped<S>(&self, size: S) -> Selfwhere
S: Into<Vec2>,
pub fn cropped<S>(&self, size: S) -> Selfwhere
S: Into<Vec2>,
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.
sourcepub fn shrinked<S>(&self, borders: S) -> Selfwhere
S: Into<Vec2>,
pub fn shrinked<S>(&self, borders: S) -> Selfwhere
S: Into<Vec2>,
Returns a new sub-printer with a shrinked area.
The printer size will be reduced by the given border from the bottom-right.
sourcepub fn content_offset<S>(&self, offset: S) -> Selfwhere
S: Into<Vec2>,
pub fn content_offset<S>(&self, offset: S) -> Selfwhere
S: Into<Vec2>,
Returns a new sub-printer with a content offset.
sourcepub fn inner_size<S>(&self, size: S) -> Selfwhere
S: Into<Vec2>,
pub fn inner_size<S>(&self, size: S) -> Selfwhere
S: Into<Vec2>,
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.