2015-05-18 18:51:30 +00:00
|
|
|
use vec::{Vec2,ToVec2};
|
2015-05-19 22:54:11 +00:00
|
|
|
use super::{View,ViewWrapper,SizeRequest};
|
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
|
|
|
|
///
|
|
|
|
/// ```
|
2015-06-04 18:40:35 +00:00
|
|
|
/// # use cursive::view::{BoxView,TextView};
|
2015-05-15 00:41:17 +00:00
|
|
|
/// // Creates a 20x4 BoxView with a TextView content.
|
2015-06-04 18:40:35 +00:00
|
|
|
/// let view = BoxView::new((20,4), TextView::new("Hello!"));
|
2015-05-15 00:41:17 +00:00
|
|
|
/// ```
|
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),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-19 22:54:11 +00:00
|
|
|
impl ViewWrapper for BoxView {
|
2015-05-15 00:41:17 +00:00
|
|
|
|
2015-05-19 23:53:50 +00:00
|
|
|
wrap_impl!(self.content);
|
2015-05-15 00:41:17 +00:00
|
|
|
|
2015-05-19 22:54:11 +00:00
|
|
|
fn wrap_get_min_size(&self, _: SizeRequest) -> Vec2 {
|
2015-05-15 00:41:17 +00:00
|
|
|
self.size
|
|
|
|
}
|
|
|
|
}
|