2015-05-23 22:58:06 +00:00
|
|
|
use view::{View,ViewWrapper,SizeRequest};
|
|
|
|
use printer::Printer;
|
|
|
|
use vec::Vec2;
|
2015-06-06 01:08:05 +00:00
|
|
|
use theme::ColorPair;
|
2015-05-23 22:58:06 +00:00
|
|
|
|
2015-05-26 23:48:27 +00:00
|
|
|
/// Wrapper view that adds a shadow.
|
|
|
|
///
|
|
|
|
/// It reserves a 1 pixel border on each side.
|
2015-05-23 22:58:06 +00:00
|
|
|
pub struct ShadowView<T: View> {
|
2015-05-26 23:48:27 +00:00
|
|
|
view: T,
|
2015-05-23 22:58:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl <T: View> ShadowView<T> {
|
2015-05-26 23:48:27 +00:00
|
|
|
/// Wraps the given view.
|
2015-05-23 22:58:06 +00:00
|
|
|
pub fn new(view: T) -> Self {
|
|
|
|
ShadowView {
|
|
|
|
view: view,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl <T: View> ViewWrapper for ShadowView<T> {
|
|
|
|
|
|
|
|
wrap_impl!(&self.view);
|
|
|
|
|
|
|
|
fn wrap_get_min_size(&self, req: SizeRequest) -> Vec2 {
|
|
|
|
self.view.get_min_size(req.reduced((2,2))) + (2,2)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn wrap_layout(&mut self, size: Vec2) {
|
|
|
|
self.view.layout(size - (2,2));
|
|
|
|
}
|
|
|
|
|
2015-05-31 04:05:34 +00:00
|
|
|
fn wrap_draw(&mut self, printer: &Printer) {
|
2015-05-23 22:58:06 +00:00
|
|
|
|
2015-06-06 01:08:05 +00:00
|
|
|
printer.with_color(ColorPair::Primary, |printer| {
|
2015-05-24 00:11:58 +00:00
|
|
|
// Draw the view background
|
|
|
|
for y in 1..printer.size.y-1 {
|
|
|
|
printer.print_hline((1,y), printer.size.x-2, ' ' as u64);
|
|
|
|
}
|
|
|
|
});
|
2015-05-23 22:58:06 +00:00
|
|
|
|
2015-07-28 19:54:32 +00:00
|
|
|
self.view.draw(&printer.sub_printer(Vec2::new(1,1),
|
|
|
|
printer.size - (2,2),
|
|
|
|
true));
|
2015-05-23 22:58:06 +00:00
|
|
|
|
|
|
|
let h = printer.size.y-1;
|
|
|
|
let w = printer.size.x-1;
|
|
|
|
|
2015-06-06 01:08:05 +00:00
|
|
|
printer.with_color(ColorPair::Shadow, |printer| {
|
2015-05-23 22:58:06 +00:00
|
|
|
printer.print_hline((2,h), w-1, ' ' as u64);
|
|
|
|
printer.print_vline((w,2), h-1, ' ' as u64);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|