mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-24 01:46:31 +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 theme;
|
||||
use vec::Vec2;
|
||||
use view::{self, AnyView, Finder, Position, View};
|
||||
use view::{self, AnyView, BoxableView, Finder, Position, View};
|
||||
use views::{self, LayerPosition};
|
||||
|
||||
/// Identifies a screen in the cursive root.
|
||||
@ -454,7 +454,10 @@ impl Cursive {
|
||||
/// 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);
|
||||
}
|
||||
|
||||
@ -463,7 +466,7 @@ impl Cursive {
|
||||
/// Fullscreen layers have no shadow.
|
||||
pub fn add_fullscreen_layer<T>(&mut self, view: T)
|
||||
where
|
||||
T: 'static + View,
|
||||
T: BoxableView,
|
||||
{
|
||||
self.screen_mut().add_fullscreen_layer(view);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use view::{AnyView, View, ViewWrapper};
|
||||
use view::{AnyView, BoxableView, ViewWrapper};
|
||||
|
||||
/// A boxed `AnyView`.
|
||||
pub struct AnyBox {
|
||||
@ -13,8 +13,8 @@ impl AnyBox {
|
||||
}
|
||||
|
||||
/// Box the given view
|
||||
pub fn boxed<T: View>(view: T) -> Self {
|
||||
AnyBox::new(Box::new(view))
|
||||
pub fn boxed<T: BoxableView>(view: T) -> Self {
|
||||
AnyBox::new(view.as_boxed_view())
|
||||
}
|
||||
|
||||
/// Returns the inner boxed view.
|
||||
|
@ -7,7 +7,8 @@ use std::cell;
|
||||
use std::ops::Deref;
|
||||
use theme::ColorStyle;
|
||||
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};
|
||||
|
||||
/// Simple stack of views.
|
||||
@ -180,7 +181,7 @@ impl StackView {
|
||||
/// Fullscreen layers have no shadow.
|
||||
pub fn add_fullscreen_layer<T>(&mut self, view: T)
|
||||
where
|
||||
T: 'static + View,
|
||||
T: BoxableView,
|
||||
{
|
||||
let boxed = AnyBox::boxed(view);
|
||||
self.layers.push(Child {
|
||||
@ -194,7 +195,7 @@ impl StackView {
|
||||
/// Adds new view on top of the stack in the center of the screen.
|
||||
pub fn add_layer<T>(&mut self, view: T)
|
||||
where
|
||||
T: 'static + View,
|
||||
T: BoxableView,
|
||||
{
|
||||
self.add_layer_at(Position::center(), view);
|
||||
}
|
||||
@ -204,7 +205,7 @@ impl StackView {
|
||||
/// Chainable variant.
|
||||
pub fn layer<T>(self, view: T) -> Self
|
||||
where
|
||||
T: 'static + View,
|
||||
T: BoxableView,
|
||||
{
|
||||
self.with(|s| s.add_layer(view))
|
||||
}
|
||||
@ -265,7 +266,7 @@ impl StackView {
|
||||
/// Chainable variant.
|
||||
pub fn fullscreen_layer<T>(self, view: T) -> Self
|
||||
where
|
||||
T: 'static + View,
|
||||
T: BoxableView,
|
||||
{
|
||||
self.with(|s| s.add_fullscreen_layer(view))
|
||||
}
|
||||
@ -273,7 +274,7 @@ impl StackView {
|
||||
/// Adds a view on top of the stack.
|
||||
pub fn add_layer_at<T>(&mut self, position: Position, view: T)
|
||||
where
|
||||
T: 'static + View,
|
||||
T: BoxableView,
|
||||
{
|
||||
let boxed = AnyBox::boxed(view);
|
||||
self.layers.push(Child {
|
||||
@ -294,7 +295,7 @@ impl StackView {
|
||||
/// Chainable variant.
|
||||
pub fn layer_at<T>(self, position: Position, view: T) -> Self
|
||||
where
|
||||
T: 'static + View,
|
||||
T: BoxableView,
|
||||
{
|
||||
self.with(|s| s.add_layer_at(position, view))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user