mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Add single-orientation FullView
full_width and full_height
This commit is contained in:
parent
b7a270f258
commit
c597c262fe
@ -1,22 +1,54 @@
|
|||||||
use view::{View, ViewWrapper};
|
use view::{View, ViewWrapper};
|
||||||
|
use orientation::Orientation;
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
|
|
||||||
/// Simple wrapper view that asks for all the space it can get.
|
/// Simple wrapper view that asks for all the space it can get.
|
||||||
pub struct FullView<T: View> {
|
pub struct FullView<T: View> {
|
||||||
view: T,
|
view: T,
|
||||||
|
orientation: Option<Orientation>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
enum Type {
|
||||||
|
FullWidth,
|
||||||
|
FullHeight,
|
||||||
|
FullScreen,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: View> FullView<T> {
|
impl<T: View> FullView<T> {
|
||||||
/// Wraps the given view into a new FullView.
|
/// Wraps the given view into a new FullView.
|
||||||
pub fn new(view: T) -> Self {
|
pub fn new(view: T) -> Self {
|
||||||
FullView { view: view }
|
FullView {
|
||||||
|
view: view,
|
||||||
|
orientation: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn full_width(view: T) -> Self {
|
||||||
|
FullView {
|
||||||
|
view: view,
|
||||||
|
orientation: Some(Orientation::Horizontal),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn full_height(view: T) -> Self {
|
||||||
|
FullView {
|
||||||
|
view: view,
|
||||||
|
orientation: Some(Orientation::Vertical),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: View> ViewWrapper for FullView<T> {
|
impl<T: View> ViewWrapper for FullView<T> {
|
||||||
wrap_impl!(&self.view);
|
wrap_impl!(&self.view);
|
||||||
|
|
||||||
fn wrap_get_min_size(&mut self, req: Vec2) -> Vec2 {
|
fn wrap_get_min_size(&mut self, mut req: Vec2) -> Vec2 {
|
||||||
|
if let Some(orientation) = self.orientation {
|
||||||
|
let child_size = self.view.get_min_size(req);
|
||||||
|
let orientation = orientation.swap();
|
||||||
|
*orientation.get_ref(&mut req) = orientation.get(&child_size);
|
||||||
|
}
|
||||||
|
|
||||||
req
|
req
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user