cursive/src/views/panel.rs

39 lines
967 B
Rust
Raw Normal View History

2016-07-25 20:35:46 +00:00
use Printer;
use vec::Vec2;
use view::{View, ViewWrapper};
/// Draws a border around a wrapped view.
pub struct Panel<V: View> {
view: V,
}
impl<V: View> Panel<V> {
/// Creates a new panel around the given view.
pub fn new(view: V) -> Self {
2016-07-25 20:39:10 +00:00
Panel { view: view }
2016-07-25 20:35:46 +00:00
}
}
impl<V: View> ViewWrapper for Panel<V> {
wrap_impl!(self.view: V);
2016-07-25 20:35:46 +00:00
fn wrap_required_size(&mut self, req: Vec2) -> Vec2 {
2016-07-25 20:35:46 +00:00
// TODO: make borders conditional?
2017-08-14 23:32:01 +00:00
let req = req.saturating_sub((2, 2));
self.view.required_size(req) + (2, 2)
2016-07-25 20:35:46 +00:00
}
fn wrap_draw(&self, printer: &Printer) {
printer.print_box((0, 0), printer.size, true);
2017-03-15 23:35:20 +00:00
self.view.draw(&printer.sub_printer((1, 1),
2017-08-14 23:32:01 +00:00
printer.size.saturating_sub((2, 2)),
2017-03-15 23:35:20 +00:00
true));
}
fn wrap_layout(&mut self, size: Vec2) {
2017-08-14 23:32:01 +00:00
self.view.layout(size.saturating_sub((2, 2)));
2016-07-25 20:35:46 +00:00
}
}