mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-12 12:13:08 +00:00
added with_theme to Printer
This commit is contained in:
parent
4a3bbbb998
commit
cabeef1d16
@ -11,7 +11,7 @@ use utils::lines::simple::prefix;
|
|||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
|
|
||||||
/// Convenient interface to draw on a subset of the screen.
|
/// Convenient interface to draw on a subset of the screen.
|
||||||
pub struct Printer<'a> {
|
pub struct Printer<'a, 'b> {
|
||||||
/// Offset into the window this printer should start drawing at.
|
/// Offset into the window this printer should start drawing at.
|
||||||
pub offset: Vec2,
|
pub offset: Vec2,
|
||||||
/// Size of the area we are allowed to draw on.
|
/// Size of the area we are allowed to draw on.
|
||||||
@ -24,16 +24,16 @@ pub struct Printer<'a> {
|
|||||||
/// `true` if nothing has been drawn yet.
|
/// `true` if nothing has been drawn yet.
|
||||||
new: Rc<Cell<bool>>,
|
new: Rc<Cell<bool>>,
|
||||||
/// Backend used to actually draw things
|
/// Backend used to actually draw things
|
||||||
backend: &'a Backend,
|
backend: &'b Backend,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Printer<'a> {
|
impl<'a, 'b> Printer<'a, 'b> {
|
||||||
/// Creates a new printer on the given window.
|
/// Creates a new printer on the given window.
|
||||||
///
|
///
|
||||||
/// But nobody needs to know that.
|
/// But nobody needs to know that.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn new<T: Into<Vec2>>(
|
pub fn new<T: Into<Vec2>>(
|
||||||
size: T, theme: &'a Theme, backend: &'a Backend
|
size: T, theme: &'a Theme, backend: &'b Backend
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Printer {
|
Printer {
|
||||||
offset: Vec2::zero(),
|
offset: Vec2::zero(),
|
||||||
@ -171,6 +171,23 @@ impl<'a> Printer<'a> {
|
|||||||
self.backend.unset_effect(effect);
|
self.backend.unset_effect(effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Call the given closure with a modified printer
|
||||||
|
/// that will apply the given theme on prints.
|
||||||
|
pub fn with_theme<F>(&self, theme: &Theme, f: F)
|
||||||
|
where
|
||||||
|
F: FnOnce(&Printer),
|
||||||
|
{
|
||||||
|
let new_printer = Printer {
|
||||||
|
offset: self.offset,
|
||||||
|
size: self.size,
|
||||||
|
focused: self.focused,
|
||||||
|
theme : theme,
|
||||||
|
new: self.new.clone(),
|
||||||
|
backend : self.backend
|
||||||
|
};
|
||||||
|
f(&new_printer);
|
||||||
|
}
|
||||||
|
|
||||||
/// Call the given closure with a modified printer
|
/// Call the given closure with a modified printer
|
||||||
/// that will apply each given effect on prints.
|
/// that will apply each given effect on prints.
|
||||||
pub fn with_effects<F>(&self, effects: EnumSet<Effect>, f: F)
|
pub fn with_effects<F>(&self, effects: EnumSet<Effect>, f: F)
|
||||||
@ -302,8 +319,8 @@ impl<'a> Printer<'a> {
|
|||||||
|
|
||||||
/// Returns a printer on a subset of this one's area.
|
/// Returns a printer on a subset of this one's area.
|
||||||
pub fn sub_printer<S: Into<Vec2>, T: Into<Vec2>>(
|
pub fn sub_printer<S: Into<Vec2>, T: Into<Vec2>>(
|
||||||
&'a self, offset: S, size: T, focused: bool
|
&self, offset: S, size: T, focused: bool
|
||||||
) -> Printer<'a> {
|
) -> Printer<'a, 'b> {
|
||||||
let size = size.into();
|
let size = size.into();
|
||||||
let offset = offset.into().or_min(self.size);
|
let offset = offset.into().or_min(self.size);
|
||||||
let available = if !offset.fits_in(self.size) {
|
let available = if !offset.fits_in(self.size) {
|
||||||
|
Loading…
Reference in New Issue
Block a user