From 2643ecbb1562e93bd9ee1ba8de107b7053c848c6 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Mon, 3 Apr 2017 10:41:18 -0700 Subject: [PATCH] Add chainable methods for `StackView` --- src/views/stack_view.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/views/stack_view.rs b/src/views/stack_view.rs index f48463e..264b8ae 100644 --- a/src/views/stack_view.rs +++ b/src/views/stack_view.rs @@ -1,5 +1,6 @@ use Printer; +use ::With; use direction::Direction; use event::{Event, EventResult}; use std::any::Any; @@ -79,6 +80,24 @@ impl StackView { self.add_layer_at(Position::center(), view); } + /// Adds new view on top of the stack in the center of the screen. + /// + /// Chainable variant. + pub fn layer(self, view: T) -> Self + where T: 'static + View + { + self.with(|s| s.add_layer(view)) + } + + /// Adds a new full-screen layer on top of the stack. + /// + /// Chainable variant. + pub fn fullscreen_layer(self, view: T) -> Self + where T: 'static + View + { + self.with(|s| s.add_fullscreen_layer(view)) + } + /// Adds a view on top of the stack. pub fn add_layer_at(&mut self, position: Position, view: T) where T: 'static + View @@ -94,6 +113,15 @@ impl StackView { }); } + /// Adds a view on top of the stack. + /// + /// Chainable variant. + pub fn layer_at(self, position: Position, view: T) -> Self + where T: 'static + View + { + self.with(|s| s.add_layer_at(position, view)) + } + /// Remove the top-most layer. pub fn pop_layer(&mut self) { self.layers.pop();