mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-24 09:55:08 +00:00
34 lines
745 B
Rust
34 lines
745 B
Rust
|
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 {
|
||
|
Panel {
|
||
|
view: view,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
impl<V: View> ViewWrapper for Panel<V> {
|
||
|
wrap_impl!(&self.view);
|
||
|
|
||
|
fn wrap_get_min_size(&mut self, req: Vec2) -> Vec2 {
|
||
|
// TODO: make borders conditional?
|
||
|
self.view.get_min_size(req - (2, 2)) + (2, 2)
|
||
|
}
|
||
|
|
||
|
fn wrap_draw(&self, printer: &Printer) {
|
||
|
printer.print_box((0, 0), printer.size);
|
||
|
self.view
|
||
|
.draw(&printer.sub_printer((1, 1), printer.size - (2, 2), true));
|
||
|
}
|
||
|
}
|