mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-08 18:30:40 +00:00
Add color option to Layer
This commit is contained in:
parent
bf0fb488a1
commit
b3f913391a
@ -1,3 +1,4 @@
|
|||||||
|
use crate::theme::ColorStyle;
|
||||||
use crate::view::{View, ViewWrapper};
|
use crate::view::{View, ViewWrapper};
|
||||||
use crate::Printer;
|
use crate::Printer;
|
||||||
|
|
||||||
@ -9,12 +10,28 @@ use crate::Printer;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Layer<T: View> {
|
pub struct Layer<T: View> {
|
||||||
view: T,
|
view: T,
|
||||||
|
color: ColorStyle,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: View> Layer<T> {
|
impl<T: View> Layer<T> {
|
||||||
/// Wraps the given view.
|
/// Wraps the given view.
|
||||||
pub fn new(view: T) -> Self {
|
pub fn new(view: T) -> Self {
|
||||||
Layer { view }
|
Self::with_color(view, ColorStyle::primary())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Wraps the given view with a custom background color.
|
||||||
|
pub fn with_color(view: T, color: ColorStyle) -> Self {
|
||||||
|
Layer { view, color }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets the current color.
|
||||||
|
pub fn color(&self) -> ColorStyle {
|
||||||
|
self.color
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the background color.
|
||||||
|
pub fn set_color(&mut self, color: ColorStyle) {
|
||||||
|
self.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
inner_getters!(self.view: T);
|
inner_getters!(self.view: T);
|
||||||
@ -24,9 +41,11 @@ impl<T: View> ViewWrapper for Layer<T> {
|
|||||||
wrap_impl!(self.view: T);
|
wrap_impl!(self.view: T);
|
||||||
|
|
||||||
fn wrap_draw(&self, printer: &Printer<'_, '_>) {
|
fn wrap_draw(&self, printer: &Printer<'_, '_>) {
|
||||||
for y in 0..printer.size.y {
|
printer.with_color(self.color, |printer| {
|
||||||
printer.print_hline((0, y), printer.size.x, " ");
|
for y in 0..printer.size.y {
|
||||||
}
|
printer.print_hline((0, y), printer.size.x, " ");
|
||||||
|
}
|
||||||
|
});
|
||||||
self.view.draw(printer);
|
self.view.draw(printer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user