mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-27 19:26:09 +00:00
Use BoxableView trait bound
This commit is contained in:
parent
e4bf9accc3
commit
17ccda2d40
@ -9,7 +9,7 @@ use std::path::Path;
|
|||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use theme;
|
use theme;
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
use view::{self, AnyView, Finder, Position, View};
|
use view::{self, AnyView, BoxableView, Finder, Position, View};
|
||||||
use views::{self, LayerPosition};
|
use views::{self, LayerPosition};
|
||||||
|
|
||||||
/// Identifies a screen in the cursive root.
|
/// Identifies a screen in the cursive root.
|
||||||
@ -454,7 +454,10 @@ impl Cursive {
|
|||||||
/// siv.add_layer(views::TextView::new("Hello world!"));
|
/// siv.add_layer(views::TextView::new("Hello world!"));
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn add_layer<T: 'static + View>(&mut self, view: T) {
|
pub fn add_layer<T>(&mut self, view: T)
|
||||||
|
where
|
||||||
|
T: BoxableView,
|
||||||
|
{
|
||||||
self.screen_mut().add_layer(view);
|
self.screen_mut().add_layer(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,7 +466,7 @@ impl Cursive {
|
|||||||
/// Fullscreen layers have no shadow.
|
/// Fullscreen layers have no shadow.
|
||||||
pub fn add_fullscreen_layer<T>(&mut self, view: T)
|
pub fn add_fullscreen_layer<T>(&mut self, view: T)
|
||||||
where
|
where
|
||||||
T: 'static + View,
|
T: BoxableView,
|
||||||
{
|
{
|
||||||
self.screen_mut().add_fullscreen_layer(view);
|
self.screen_mut().add_fullscreen_layer(view);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use view::{AnyView, View, ViewWrapper};
|
use view::{AnyView, BoxableView, ViewWrapper};
|
||||||
|
|
||||||
/// A boxed `AnyView`.
|
/// A boxed `AnyView`.
|
||||||
pub struct AnyBox {
|
pub struct AnyBox {
|
||||||
@ -13,8 +13,8 @@ impl AnyBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Box the given view
|
/// Box the given view
|
||||||
pub fn boxed<T: View>(view: T) -> Self {
|
pub fn boxed<T: BoxableView>(view: T) -> Self {
|
||||||
AnyBox::new(Box::new(view))
|
AnyBox::new(view.as_boxed_view())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the inner boxed view.
|
/// Returns the inner boxed view.
|
||||||
|
@ -7,7 +7,8 @@ use std::cell;
|
|||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use theme::ColorStyle;
|
use theme::ColorStyle;
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
use view::{AnyView, Offset, Position, Selector, View, ViewWrapper};
|
use view::{AnyView, BoxableView, Offset, Position, Selector, View,
|
||||||
|
ViewWrapper};
|
||||||
use views::{AnyBox, Layer, ShadowView};
|
use views::{AnyBox, Layer, ShadowView};
|
||||||
|
|
||||||
/// Simple stack of views.
|
/// Simple stack of views.
|
||||||
@ -180,7 +181,7 @@ impl StackView {
|
|||||||
/// Fullscreen layers have no shadow.
|
/// Fullscreen layers have no shadow.
|
||||||
pub fn add_fullscreen_layer<T>(&mut self, view: T)
|
pub fn add_fullscreen_layer<T>(&mut self, view: T)
|
||||||
where
|
where
|
||||||
T: 'static + View,
|
T: BoxableView,
|
||||||
{
|
{
|
||||||
let boxed = AnyBox::boxed(view);
|
let boxed = AnyBox::boxed(view);
|
||||||
self.layers.push(Child {
|
self.layers.push(Child {
|
||||||
@ -194,7 +195,7 @@ impl StackView {
|
|||||||
/// Adds new view on top of the stack in the center of the screen.
|
/// Adds new view on top of the stack in the center of the screen.
|
||||||
pub fn add_layer<T>(&mut self, view: T)
|
pub fn add_layer<T>(&mut self, view: T)
|
||||||
where
|
where
|
||||||
T: 'static + View,
|
T: BoxableView,
|
||||||
{
|
{
|
||||||
self.add_layer_at(Position::center(), view);
|
self.add_layer_at(Position::center(), view);
|
||||||
}
|
}
|
||||||
@ -204,7 +205,7 @@ impl StackView {
|
|||||||
/// Chainable variant.
|
/// Chainable variant.
|
||||||
pub fn layer<T>(self, view: T) -> Self
|
pub fn layer<T>(self, view: T) -> Self
|
||||||
where
|
where
|
||||||
T: 'static + View,
|
T: BoxableView,
|
||||||
{
|
{
|
||||||
self.with(|s| s.add_layer(view))
|
self.with(|s| s.add_layer(view))
|
||||||
}
|
}
|
||||||
@ -265,7 +266,7 @@ impl StackView {
|
|||||||
/// Chainable variant.
|
/// Chainable variant.
|
||||||
pub fn fullscreen_layer<T>(self, view: T) -> Self
|
pub fn fullscreen_layer<T>(self, view: T) -> Self
|
||||||
where
|
where
|
||||||
T: 'static + View,
|
T: BoxableView,
|
||||||
{
|
{
|
||||||
self.with(|s| s.add_fullscreen_layer(view))
|
self.with(|s| s.add_fullscreen_layer(view))
|
||||||
}
|
}
|
||||||
@ -273,7 +274,7 @@ impl StackView {
|
|||||||
/// Adds a view on top of the stack.
|
/// Adds a view on top of the stack.
|
||||||
pub fn add_layer_at<T>(&mut self, position: Position, view: T)
|
pub fn add_layer_at<T>(&mut self, position: Position, view: T)
|
||||||
where
|
where
|
||||||
T: 'static + View,
|
T: BoxableView,
|
||||||
{
|
{
|
||||||
let boxed = AnyBox::boxed(view);
|
let boxed = AnyBox::boxed(view);
|
||||||
self.layers.push(Child {
|
self.layers.push(Child {
|
||||||
@ -294,7 +295,7 @@ impl StackView {
|
|||||||
/// Chainable variant.
|
/// Chainable variant.
|
||||||
pub fn layer_at<T>(self, position: Position, view: T) -> Self
|
pub fn layer_at<T>(self, position: Position, view: T) -> Self
|
||||||
where
|
where
|
||||||
T: 'static + View,
|
T: BoxableView,
|
||||||
{
|
{
|
||||||
self.with(|s| s.add_layer_at(position, view))
|
self.with(|s| s.add_layer_at(position, view))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user