2015-05-15 00:41:17 +00:00
|
|
|
use event::EventResult;
|
2015-05-15 18:58:47 +00:00
|
|
|
use vec2::{Vec2,ToVec2};
|
2015-05-16 00:56:38 +00:00
|
|
|
use super::{View,SizeRequest};
|
2015-05-15 18:58:47 +00:00
|
|
|
use printer::Printer;
|
2015-05-15 00:41:17 +00:00
|
|
|
|
|
|
|
/// BoxView is a wrapper around an other view, with a given minimum size.
|
|
|
|
pub struct BoxView {
|
2015-05-15 18:58:47 +00:00
|
|
|
size: Vec2,
|
2015-05-15 00:41:17 +00:00
|
|
|
|
|
|
|
content: Box<View>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BoxView {
|
|
|
|
/// Creates a new BoxView with the given minimum size and content
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// // Creates a 20x4 BoxView with a TextView content.
|
|
|
|
/// let box = BoxView::new((20,4), TextView::new("Hello!"))
|
|
|
|
/// ```
|
2015-05-15 18:58:47 +00:00
|
|
|
pub fn new<S: ToVec2, V: View + 'static>(size: S, view: V) -> Self {
|
2015-05-15 00:41:17 +00:00
|
|
|
BoxView {
|
2015-05-15 18:58:47 +00:00
|
|
|
size: size.to_vec2(),
|
2015-05-15 00:41:17 +00:00
|
|
|
content: Box::new(view),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl View for BoxView {
|
|
|
|
fn on_key_event(&mut self, ch: i32) -> EventResult {
|
|
|
|
self.content.on_key_event(ch)
|
|
|
|
}
|
|
|
|
|
2015-05-15 18:58:47 +00:00
|
|
|
fn draw(&self, printer: &Printer) {
|
|
|
|
self.content.draw(printer)
|
2015-05-15 00:41:17 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 18:58:47 +00:00
|
|
|
fn get_min_size(&self, _: SizeRequest) -> Vec2 {
|
2015-05-15 00:41:17 +00:00
|
|
|
self.size
|
|
|
|
}
|
|
|
|
|
2015-05-15 18:58:47 +00:00
|
|
|
fn layout(&mut self, size: Vec2) {
|
2015-05-15 00:41:17 +00:00
|
|
|
self.content.layout(size);
|
|
|
|
}
|
|
|
|
}
|