mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Implement ViewWrapper::important_area
This commit is contained in:
parent
6729453118
commit
d140e154aa
@ -1,6 +1,7 @@
|
|||||||
use Printer;
|
use Printer;
|
||||||
use direction::Direction;
|
use direction::Direction;
|
||||||
use event::{Event, EventResult};
|
use event::{Event, EventResult};
|
||||||
|
use rect::Rect;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
use view::{Selector, View};
|
use view::{Selector, View};
|
||||||
@ -94,6 +95,12 @@ pub trait ViewWrapper: 'static {
|
|||||||
self.with_view(|v| v.needs_relayout())
|
self.with_view(|v| v.needs_relayout())
|
||||||
.unwrap_or(true)
|
.unwrap_or(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Wraps the `important_area` method.
|
||||||
|
fn wrap_important_area(&self, size: Vec2) -> Rect {
|
||||||
|
self.with_view(|v| v.important_area(size))
|
||||||
|
.unwrap_or(Rect::from((0, 0)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The main point of implementing ViewWrapper is to have View for free.
|
// The main point of implementing ViewWrapper is to have View for free.
|
||||||
@ -131,6 +138,10 @@ impl<T: ViewWrapper> View for T {
|
|||||||
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> {
|
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> {
|
||||||
self.wrap_focus_view(selector)
|
self.wrap_focus_view(selector)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn important_area(&self, size: Vec2) -> Rect {
|
||||||
|
self.wrap_important_area(size)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenient macro to implement the [`ViewWrapper`] trait.
|
/// Convenient macro to implement the [`ViewWrapper`] trait.
|
||||||
|
Loading…
Reference in New Issue
Block a user