2019-02-28 23:54:12 +00:00
|
|
|
use crate::direction::Direction;
|
|
|
|
use crate::event::{AnyCb, Event, EventResult};
|
|
|
|
use crate::theme::ColorStyle;
|
2019-03-01 00:04:14 +00:00
|
|
|
use crate::view::{
|
|
|
|
IntoBoxedView, Offset, Position, Selector, View, ViewWrapper,
|
|
|
|
};
|
2020-01-06 19:51:50 +00:00
|
|
|
use crate::views::{BoxedView, CircularFocus, Layer, ShadowView};
|
2019-02-28 23:54:12 +00:00
|
|
|
use crate::Printer;
|
2020-01-06 23:51:38 +00:00
|
|
|
use crate::Vec2;
|
2019-02-28 23:54:12 +00:00
|
|
|
use crate::With;
|
2019-03-01 00:04:14 +00:00
|
|
|
use std::cell;
|
|
|
|
use std::ops::Deref;
|
2015-05-15 01:38:58 +00:00
|
|
|
|
2015-05-15 00:41:17 +00:00
|
|
|
/// Simple stack of views.
|
|
|
|
/// Only the top-most view is active and can receive input.
|
|
|
|
pub struct StackView {
|
2017-12-18 17:18:23 +00:00
|
|
|
// Store layers from back to front.
|
2017-01-24 02:54:33 +00:00
|
|
|
layers: Vec<Child>,
|
2016-07-20 07:30:00 +00:00
|
|
|
last_size: Vec2,
|
2018-02-08 00:25:00 +00:00
|
|
|
// Flag indicates if undrawn areas of the background are exposed
|
|
|
|
// and therefore need redrawing.
|
|
|
|
bg_dirty: cell::Cell<bool>,
|
2015-05-15 23:06:48 +00:00
|
|
|
}
|
|
|
|
|
2019-02-13 01:24:34 +00:00
|
|
|
/// Where should the view be on the screen (per dimension).
|
2017-01-24 02:54:33 +00:00
|
|
|
enum Placement {
|
2019-02-13 01:24:34 +00:00
|
|
|
/// View is floating at a specific position.
|
2017-01-24 02:54:33 +00:00
|
|
|
Floating(Position),
|
2019-02-13 01:24:34 +00:00
|
|
|
|
|
|
|
/// View is full-screen; it should not have a 1-cell border.
|
2017-01-24 02:54:33 +00:00
|
|
|
Fullscreen,
|
|
|
|
}
|
|
|
|
|
2017-12-18 17:18:23 +00:00
|
|
|
/// Identifies a layer in a `StackView`.
|
2018-03-11 23:51:28 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
2017-12-18 17:18:23 +00:00
|
|
|
pub enum LayerPosition {
|
|
|
|
/// Starts from the back (bottom) of the stack.
|
|
|
|
FromBack(usize),
|
|
|
|
/// Starts from the front (top) of the stack.
|
|
|
|
FromFront(usize),
|
|
|
|
}
|
|
|
|
|
2017-01-24 02:54:33 +00:00
|
|
|
impl Placement {
|
2017-10-11 18:35:18 +00:00
|
|
|
pub fn compute_offset<S, A, P>(
|
2019-07-30 23:08:05 +00:00
|
|
|
&self,
|
|
|
|
size: S,
|
|
|
|
available: A,
|
|
|
|
parent: P,
|
2017-10-11 18:35:18 +00:00
|
|
|
) -> Vec2
|
|
|
|
where
|
|
|
|
S: Into<Vec2>,
|
|
|
|
A: Into<Vec2>,
|
|
|
|
P: Into<Vec2>,
|
2017-01-24 02:54:33 +00:00
|
|
|
{
|
|
|
|
match *self {
|
|
|
|
Placement::Floating(ref position) => {
|
|
|
|
position.compute_offset(size, available, parent)
|
|
|
|
}
|
|
|
|
Placement::Fullscreen => Vec2::zero(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 01:24:34 +00:00
|
|
|
/// A child view can be wrapped in multiple ways.
|
2017-12-15 07:19:18 +00:00
|
|
|
enum ChildWrapper<T: View> {
|
|
|
|
// Some views include a shadow around.
|
2019-01-24 19:57:30 +00:00
|
|
|
Shadow(ShadowView<Layer<CircularFocus<T>>>),
|
2018-09-12 23:13:41 +00:00
|
|
|
|
|
|
|
// Some include only include a background.
|
2019-01-24 19:57:30 +00:00
|
|
|
Backfilled(Layer<CircularFocus<T>>),
|
2018-09-12 23:13:41 +00:00
|
|
|
|
|
|
|
// Some views don't even have a background (they'll be transparent).
|
2019-01-24 19:57:30 +00:00
|
|
|
Plain(CircularFocus<T>),
|
2017-12-15 07:19:18 +00:00
|
|
|
}
|
|
|
|
|
2017-12-15 07:45:14 +00:00
|
|
|
impl<T: View> ChildWrapper<T> {
|
|
|
|
fn unwrap(self) -> T {
|
|
|
|
match self {
|
2019-01-24 19:57:30 +00:00
|
|
|
// All these into_inner() can never fail.
|
|
|
|
// (ShadowView, Layer, CircularFocus)
|
|
|
|
ChildWrapper::Shadow(shadow) => shadow
|
|
|
|
.into_inner()
|
|
|
|
.ok()
|
|
|
|
.unwrap()
|
|
|
|
.into_inner()
|
|
|
|
.ok()
|
|
|
|
.unwrap()
|
|
|
|
.into_inner()
|
|
|
|
.ok()
|
|
|
|
.unwrap(),
|
2018-05-29 22:27:33 +00:00
|
|
|
// Layer::into_inner can never fail.
|
2019-01-24 19:57:30 +00:00
|
|
|
ChildWrapper::Backfilled(background) => background
|
|
|
|
.into_inner()
|
|
|
|
.ok()
|
|
|
|
.unwrap()
|
|
|
|
.into_inner()
|
|
|
|
.ok()
|
|
|
|
.unwrap(),
|
|
|
|
ChildWrapper::Plain(layer) => layer.into_inner().ok().unwrap(),
|
2017-12-15 07:45:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-15 07:19:18 +00:00
|
|
|
|
2018-03-14 21:59:41 +00:00
|
|
|
impl<T: View> ChildWrapper<T> {
|
2018-03-11 23:51:28 +00:00
|
|
|
/// Returns a reference to the inner view
|
2018-06-26 20:54:49 +00:00
|
|
|
pub fn get_inner(&self) -> &T {
|
2018-03-11 23:51:28 +00:00
|
|
|
match *self {
|
2019-01-24 19:57:30 +00:00
|
|
|
ChildWrapper::Shadow(ref shadow) => {
|
|
|
|
shadow.get_inner().get_inner().get_inner()
|
|
|
|
}
|
|
|
|
ChildWrapper::Backfilled(ref background) => {
|
|
|
|
background.get_inner().get_inner()
|
|
|
|
}
|
|
|
|
ChildWrapper::Plain(ref layer) => layer.get_inner(),
|
2018-03-11 23:51:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a mutable reference to the inner view
|
2018-06-26 20:54:49 +00:00
|
|
|
pub fn get_inner_mut(&mut self) -> &mut T {
|
2018-03-11 23:51:28 +00:00
|
|
|
match *self {
|
|
|
|
ChildWrapper::Shadow(ref mut shadow) => {
|
2019-01-24 19:57:30 +00:00
|
|
|
shadow.get_inner_mut().get_inner_mut().get_inner_mut()
|
2018-03-11 23:51:28 +00:00
|
|
|
}
|
2018-05-29 22:27:33 +00:00
|
|
|
ChildWrapper::Backfilled(ref mut background) => {
|
2019-01-24 19:57:30 +00:00
|
|
|
background.get_inner_mut().get_inner_mut()
|
2018-05-29 22:27:33 +00:00
|
|
|
}
|
2019-01-24 19:57:30 +00:00
|
|
|
ChildWrapper::Plain(ref mut layer) => layer.get_inner_mut(),
|
2018-03-11 23:51:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-15 07:45:14 +00:00
|
|
|
// TODO: use macros to make this less ugly?
|
|
|
|
impl<T: View> View for ChildWrapper<T> {
|
2019-02-28 23:55:02 +00:00
|
|
|
fn draw(&self, printer: &Printer<'_, '_>) {
|
2017-12-15 07:19:18 +00:00
|
|
|
match *self {
|
|
|
|
ChildWrapper::Shadow(ref v) => v.draw(printer),
|
2018-05-29 22:27:33 +00:00
|
|
|
ChildWrapper::Backfilled(ref v) => v.draw(printer),
|
2017-12-15 07:19:18 +00:00
|
|
|
ChildWrapper::Plain(ref v) => v.draw(printer),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn on_event(&mut self, event: Event) -> EventResult {
|
|
|
|
match *self {
|
|
|
|
ChildWrapper::Shadow(ref mut v) => v.on_event(event),
|
2018-05-29 22:27:33 +00:00
|
|
|
ChildWrapper::Backfilled(ref mut v) => v.on_event(event),
|
2017-12-15 07:19:18 +00:00
|
|
|
ChildWrapper::Plain(ref mut v) => v.on_event(event),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn layout(&mut self, size: Vec2) {
|
|
|
|
match *self {
|
|
|
|
ChildWrapper::Shadow(ref mut v) => v.layout(size),
|
2018-05-29 22:27:33 +00:00
|
|
|
ChildWrapper::Backfilled(ref mut v) => v.layout(size),
|
2017-12-15 07:19:18 +00:00
|
|
|
ChildWrapper::Plain(ref mut v) => v.layout(size),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn required_size(&mut self, size: Vec2) -> Vec2 {
|
|
|
|
match *self {
|
|
|
|
ChildWrapper::Shadow(ref mut v) => v.required_size(size),
|
2018-05-29 22:27:33 +00:00
|
|
|
ChildWrapper::Backfilled(ref mut v) => v.required_size(size),
|
2017-12-15 07:19:18 +00:00
|
|
|
ChildWrapper::Plain(ref mut v) => v.required_size(size),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn take_focus(&mut self, source: Direction) -> bool {
|
|
|
|
match *self {
|
|
|
|
ChildWrapper::Shadow(ref mut v) => v.take_focus(source),
|
2018-05-29 22:27:33 +00:00
|
|
|
ChildWrapper::Backfilled(ref mut v) => v.take_focus(source),
|
2017-12-15 07:19:18 +00:00
|
|
|
ChildWrapper::Plain(ref mut v) => v.take_focus(source),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-01 00:04:14 +00:00
|
|
|
fn call_on_any<'a>(
|
2019-07-30 23:08:05 +00:00
|
|
|
&mut self,
|
|
|
|
selector: &Selector<'_>,
|
|
|
|
callback: AnyCb<'a>,
|
2019-03-01 00:04:14 +00:00
|
|
|
) {
|
2017-12-15 07:19:18 +00:00
|
|
|
match *self {
|
2017-12-15 07:45:14 +00:00
|
|
|
ChildWrapper::Shadow(ref mut v) => {
|
|
|
|
v.call_on_any(selector, callback)
|
|
|
|
}
|
2018-05-29 22:27:33 +00:00
|
|
|
ChildWrapper::Backfilled(ref mut v) => {
|
|
|
|
v.call_on_any(selector, callback)
|
|
|
|
}
|
2017-12-15 07:45:14 +00:00
|
|
|
ChildWrapper::Plain(ref mut v) => {
|
|
|
|
v.call_on_any(selector, callback)
|
|
|
|
}
|
2017-12-15 07:19:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-28 23:55:02 +00:00
|
|
|
fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
|
2017-12-15 07:19:18 +00:00
|
|
|
match *self {
|
|
|
|
ChildWrapper::Shadow(ref mut v) => v.focus_view(selector),
|
2018-05-29 22:27:33 +00:00
|
|
|
ChildWrapper::Backfilled(ref mut v) => v.focus_view(selector),
|
2017-12-15 07:19:18 +00:00
|
|
|
ChildWrapper::Plain(ref mut v) => v.focus_view(selector),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-24 02:54:33 +00:00
|
|
|
struct Child {
|
2020-01-06 19:51:50 +00:00
|
|
|
view: ChildWrapper<BoxedView>,
|
2015-05-15 23:06:48 +00:00
|
|
|
size: Vec2,
|
2017-01-24 02:54:33 +00:00
|
|
|
placement: Placement,
|
|
|
|
|
|
|
|
// We cannot call `take_focus` until we've called `layout()`
|
2017-10-11 18:51:46 +00:00
|
|
|
// (for instance, a textView must know it will scroll to be focusable).
|
|
|
|
// So we want to call `take_focus` right after the first call to `layout`.
|
|
|
|
// This flag remembers when we've done that.
|
2015-05-31 04:53:25 +00:00
|
|
|
virgin: bool,
|
2015-05-15 00:41:17 +00:00
|
|
|
}
|
|
|
|
|
2016-07-17 00:28:42 +00:00
|
|
|
new_default!(StackView);
|
2016-06-28 05:40:11 +00:00
|
|
|
|
2015-05-15 00:41:17 +00:00
|
|
|
impl StackView {
|
|
|
|
/// Creates a new empty StackView
|
|
|
|
pub fn new() -> Self {
|
2016-07-20 07:30:00 +00:00
|
|
|
StackView {
|
|
|
|
layers: Vec::new(),
|
|
|
|
last_size: Vec2::zero(),
|
2018-02-08 00:25:00 +00:00
|
|
|
bg_dirty: cell::Cell::new(true),
|
2016-07-20 07:30:00 +00:00
|
|
|
}
|
2015-05-15 00:41:17 +00:00
|
|
|
}
|
2015-05-15 00:48:24 +00:00
|
|
|
|
2019-02-13 01:24:34 +00:00
|
|
|
/// Returns the number of layers in this `StackView`.
|
|
|
|
pub fn len(&self) -> usize {
|
|
|
|
self.layers.len()
|
|
|
|
}
|
|
|
|
|
2019-03-04 18:31:36 +00:00
|
|
|
/// Returns `true` if there is no layer in this `StackView`.
|
|
|
|
pub fn is_empty(&self) -> bool {
|
|
|
|
self.layers.is_empty()
|
|
|
|
}
|
|
|
|
|
2019-02-13 01:24:34 +00:00
|
|
|
/// Returns `true` if `position` points to a valid layer.
|
|
|
|
///
|
|
|
|
/// Returns `false` if it exceeds the bounds.
|
|
|
|
pub fn fits(&self, position: LayerPosition) -> bool {
|
|
|
|
let i = match position {
|
|
|
|
LayerPosition::FromBack(i) | LayerPosition::FromFront(i) => i,
|
|
|
|
};
|
|
|
|
|
|
|
|
i < self.len()
|
|
|
|
}
|
|
|
|
|
2017-01-24 02:54:33 +00:00
|
|
|
/// Adds a new full-screen layer on top of the stack.
|
|
|
|
///
|
|
|
|
/// Fullscreen layers have no shadow.
|
|
|
|
pub fn add_fullscreen_layer<T>(&mut self, view: T)
|
2017-10-11 18:35:18 +00:00
|
|
|
where
|
2018-03-14 20:58:57 +00:00
|
|
|
T: IntoBoxedView,
|
2017-01-24 02:54:33 +00:00
|
|
|
{
|
2020-01-06 19:51:50 +00:00
|
|
|
let boxed = BoxedView::boxed(view);
|
2017-01-24 02:54:33 +00:00
|
|
|
self.layers.push(Child {
|
2019-01-24 19:57:30 +00:00
|
|
|
view: ChildWrapper::Backfilled(Layer::new(
|
|
|
|
CircularFocus::wrap_tab(boxed),
|
|
|
|
)),
|
2017-01-24 02:54:33 +00:00
|
|
|
size: Vec2::zero(),
|
|
|
|
placement: Placement::Fullscreen,
|
|
|
|
virgin: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-07-02 02:19:43 +00:00
|
|
|
/// Adds new view on top of the stack in the center of the screen.
|
2017-01-24 02:54:33 +00:00
|
|
|
pub fn add_layer<T>(&mut self, view: T)
|
2017-10-11 18:35:18 +00:00
|
|
|
where
|
2018-03-14 20:58:57 +00:00
|
|
|
T: IntoBoxedView,
|
2017-01-24 02:54:33 +00:00
|
|
|
{
|
2016-07-02 02:19:43 +00:00
|
|
|
self.add_layer_at(Position::center(), view);
|
|
|
|
}
|
|
|
|
|
2017-04-03 17:41:18 +00:00
|
|
|
/// Adds new view on top of the stack in the center of the screen.
|
|
|
|
///
|
|
|
|
/// Chainable variant.
|
|
|
|
pub fn layer<T>(self, view: T) -> Self
|
2017-10-11 18:35:18 +00:00
|
|
|
where
|
2018-03-14 20:58:57 +00:00
|
|
|
T: IntoBoxedView,
|
2017-04-03 17:41:18 +00:00
|
|
|
{
|
|
|
|
self.with(|s| s.add_layer(view))
|
|
|
|
}
|
|
|
|
|
2018-03-11 23:51:28 +00:00
|
|
|
/// Returns a reference to the layer at the given position.
|
2019-02-28 23:55:02 +00:00
|
|
|
pub fn get(&self, pos: LayerPosition) -> Option<&dyn View> {
|
2019-02-13 01:24:34 +00:00
|
|
|
self.get_index(pos).and_then(|i| {
|
|
|
|
self.layers.get(i).map(|child| &**child.view.get_inner())
|
|
|
|
})
|
2018-03-11 23:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a mutable reference to the layer at the given position.
|
2019-02-28 23:55:02 +00:00
|
|
|
pub fn get_mut(&mut self, pos: LayerPosition) -> Option<&mut dyn View> {
|
2019-02-13 01:24:34 +00:00
|
|
|
self.get_index(pos).and_then(move |i| {
|
|
|
|
self.layers
|
|
|
|
.get_mut(i)
|
|
|
|
.map(|child| &mut **child.view.get_inner_mut())
|
|
|
|
})
|
2018-03-11 23:51:28 +00:00
|
|
|
}
|
|
|
|
|
2020-01-06 23:41:51 +00:00
|
|
|
/// Looks for the layer containing a view with the given name.
|
2018-03-11 23:51:28 +00:00
|
|
|
///
|
2020-01-06 23:41:51 +00:00
|
|
|
/// Returns `Some(pos)` if `self.get(pos)` has the given name,
|
|
|
|
/// or is a parent of a view with this name.
|
2018-03-11 23:51:28 +00:00
|
|
|
///
|
2020-01-06 23:41:51 +00:00
|
|
|
/// Returns `None` if the given name is not found.
|
2018-03-11 23:51:28 +00:00
|
|
|
///
|
2019-02-13 01:24:34 +00:00
|
|
|
/// Note that the returned position may be invalidated if some layers are
|
|
|
|
/// removed from the view.
|
|
|
|
///
|
2018-03-11 23:51:28 +00:00
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// # use cursive::views::{TextView, StackView, Dialog, LayerPosition};
|
|
|
|
/// # use cursive::view::Identifiable;
|
|
|
|
/// let mut stack = StackView::new();
|
|
|
|
/// stack.add_layer(TextView::new("Back"));
|
2020-01-06 23:39:30 +00:00
|
|
|
/// stack.add_layer(Dialog::around(TextView::new("Middle").with_name("text")));
|
2018-03-11 23:51:28 +00:00
|
|
|
/// stack.add_layer(TextView::new("Front"));
|
|
|
|
///
|
2020-01-06 23:39:30 +00:00
|
|
|
/// assert_eq!(stack.find_layer_from_name("text"), Some(LayerPosition::FromBack(1)));
|
2018-03-11 23:51:28 +00:00
|
|
|
/// ```
|
2020-01-06 23:39:30 +00:00
|
|
|
pub fn find_layer_from_name(&mut self, id: &str) -> Option<LayerPosition> {
|
2020-01-06 20:10:24 +00:00
|
|
|
let selector = Selector::Name(id);
|
2018-03-11 23:51:28 +00:00
|
|
|
|
|
|
|
for (i, child) in self.layers.iter_mut().enumerate() {
|
|
|
|
let mut found = false;
|
2019-09-06 23:02:20 +00:00
|
|
|
child.view.call_on_any(&selector, &mut |_| found = true);
|
2018-03-11 23:51:28 +00:00
|
|
|
if found {
|
|
|
|
return Some(LayerPosition::FromBack(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2020-01-06 23:39:30 +00:00
|
|
|
/// Same as [`find_layer_from_name`](StackView::find_layer_from_name).
|
|
|
|
#[deprecated(
|
|
|
|
note = "`find_layer_from_id` is being renamed to `find_layer_from_name`"
|
|
|
|
)]
|
|
|
|
pub fn find_layer_from_id(&mut self, id: &str) -> Option<LayerPosition> {
|
|
|
|
self.find_layer_from_name(id)
|
|
|
|
}
|
|
|
|
|
2017-04-03 17:41:18 +00:00
|
|
|
/// Adds a new full-screen layer on top of the stack.
|
|
|
|
///
|
|
|
|
/// Chainable variant.
|
|
|
|
pub fn fullscreen_layer<T>(self, view: T) -> Self
|
2017-10-11 18:35:18 +00:00
|
|
|
where
|
2018-03-14 20:58:57 +00:00
|
|
|
T: IntoBoxedView,
|
2017-04-03 17:41:18 +00:00
|
|
|
{
|
|
|
|
self.with(|s| s.add_fullscreen_layer(view))
|
|
|
|
}
|
|
|
|
|
2018-05-29 22:27:33 +00:00
|
|
|
/// Adds a new transparent layer on top of the stack.
|
|
|
|
///
|
|
|
|
/// Chainable variant.
|
|
|
|
pub fn transparent_layer<T>(self, view: T) -> Self
|
|
|
|
where
|
|
|
|
T: IntoBoxedView,
|
|
|
|
{
|
|
|
|
self.with(|s| s.add_transparent_layer(view))
|
|
|
|
}
|
|
|
|
|
2016-07-02 02:19:43 +00:00
|
|
|
/// Adds a view on top of the stack.
|
2017-01-24 02:54:33 +00:00
|
|
|
pub fn add_layer_at<T>(&mut self, position: Position, view: T)
|
2017-10-11 18:35:18 +00:00
|
|
|
where
|
2018-03-14 20:58:57 +00:00
|
|
|
T: IntoBoxedView,
|
2017-01-24 02:54:33 +00:00
|
|
|
{
|
2020-01-06 19:51:50 +00:00
|
|
|
let boxed = BoxedView::boxed(view);
|
2017-01-24 02:54:33 +00:00
|
|
|
self.layers.push(Child {
|
2016-07-03 02:46:23 +00:00
|
|
|
// Skip padding for absolute/parent-placed views
|
2017-12-15 07:19:18 +00:00
|
|
|
view: ChildWrapper::Shadow(
|
2019-01-24 19:57:30 +00:00
|
|
|
ShadowView::new(Layer::new(CircularFocus::wrap_tab(boxed)))
|
2017-10-11 18:35:18 +00:00
|
|
|
.top_padding(position.y == Offset::Center)
|
|
|
|
.left_padding(position.x == Offset::Center),
|
|
|
|
),
|
2016-03-15 22:37:57 +00:00
|
|
|
size: Vec2::new(0, 0),
|
2017-01-24 02:54:33 +00:00
|
|
|
placement: Placement::Floating(position),
|
2015-05-31 04:53:25 +00:00
|
|
|
virgin: true,
|
2015-05-15 23:06:48 +00:00
|
|
|
});
|
2015-05-15 01:38:58 +00:00
|
|
|
}
|
|
|
|
|
2018-05-29 22:27:33 +00:00
|
|
|
/// Adds a transparent view on top of the stack in the center of the screen.
|
|
|
|
pub fn add_transparent_layer<T>(&mut self, view: T)
|
|
|
|
where
|
|
|
|
T: IntoBoxedView,
|
|
|
|
{
|
|
|
|
self.add_transparent_layer_at(Position::center(), view);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Adds a transparent view on top of the stack.
|
|
|
|
pub fn add_transparent_layer_at<T>(&mut self, position: Position, view: T)
|
|
|
|
where
|
|
|
|
T: IntoBoxedView,
|
|
|
|
{
|
2020-01-06 19:51:50 +00:00
|
|
|
let boxed = BoxedView::boxed(view);
|
2018-05-29 22:27:33 +00:00
|
|
|
self.layers.push(Child {
|
2019-01-24 19:57:30 +00:00
|
|
|
view: ChildWrapper::Plain(CircularFocus::wrap_tab(boxed)),
|
2018-05-29 22:27:33 +00:00
|
|
|
size: Vec2::new(0, 0),
|
|
|
|
placement: Placement::Floating(position),
|
|
|
|
virgin: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-13 01:24:34 +00:00
|
|
|
/// Adds a view on top of the stack at the given position.
|
2017-04-03 17:41:18 +00:00
|
|
|
///
|
|
|
|
/// Chainable variant.
|
|
|
|
pub fn layer_at<T>(self, position: Position, view: T) -> Self
|
2017-10-11 18:35:18 +00:00
|
|
|
where
|
2018-03-14 20:58:57 +00:00
|
|
|
T: IntoBoxedView,
|
2017-04-03 17:41:18 +00:00
|
|
|
{
|
|
|
|
self.with(|s| s.add_layer_at(position, view))
|
|
|
|
}
|
|
|
|
|
2019-02-13 01:24:34 +00:00
|
|
|
/// Remove a layer from this `StackView`.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// If the given position is out of bounds.
|
2019-02-28 23:55:02 +00:00
|
|
|
pub fn remove_layer(&mut self, position: LayerPosition) -> Box<dyn View> {
|
2019-02-13 01:24:34 +00:00
|
|
|
let i = self.get_index(position).unwrap();
|
|
|
|
self.layers.remove(i).view.unwrap().unwrap()
|
|
|
|
}
|
|
|
|
|
2015-05-15 01:38:58 +00:00
|
|
|
/// Remove the top-most layer.
|
2019-02-28 23:55:02 +00:00
|
|
|
pub fn pop_layer(&mut self) -> Option<Box<dyn View>> {
|
2018-02-08 00:25:00 +00:00
|
|
|
self.bg_dirty.set(true);
|
2018-03-14 19:32:07 +00:00
|
|
|
self.layers
|
|
|
|
.pop()
|
|
|
|
.map(|child| child.view)
|
|
|
|
.map(ChildWrapper::unwrap)
|
2020-01-06 19:51:50 +00:00
|
|
|
.map(BoxedView::unwrap)
|
2015-05-15 00:48:24 +00:00
|
|
|
}
|
2016-07-20 07:30:00 +00:00
|
|
|
|
|
|
|
/// Computes the offset of the current top view.
|
|
|
|
pub fn offset(&self) -> Vec2 {
|
|
|
|
let mut previous = Vec2::zero();
|
|
|
|
for layer in &self.layers {
|
2017-10-11 18:35:18 +00:00
|
|
|
let offset = layer.placement.compute_offset(
|
|
|
|
layer.size,
|
|
|
|
self.last_size,
|
|
|
|
previous,
|
|
|
|
);
|
2016-07-20 07:30:00 +00:00
|
|
|
previous = offset;
|
|
|
|
}
|
|
|
|
previous
|
|
|
|
}
|
2016-10-12 00:12:00 +00:00
|
|
|
|
|
|
|
/// Returns the size for each layer in this view.
|
|
|
|
pub fn layer_sizes(&self) -> Vec<Vec2> {
|
2018-04-17 05:39:16 +00:00
|
|
|
self.layers.iter().map(|layer| layer.size).collect()
|
2016-10-12 00:12:00 +00:00
|
|
|
}
|
2017-12-18 17:18:23 +00:00
|
|
|
|
2019-02-13 01:24:34 +00:00
|
|
|
fn get_index(&self, pos: LayerPosition) -> Option<usize> {
|
2017-12-18 17:18:23 +00:00
|
|
|
match pos {
|
2019-02-13 01:24:34 +00:00
|
|
|
LayerPosition::FromBack(i) => Some(i),
|
|
|
|
LayerPosition::FromFront(i) => {
|
|
|
|
self.layers.len().checked_sub(i + 1)
|
|
|
|
}
|
2017-12-18 17:18:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Moves a layer to a new position in the stack.
|
2017-12-30 22:03:42 +00:00
|
|
|
///
|
2017-12-18 17:18:23 +00:00
|
|
|
/// This only affects the elevation of a layer (whether it is drawn over
|
|
|
|
/// or under other views).
|
2019-02-13 01:24:34 +00:00
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// If either `from` or `to` is out of bounds.
|
2017-12-18 17:18:23 +00:00
|
|
|
pub fn move_layer(&mut self, from: LayerPosition, to: LayerPosition) {
|
|
|
|
// Convert relative positions to indices in the array
|
2019-02-13 01:24:34 +00:00
|
|
|
let from = self.get_index(from).unwrap();
|
|
|
|
let to = self.get_index(to).unwrap();
|
2017-12-18 17:18:23 +00:00
|
|
|
|
2019-02-13 01:24:34 +00:00
|
|
|
let removed = self.layers.remove(from);
|
|
|
|
self.layers.insert(to, removed);
|
2017-12-18 17:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Brings the given view to the front of the stack.
|
2019-02-13 01:24:34 +00:00
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// If `layer` is out of bounds.
|
2017-12-18 17:18:23 +00:00
|
|
|
pub fn move_to_front(&mut self, layer: LayerPosition) {
|
|
|
|
self.move_layer(layer, LayerPosition::FromFront(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Pushes the given view to the back of the stack.
|
2019-02-13 01:24:34 +00:00
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// If `layer` is out of bounds.
|
2017-12-18 17:18:23 +00:00
|
|
|
pub fn move_to_back(&mut self, layer: LayerPosition) {
|
|
|
|
self.move_layer(layer, LayerPosition::FromBack(0));
|
|
|
|
}
|
2018-02-08 00:25:00 +00:00
|
|
|
|
|
|
|
/// Moves a layer to a new position on the screen.
|
|
|
|
///
|
2019-02-13 01:24:34 +00:00
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// If `layer` is out of bounds.
|
2018-02-08 00:25:00 +00:00
|
|
|
pub fn reposition_layer(
|
2019-07-30 23:08:05 +00:00
|
|
|
&mut self,
|
|
|
|
layer: LayerPosition,
|
|
|
|
position: Position,
|
2018-02-08 00:25:00 +00:00
|
|
|
) {
|
2019-02-13 01:24:34 +00:00
|
|
|
let i = self.get_index(layer).unwrap();
|
|
|
|
let child = &mut self.layers[i];
|
2018-02-08 00:25:00 +00:00
|
|
|
match child.placement {
|
|
|
|
Placement::Floating(_) => {
|
|
|
|
child.placement = Placement::Floating(position);
|
|
|
|
self.bg_dirty.set(true);
|
|
|
|
}
|
|
|
|
Placement::Fullscreen => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Background drawing
|
2018-03-11 23:51:28 +00:00
|
|
|
///
|
2018-02-08 00:25:00 +00:00
|
|
|
/// Drawing functions are split into forground and background to
|
2019-02-13 01:24:34 +00:00
|
|
|
/// ease inserting layers under the stackview but above its background.
|
|
|
|
///
|
2018-02-08 00:25:00 +00:00
|
|
|
/// you probably just want to call draw()
|
2019-02-28 23:55:02 +00:00
|
|
|
pub fn draw_bg(&self, printer: &Printer<'_, '_>) {
|
2018-02-08 00:25:00 +00:00
|
|
|
// If the background is dirty draw a new background
|
|
|
|
if self.bg_dirty.get() {
|
|
|
|
for y in 0..printer.size.y {
|
|
|
|
printer.with_color(ColorStyle::background(), |printer| {
|
|
|
|
printer.print_hline((0, y), printer.size.x, " ");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// set background as clean, so we don't need to do this every frame
|
|
|
|
self.bg_dirty.set(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Forground drawing
|
2018-03-11 23:51:28 +00:00
|
|
|
///
|
2018-02-08 00:25:00 +00:00
|
|
|
/// Drawing functions are split into forground and background to
|
2019-02-13 01:24:34 +00:00
|
|
|
/// ease inserting layers under the stackview but above its background.
|
|
|
|
///
|
|
|
|
/// You probably just want to call draw()
|
2019-02-28 23:55:02 +00:00
|
|
|
pub fn draw_fg(&self, printer: &Printer<'_, '_>) {
|
2018-02-08 00:25:00 +00:00
|
|
|
let last = self.layers.len();
|
|
|
|
printer.with_color(ColorStyle::primary(), |printer| {
|
|
|
|
for (i, (v, offset)) in
|
|
|
|
StackPositionIterator::new(self.layers.iter(), printer.size)
|
|
|
|
.enumerate()
|
|
|
|
{
|
2018-06-16 20:23:09 +00:00
|
|
|
v.view.draw(
|
|
|
|
&printer
|
|
|
|
.offset(offset)
|
|
|
|
.cropped(v.size)
|
|
|
|
.focused(i + 1 == last),
|
|
|
|
);
|
2018-02-08 00:25:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-05-15 00:41:17 +00:00
|
|
|
}
|
|
|
|
|
2019-02-13 01:24:34 +00:00
|
|
|
/// Iterates on the layers and compute the position of each.
|
|
|
|
struct StackPositionIterator<I> {
|
2017-10-11 18:35:18 +00:00
|
|
|
inner: I,
|
|
|
|
previous: Vec2,
|
|
|
|
total_size: Vec2,
|
|
|
|
}
|
|
|
|
|
2019-02-13 01:24:34 +00:00
|
|
|
impl<I> StackPositionIterator<I>
|
|
|
|
where
|
|
|
|
I: Iterator,
|
|
|
|
I::Item: Deref<Target = Child>,
|
2018-01-22 22:37:27 +00:00
|
|
|
{
|
2017-10-11 18:35:18 +00:00
|
|
|
/// Returns a new StackPositionIterator
|
|
|
|
pub fn new(inner: I, total_size: Vec2) -> Self {
|
|
|
|
let previous = Vec2::zero();
|
|
|
|
StackPositionIterator {
|
|
|
|
inner,
|
|
|
|
previous,
|
|
|
|
total_size,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 01:24:34 +00:00
|
|
|
impl<I> Iterator for StackPositionIterator<I>
|
|
|
|
where
|
|
|
|
I: Iterator,
|
|
|
|
I::Item: Deref<Target = Child>,
|
2018-01-22 22:37:27 +00:00
|
|
|
{
|
2019-02-13 01:24:34 +00:00
|
|
|
type Item = (I::Item, Vec2);
|
2017-10-11 18:35:18 +00:00
|
|
|
|
2019-02-13 01:24:34 +00:00
|
|
|
fn next(&mut self) -> Option<(I::Item, Vec2)> {
|
2017-10-11 18:35:18 +00:00
|
|
|
self.inner.next().map(|v| {
|
|
|
|
let offset = v.placement.compute_offset(
|
|
|
|
v.size,
|
|
|
|
self.total_size,
|
|
|
|
self.previous,
|
|
|
|
);
|
|
|
|
|
|
|
|
self.previous = offset;
|
|
|
|
|
2017-10-12 23:41:45 +00:00
|
|
|
// eprintln!("{:?}", offset);
|
2017-10-11 18:35:18 +00:00
|
|
|
(v, offset)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-15 00:41:17 +00:00
|
|
|
impl View for StackView {
|
2019-02-28 23:55:02 +00:00
|
|
|
fn draw(&self, printer: &Printer<'_, '_>) {
|
2018-02-08 00:25:00 +00:00
|
|
|
// This function is included for compat with the view trait,
|
|
|
|
// it should behave the same as calling them seperately, but does
|
|
|
|
// not pause to let you insert in between the layers.
|
|
|
|
self.draw_bg(printer);
|
|
|
|
self.draw_fg(printer);
|
2015-05-15 00:41:17 +00:00
|
|
|
}
|
2015-05-15 01:38:58 +00:00
|
|
|
|
2015-05-28 01:04:33 +00:00
|
|
|
fn on_event(&mut self, event: Event) -> EventResult {
|
2018-02-08 00:25:00 +00:00
|
|
|
if event == Event::WindowResize {
|
|
|
|
self.bg_dirty.set(true);
|
|
|
|
}
|
2017-10-11 18:35:18 +00:00
|
|
|
// Use the stack position iterator to get the offset of the top layer.
|
|
|
|
// TODO: save it instead when drawing?
|
|
|
|
match StackPositionIterator::new(
|
|
|
|
self.layers.iter_mut(),
|
|
|
|
self.last_size,
|
2019-01-24 19:57:30 +00:00
|
|
|
)
|
|
|
|
.last()
|
2017-10-11 18:35:18 +00:00
|
|
|
{
|
2015-05-15 01:38:58 +00:00
|
|
|
None => EventResult::Ignored,
|
2017-10-11 18:35:18 +00:00
|
|
|
Some((v, offset)) => v.view.on_event(event.relativized(offset)),
|
2015-05-15 23:06:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn layout(&mut self, size: Vec2) {
|
2016-07-20 07:30:00 +00:00
|
|
|
self.last_size = size;
|
|
|
|
|
2016-07-02 02:19:43 +00:00
|
|
|
// The call has been made, we can't ask for more space anymore.
|
|
|
|
// Let's make do with what we have.
|
|
|
|
|
2016-06-28 05:40:11 +00:00
|
|
|
for layer in &mut self.layers {
|
2016-07-02 02:19:43 +00:00
|
|
|
// Give each guy what he asks for, within the budget constraints.
|
2017-01-24 06:52:29 +00:00
|
|
|
let size = Vec2::min(size, layer.view.required_size(size));
|
2016-10-02 22:33:55 +00:00
|
|
|
layer.size = size;
|
2015-05-15 23:06:48 +00:00
|
|
|
layer.view.layout(layer.size);
|
2016-07-02 02:19:43 +00:00
|
|
|
|
2017-01-24 00:51:48 +00:00
|
|
|
// We need to call `layout()` on the view before giving it focus
|
|
|
|
// for the first time. Otherwise it will not be properly set up.
|
|
|
|
// Ex: examples/lorem.rs: the text view takes focus because it's
|
|
|
|
// scrolling, but it only knows that after a call to `layout()`.
|
2015-05-31 04:53:25 +00:00
|
|
|
if layer.virgin {
|
2016-07-15 03:27:15 +00:00
|
|
|
layer.view.take_focus(Direction::none());
|
2015-05-31 04:53:25 +00:00
|
|
|
layer.virgin = false;
|
|
|
|
}
|
2015-05-15 01:38:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-24 06:52:29 +00:00
|
|
|
fn required_size(&mut self, size: Vec2) -> Vec2 {
|
2015-05-15 01:38:58 +00:00
|
|
|
// The min size is the max of all children's
|
|
|
|
|
2016-07-02 07:47:38 +00:00
|
|
|
self.layers
|
2016-07-10 01:23:58 +00:00
|
|
|
.iter_mut()
|
2017-01-24 06:52:29 +00:00
|
|
|
.map(|layer| layer.view.required_size(size))
|
2016-07-02 07:47:38 +00:00
|
|
|
.fold(Vec2::new(1, 1), Vec2::max)
|
2015-05-15 01:38:58 +00:00
|
|
|
}
|
2015-05-19 22:54:11 +00:00
|
|
|
|
2016-07-15 03:27:15 +00:00
|
|
|
fn take_focus(&mut self, source: Direction) -> bool {
|
2015-05-19 22:54:11 +00:00
|
|
|
match self.layers.last_mut() {
|
|
|
|
None => false,
|
2017-08-14 22:13:32 +00:00
|
|
|
Some(v) => v.view.take_focus(source),
|
2015-05-19 22:54:11 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-23 17:33:29 +00:00
|
|
|
|
2017-10-11 18:35:18 +00:00
|
|
|
fn call_on_any<'a>(
|
2019-07-30 23:08:05 +00:00
|
|
|
&mut self,
|
|
|
|
selector: &Selector<'_>,
|
2019-09-06 23:02:20 +00:00
|
|
|
callback: AnyCb<'a>,
|
2017-10-11 18:35:18 +00:00
|
|
|
) {
|
2017-02-07 02:18:17 +00:00
|
|
|
for layer in &mut self.layers {
|
2019-09-06 23:02:20 +00:00
|
|
|
layer.view.call_on_any(selector, callback);
|
2017-02-07 02:18:17 +00:00
|
|
|
}
|
2015-05-23 17:33:29 +00:00
|
|
|
}
|
2017-03-25 21:50:52 +00:00
|
|
|
|
2019-02-28 23:55:02 +00:00
|
|
|
fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
|
2017-03-25 21:50:52 +00:00
|
|
|
for layer in &mut self.layers {
|
|
|
|
if layer.view.focus_view(selector).is_ok() {
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Err(())
|
|
|
|
}
|
2015-05-15 00:41:17 +00:00
|
|
|
}
|
2018-03-06 02:47:25 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2019-02-28 23:54:12 +00:00
|
|
|
use crate::views::TextView;
|
2018-03-06 02:47:25 +00:00
|
|
|
|
2018-03-14 21:59:41 +00:00
|
|
|
#[test]
|
|
|
|
fn pop_add() {
|
2018-03-14 22:19:56 +00:00
|
|
|
// Start with a simple stack
|
|
|
|
let mut stack = StackView::new().layer(TextView::new("1"));
|
2018-03-14 21:59:41 +00:00
|
|
|
|
2018-03-14 22:19:56 +00:00
|
|
|
// And keep poping and re-pushing the view
|
2018-03-14 21:59:41 +00:00
|
|
|
for _ in 0..20 {
|
|
|
|
let layer = stack.pop_layer().unwrap();
|
|
|
|
stack.add_layer(layer);
|
|
|
|
}
|
|
|
|
|
2018-03-14 22:19:56 +00:00
|
|
|
// We want to make sure we don't add any layer of Box'ing
|
2018-03-14 21:59:41 +00:00
|
|
|
let layer = stack.pop_layer().unwrap();
|
|
|
|
let text: Box<TextView> = layer.as_boxed_any().downcast().unwrap();
|
2018-03-14 22:19:56 +00:00
|
|
|
|
2018-03-14 21:59:41 +00:00
|
|
|
assert_eq!(text.get_content().source(), "1");
|
|
|
|
}
|
|
|
|
|
2018-03-06 02:47:25 +00:00
|
|
|
#[test]
|
|
|
|
fn move_layer_works() {
|
|
|
|
let mut stack = StackView::new()
|
|
|
|
.layer(TextView::new("1"))
|
|
|
|
.layer(TextView::new("2"))
|
2018-03-14 22:19:56 +00:00
|
|
|
.layer(TextView::new("3"))
|
|
|
|
.layer(TextView::new("4"));
|
2018-03-06 02:47:25 +00:00
|
|
|
|
2018-03-14 22:19:56 +00:00
|
|
|
// Try moving views around, make sure we have the expected result
|
|
|
|
|
|
|
|
// 1,2,3,4
|
2018-03-11 23:51:28 +00:00
|
|
|
stack.move_layer(
|
|
|
|
LayerPosition::FromFront(0),
|
|
|
|
LayerPosition::FromBack(0),
|
|
|
|
);
|
2018-03-14 22:19:56 +00:00
|
|
|
|
|
|
|
// 4,1,2,3
|
2018-03-11 23:51:28 +00:00
|
|
|
stack.move_layer(
|
|
|
|
LayerPosition::FromBack(0),
|
|
|
|
LayerPosition::FromFront(0),
|
|
|
|
);
|
2018-03-14 22:19:56 +00:00
|
|
|
// 1,2,3,4
|
2018-03-11 23:51:28 +00:00
|
|
|
stack.move_layer(
|
|
|
|
LayerPosition::FromFront(1),
|
|
|
|
LayerPosition::FromFront(0),
|
|
|
|
);
|
2018-03-14 22:19:56 +00:00
|
|
|
// 1,2,4,3
|
|
|
|
|
|
|
|
let layer = stack.pop_layer().unwrap();
|
|
|
|
let text: Box<TextView> = layer.as_boxed_any().downcast().unwrap();
|
|
|
|
assert_eq!(text.get_content().source(), "3");
|
|
|
|
|
|
|
|
let layer = stack.pop_layer().unwrap();
|
|
|
|
let text: Box<TextView> = layer.as_boxed_any().downcast().unwrap();
|
|
|
|
assert_eq!(text.get_content().source(), "4");
|
2018-03-06 02:47:25 +00:00
|
|
|
|
|
|
|
let layer = stack.pop_layer().unwrap();
|
2018-03-14 18:18:28 +00:00
|
|
|
let text: Box<TextView> = layer.as_boxed_any().downcast().unwrap();
|
|
|
|
assert_eq!(text.get_content().source(), "2");
|
2018-03-14 22:19:56 +00:00
|
|
|
|
|
|
|
let layer = stack.pop_layer().unwrap();
|
|
|
|
let text: Box<TextView> = layer.as_boxed_any().downcast().unwrap();
|
|
|
|
assert_eq!(text.get_content().source(), "1");
|
|
|
|
|
|
|
|
assert!(stack.pop_layer().is_none());
|
2018-03-06 02:47:25 +00:00
|
|
|
}
|
2018-05-29 22:27:33 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn get() {
|
|
|
|
let mut stack = StackView::new()
|
|
|
|
.layer(TextView::new("1"))
|
|
|
|
.layer(TextView::new("2"));
|
|
|
|
|
2019-01-24 19:57:30 +00:00
|
|
|
assert!(stack
|
|
|
|
.get(LayerPosition::FromFront(0))
|
|
|
|
.unwrap()
|
|
|
|
.is::<TextView>());
|
|
|
|
assert!(stack
|
|
|
|
.get(LayerPosition::FromBack(0))
|
|
|
|
.unwrap()
|
|
|
|
.is::<TextView>());
|
|
|
|
assert!(stack
|
|
|
|
.get_mut(LayerPosition::FromFront(0))
|
|
|
|
.unwrap()
|
|
|
|
.is::<TextView>());
|
|
|
|
assert!(stack
|
|
|
|
.get_mut(LayerPosition::FromBack(0))
|
|
|
|
.unwrap()
|
|
|
|
.is::<TextView>());
|
2018-05-29 22:27:33 +00:00
|
|
|
}
|
2018-03-06 02:47:25 +00:00
|
|
|
}
|