pub struct TabPanel { /* private fields */ }
Expand description
The TabPanel
is an ease of use wrapper around a TabView
and its TabBar
.
Additionally the TabBar in the Panel can be horizontally aligned, by default it is set to be left aligned.
§Example
use cursive_tabs::{Align, TabPanel};
use cursive::views::TextView;
use cursive::view::Nameable;
let mut tabs = TabPanel::new()
.with_tab(TextView::new("First").with_name("First"))
.with_tab(TextView::new("Second").with_name("Second"))
.with_bar_alignment(Align::Center);
A TabView is also usable separately, so if you prefer the tabs without the TabBar and Panel around have a look at TabView
.
Implementations§
Source§impl TabPanel
impl TabPanel
Sourcepub fn new() -> Self
pub fn new() -> Self
Returns a new instance of a TabPanel.
Alignment is set by default to left, to change this use set_bar_alignment
to change to any other HAlign
provided by cursive
.
Sourcepub fn active_tab(&self) -> Option<&str>
pub fn active_tab(&self) -> Option<&str>
Returns the current active tab of the TabView
.
Note: Calls active_tab
on the enclosed TabView
.
Sourcepub fn active_view(&self) -> Option<&dyn View>
pub fn active_view(&self) -> Option<&dyn View>
Returns a reference to the underlying view.
Sourcepub fn active_view_mut(&mut self) -> Option<&mut dyn View>
pub fn active_view_mut(&mut self) -> Option<&mut dyn View>
Returns a mutable reference to the underlying view.
pub fn views(&self) -> Vec<&dyn View>
pub fn views_mut(&mut self) -> Vec<&mut dyn View>
Sourcepub fn set_active_tab(&mut self, id: &str) -> Result<(), IdNotFound>
pub fn set_active_tab(&mut self, id: &str) -> Result<(), IdNotFound>
Non-consuming variant to set the active tab in the TabView
.
Note: Calls set_active_tab
on the enclosed TabView
.
Sourcepub fn with_active_tab(self, id: &str) -> Result<Self, Self>
pub fn with_active_tab(self, id: &str) -> Result<Self, Self>
Consuming & Chainable variant to set the active tab in the TabView
.
Note: Calls set_active_tab
on the enclosed TabView
.
Sourcepub fn add_tab<T: View>(&mut self, view: NamedView<T>)
pub fn add_tab<T: View>(&mut self, view: NamedView<T>)
Non-consuming variant to add new tabs to the TabView
.
Note: Calls add_tab
on the enclosed TabView
.
Sourcepub fn with_tab<T: View>(self, view: NamedView<T>) -> Self
pub fn with_tab<T: View>(self, view: NamedView<T>) -> Self
Consuming & Chainable variant to add a new tab.
Note: Calls add_tab
on the enclosed TabView
.
Sourcepub fn swap_tabs(&mut self, fst: &str, snd: &str)
pub fn swap_tabs(&mut self, fst: &str, snd: &str)
Swaps the given tab keys. If at least one of them cannot be found then no operation is performed
Sourcepub fn add_tab_at<T: View>(&mut self, view: NamedView<T>, pos: usize)
pub fn add_tab_at<T: View>(&mut self, view: NamedView<T>, pos: usize)
Non-consuming variant to add new tabs to the TabView
at a certain position.
It is fail-safe, if the postion is greater than the amount of tabs, it is appended to the end.
Note: Calls add_tab_at
on the enclosed TabView
.
Sourcepub fn with_tab_at<T: View>(self, view: NamedView<T>, pos: usize) -> Self
pub fn with_tab_at<T: View>(self, view: NamedView<T>, pos: usize) -> Self
Consuming & Chainable variant to add a new tab at a certain position.
It is fail-safe, if the postion is greater than the amount of tabs, it is appended to the end.
Note: Calls add_tab_at
on the enclosed TabView
.
Sourcepub fn remove_tab(&mut self, id: &str) -> Result<(), IdNotFound>
pub fn remove_tab(&mut self, id: &str) -> Result<(), IdNotFound>
Remove a tab of the enclosed TabView
.
Sourcepub fn with_bar_alignment(self, align: Align) -> Self
pub fn with_bar_alignment(self, align: Align) -> Self
Consumable & Chainable variant to set the bar alignment.
Sourcepub fn set_bar_alignment(&mut self, align: Align)
pub fn set_bar_alignment(&mut self, align: Align)
Non-consuming variant to set the bar alignment.
pub fn with_bar_placement(self, placement: Placement) -> Self
pub fn set_bar_placement(&mut self, placement: Placement)
Trait Implementations§
Source§impl View for TabPanel
impl View for TabPanel
Source§fn draw(&self, printer: &Printer<'_, '_>)
fn draw(&self, printer: &Printer<'_, '_>)
Source§fn layout(&mut self, vec: Vec2)
fn layout(&mut self, vec: Vec2)
Source§fn needs_relayout(&self) -> bool
fn needs_relayout(&self) -> bool
Source§fn required_size(&mut self, cst: Vec2) -> Vec2
fn required_size(&mut self, cst: Vec2) -> Vec2
Source§fn on_event(&mut self, evt: Event) -> EventResult
fn on_event(&mut self, evt: Event) -> EventResult
Source§fn take_focus(&mut self, d: Direction) -> Result<EventResult, CannotFocus>
fn take_focus(&mut self, d: Direction) -> Result<EventResult, CannotFocus>
Source§fn focus_view(
&mut self,
slt: &Selector<'_>,
) -> Result<EventResult, ViewNotFound>
fn focus_view( &mut self, slt: &Selector<'_>, ) -> Result<EventResult, ViewNotFound>
Source§fn call_on_any<'a>(&mut self, slt: &Selector<'_>, cb: AnyCb<'a>)
fn call_on_any<'a>(&mut self, slt: &Selector<'_>, cb: AnyCb<'a>)
Auto Trait Implementations§
impl Freeze for TabPanel
impl !RefUnwindSafe for TabPanel
impl Send for TabPanel
impl Sync for TabPanel
impl Unpin for TabPanel
impl !UnwindSafe for TabPanel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Finder for Twhere
T: View,
impl<T> Finder for Twhere
T: View,
Source§fn call_on_all<V, F>(&mut self, sel: &Selector<'_>, callback: F)
fn call_on_all<V, F>(&mut self, sel: &Selector<'_>, callback: F)
sel
. Read moreSource§fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>
fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>
sel
. Read moreSource§fn call_on_name<V, F, R>(&mut self, name: &str, callback: F) -> Option<R>
fn call_on_name<V, F, R>(&mut self, name: &str, callback: F) -> Option<R>
call_on
with a view::Selector::Name
.Source§impl<T> IntoBoxedView for Twhere
T: View,
impl<T> IntoBoxedView for Twhere
T: View,
Source§fn into_boxed_view(self) -> Box<dyn View>
fn into_boxed_view(self) -> Box<dyn View>
Box<View>
.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Resizable for Twhere
T: View,
impl<T> Resizable for Twhere
T: View,
Source§fn resized(
self,
width: SizeConstraint,
height: SizeConstraint,
) -> ResizedView<Self>
fn resized( self, width: SizeConstraint, height: SizeConstraint, ) -> ResizedView<Self>
self
in a ResizedView
with the given size constraints.Source§fn fixed_size<S>(self, size: S) -> ResizedView<Self>
fn fixed_size<S>(self, size: S) -> ResizedView<Self>
self
into a fixed-size ResizedView
.Source§fn fixed_width(self, width: usize) -> ResizedView<Self>
fn fixed_width(self, width: usize) -> ResizedView<Self>
self
into a fixed-width ResizedView
.Source§fn fixed_height(self, height: usize) -> ResizedView<Self>
fn fixed_height(self, height: usize) -> ResizedView<Self>
self
into a fixed-width ResizedView
.Source§fn full_screen(self) -> ResizedView<Self>
fn full_screen(self) -> ResizedView<Self>
self
into a full-screen ResizedView
.Source§fn full_width(self) -> ResizedView<Self>
fn full_width(self) -> ResizedView<Self>
self
into a full-width ResizedView
.Source§fn full_height(self) -> ResizedView<Self>
fn full_height(self) -> ResizedView<Self>
self
into a full-height ResizedView
.Source§fn max_size<S>(self, size: S) -> ResizedView<Self>
fn max_size<S>(self, size: S) -> ResizedView<Self>
self
into a limited-size ResizedView
.Source§fn max_width(self, max_width: usize) -> ResizedView<Self>
fn max_width(self, max_width: usize) -> ResizedView<Self>
self
into a limited-width ResizedView
.Source§fn max_height(self, max_height: usize) -> ResizedView<Self>
fn max_height(self, max_height: usize) -> ResizedView<Self>
self
into a limited-height ResizedView
.Source§fn min_size<S>(self, size: S) -> ResizedView<Self>
fn min_size<S>(self, size: S) -> ResizedView<Self>
self
into a ResizedView
at least sized size
.Source§fn min_width(self, min_width: usize) -> ResizedView<Self>
fn min_width(self, min_width: usize) -> ResizedView<Self>
self
in a ResizedView
at least min_width
wide.Source§fn min_height(self, min_height: usize) -> ResizedView<Self>
fn min_height(self, min_height: usize) -> ResizedView<Self>
self
in a ResizedView
at least min_height
tall.Source§impl<T> Scrollable for Twhere
T: View,
impl<T> Scrollable for Twhere
T: View,
Source§fn scrollable(self) -> ScrollView<Self>
fn scrollable(self) -> ScrollView<Self>
self
in a ScrollView
.