TabsState

Struct TabsState 

Source
pub struct TabsState<T: ToString + Default + Copy> { /* private fields */ }

Implementations§

Source§

impl<T: ToString + Default + Copy> TabsState<T>

Source

pub fn new(possible_tabs: Vec<T>) -> Self

Examples found in repository?
examples/basic.rs (lines 67-71)
65    fn new() -> Self {
66        Self {
67            tabs_state: TabsState::new(vec![
68                CurrentTab::Main,
69                CurrentTab::Settings,
70                CurrentTab::About,
71            ]),
72        }
73    }
Source§

impl<T: ToString + Default + Copy> TabsState<T>

Source

pub fn next(&mut self)

Examples found in repository?
examples/basic.rs (line 84)
75    fn run(mut self, terminal: &mut Terminal<CrosstermBackend<Stdout>>) -> io::Result<()> {
76        loop {
77            terminal.draw(|frame| frame.render_widget(&mut self, frame.area()))?;
78
79            if event::poll(Duration::from_millis(10))? {
80                if let Event::Key(key) = event::read()? {
81                    match key.code {
82                        KeyCode::Char('q') => break,
83                        KeyCode::Char('h') => self.tabs_state.prev(),
84                        KeyCode::Char('l') => self.tabs_state.next(),
85                        KeyCode::Char('1') => self.tabs_state.set(1),
86                        KeyCode::Char('2') => self.tabs_state.set(2),
87                        KeyCode::Char('3') => self.tabs_state.set(3),
88                        _ => (),
89                    }
90                }
91            }
92        }
93
94        Ok(())
95    }
Source

pub fn prev(&mut self)

Examples found in repository?
examples/basic.rs (line 83)
75    fn run(mut self, terminal: &mut Terminal<CrosstermBackend<Stdout>>) -> io::Result<()> {
76        loop {
77            terminal.draw(|frame| frame.render_widget(&mut self, frame.area()))?;
78
79            if event::poll(Duration::from_millis(10))? {
80                if let Event::Key(key) = event::read()? {
81                    match key.code {
82                        KeyCode::Char('q') => break,
83                        KeyCode::Char('h') => self.tabs_state.prev(),
84                        KeyCode::Char('l') => self.tabs_state.next(),
85                        KeyCode::Char('1') => self.tabs_state.set(1),
86                        KeyCode::Char('2') => self.tabs_state.set(2),
87                        KeyCode::Char('3') => self.tabs_state.set(3),
88                        _ => (),
89                    }
90                }
91            }
92        }
93
94        Ok(())
95    }
Source

pub fn set(&mut self, idx: usize)

Examples found in repository?
examples/basic.rs (line 85)
75    fn run(mut self, terminal: &mut Terminal<CrosstermBackend<Stdout>>) -> io::Result<()> {
76        loop {
77            terminal.draw(|frame| frame.render_widget(&mut self, frame.area()))?;
78
79            if event::poll(Duration::from_millis(10))? {
80                if let Event::Key(key) = event::read()? {
81                    match key.code {
82                        KeyCode::Char('q') => break,
83                        KeyCode::Char('h') => self.tabs_state.prev(),
84                        KeyCode::Char('l') => self.tabs_state.next(),
85                        KeyCode::Char('1') => self.tabs_state.set(1),
86                        KeyCode::Char('2') => self.tabs_state.set(2),
87                        KeyCode::Char('3') => self.tabs_state.set(3),
88                        _ => (),
89                    }
90                }
91            }
92        }
93
94        Ok(())
95    }
Source

pub fn current(&self) -> T

Auto Trait Implementations§

§

impl<T> Freeze for TabsState<T>

§

impl<T> RefUnwindSafe for TabsState<T>
where T: RefUnwindSafe,

§

impl<T> Send for TabsState<T>
where T: Send,

§

impl<T> Sync for TabsState<T>
where T: Sync,

§

impl<T> Unpin for TabsState<T>
where T: Unpin,

§

impl<T> UnwindSafe for TabsState<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.