mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Add TrackedView to cache the view size
This commit is contained in:
parent
87cd1ce23f
commit
c958093b74
@ -1,6 +1,7 @@
|
||||
//! Defines various views to use when creating the layout.
|
||||
|
||||
#[macro_use]mod view_wrapper;
|
||||
#[macro_use]
|
||||
mod view_wrapper;
|
||||
|
||||
// Essentials components
|
||||
mod position;
|
||||
@ -24,6 +25,7 @@ mod select_view;
|
||||
mod sized_view;
|
||||
mod stack_view;
|
||||
mod text_view;
|
||||
mod tracked_view;
|
||||
|
||||
|
||||
use std::any::Any;
|
||||
@ -50,6 +52,7 @@ pub use self::select_view::SelectView;
|
||||
pub use self::shadow_view::ShadowView;
|
||||
pub use self::stack_view::StackView;
|
||||
pub use self::text_view::TextView;
|
||||
pub use self::tracked_view::TrackedView;
|
||||
pub use self::sized_view::SizedView;
|
||||
pub use self::view_wrapper::ViewWrapper;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use ::vec::{ToVec2, Vec2};
|
||||
use vec::{ToVec2, Vec2};
|
||||
|
||||
/// Location of the view on screen
|
||||
pub struct Position {
|
||||
@ -8,10 +8,7 @@ pub struct Position {
|
||||
|
||||
impl Position {
|
||||
pub fn new(x: Offset, y: Offset) -> Self {
|
||||
Position {
|
||||
x: x,
|
||||
y: y,
|
||||
}
|
||||
Position { x: x, y: y }
|
||||
}
|
||||
|
||||
pub fn center() -> Self {
|
||||
|
@ -24,7 +24,7 @@ impl<T: View> ViewWrapper for SizedView<T> {
|
||||
wrap_impl!(&self.view);
|
||||
|
||||
fn wrap_layout(&mut self, size: Vec2) {
|
||||
self.view.layout(size);
|
||||
self.size = size;
|
||||
self.view.layout(size);
|
||||
}
|
||||
}
|
||||
|
30
src/view/tracked_view.rs
Normal file
30
src/view/tracked_view.rs
Normal file
@ -0,0 +1,30 @@
|
||||
use view::{IdView, View, ViewWrapper};
|
||||
use printer::Printer;
|
||||
use vec::Vec2;
|
||||
|
||||
pub struct TrackedView<T: View> {
|
||||
pub view: T,
|
||||
pub offset: Vec2,
|
||||
}
|
||||
|
||||
impl <T: View> TrackedView<T> {
|
||||
pub fn new(view: T) -> Self {
|
||||
TrackedView {
|
||||
view: view,
|
||||
offset: Vec2::zero(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_id(self, id: &str) -> IdView<Self> {
|
||||
IdView::new(id, self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: View> ViewWrapper for TrackedView<T> {
|
||||
wrap_impl!(&self.view);
|
||||
|
||||
fn wrap_draw(&mut self, printer: &Printer) {
|
||||
self.offset = printer.offset;
|
||||
self.view.draw(printer);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user