2015-05-19 02:41:35 +00:00
|
|
|
use vec::Vec2;
|
2016-10-02 22:22:29 +00:00
|
|
|
use view::View;
|
2015-05-19 02:41:35 +00:00
|
|
|
use view::ViewWrapper;
|
|
|
|
|
|
|
|
/// Wrapper around a view that remembers its size.
|
2016-03-15 22:37:57 +00:00
|
|
|
pub struct SizedView<T: View> {
|
2015-05-20 00:31:52 +00:00
|
|
|
/// Wrapped view.
|
2015-05-19 02:41:35 +00:00
|
|
|
pub view: T,
|
2015-05-20 00:31:52 +00:00
|
|
|
/// Cached size from the last layout() call.
|
2015-05-19 02:41:35 +00:00
|
|
|
pub size: Vec2,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: View> SizedView<T> {
|
|
|
|
/// Wraps the given view.
|
|
|
|
pub fn new(view: T) -> Self {
|
|
|
|
SizedView {
|
|
|
|
view: view,
|
|
|
|
size: Vec2::zero(),
|
|
|
|
}
|
|
|
|
}
|
2018-01-26 11:06:14 +00:00
|
|
|
|
|
|
|
inner_getters!(T);
|
2015-05-19 02:41:35 +00:00
|
|
|
}
|
|
|
|
|
2016-06-25 23:36:22 +00:00
|
|
|
impl<T: View> ViewWrapper for SizedView<T> {
|
2016-09-20 00:11:00 +00:00
|
|
|
wrap_impl!(self.view: T);
|
2015-05-19 02:41:35 +00:00
|
|
|
|
|
|
|
fn wrap_layout(&mut self, size: Vec2) {
|
|
|
|
self.size = size;
|
2016-07-02 03:23:58 +00:00
|
|
|
self.view.layout(size);
|
2015-05-19 02:41:35 +00:00
|
|
|
}
|
|
|
|
}
|