Struct Textbox

Source
pub struct Textbox { /* private fields */ }

Implementations§

Source§

impl Textbox

Source

pub fn bg(self, bg: Color) -> Self

Defines background color of textbox

Examples found in repository?
examples/demo.rs (line 40)
14    pub fn ui(&mut self, f: &mut Frame) {
15        let size = f.area();
16
17        let vertical_chunks = Layout::default()
18            .direction(Direction::Vertical)
19            .constraints([Constraint::Length(3), Constraint::Length(3), Constraint::Percentage(100)])
20            .split(size);
21
22        let block1 = Block::default().borders(Borders::ALL).title(format!("Use <TAB> to switch active textbox, <ESC> to exit demo"));
23        f.render_widget(block1, vertical_chunks[0]);
24
25        let textbox = Textbox::default()
26            .render_cursor(self.focused_textbox == 0);
27        let textbox_rect = Rect {
28            x: 1,
29            y: 1,
30            width: 15,
31            height: 1,
32        };
33        f.render_stateful_widget(textbox, textbox_rect, &mut self.textbox_state);
34
35        let block2 = Block::default().borders(Borders::ALL);
36        f.render_widget(block2, vertical_chunks[1]);
37
38        let textbox2 = Textbox::default()
39            .fg(ratatui::style::Color::Yellow)
40            .bg(ratatui::style::Color::Green)
41            .hint_color(ratatui::style::Color::LightGreen)
42            .cursor_color(ratatui::style::Color::DarkGray)
43            .render_cursor(self.focused_textbox == 1);
44        f.render_stateful_widget(textbox2, vertical_chunks[1].inner(ratatui::layout::Margin::new(1, 1)), &mut self.textbox2_state);
45    }
Source

pub fn fg(self, fg: Color) -> Self

Defines foreground color (text color) of textbox

Examples found in repository?
examples/demo.rs (line 39)
14    pub fn ui(&mut self, f: &mut Frame) {
15        let size = f.area();
16
17        let vertical_chunks = Layout::default()
18            .direction(Direction::Vertical)
19            .constraints([Constraint::Length(3), Constraint::Length(3), Constraint::Percentage(100)])
20            .split(size);
21
22        let block1 = Block::default().borders(Borders::ALL).title(format!("Use <TAB> to switch active textbox, <ESC> to exit demo"));
23        f.render_widget(block1, vertical_chunks[0]);
24
25        let textbox = Textbox::default()
26            .render_cursor(self.focused_textbox == 0);
27        let textbox_rect = Rect {
28            x: 1,
29            y: 1,
30            width: 15,
31            height: 1,
32        };
33        f.render_stateful_widget(textbox, textbox_rect, &mut self.textbox_state);
34
35        let block2 = Block::default().borders(Borders::ALL);
36        f.render_widget(block2, vertical_chunks[1]);
37
38        let textbox2 = Textbox::default()
39            .fg(ratatui::style::Color::Yellow)
40            .bg(ratatui::style::Color::Green)
41            .hint_color(ratatui::style::Color::LightGreen)
42            .cursor_color(ratatui::style::Color::DarkGray)
43            .render_cursor(self.focused_textbox == 1);
44        f.render_stateful_widget(textbox2, vertical_chunks[1].inner(ratatui::layout::Margin::new(1, 1)), &mut self.textbox2_state);
45    }
Source

pub fn hint_color(self, hint: Color) -> Self

Defines the color of hint_text

Examples found in repository?
examples/demo.rs (line 41)
14    pub fn ui(&mut self, f: &mut Frame) {
15        let size = f.area();
16
17        let vertical_chunks = Layout::default()
18            .direction(Direction::Vertical)
19            .constraints([Constraint::Length(3), Constraint::Length(3), Constraint::Percentage(100)])
20            .split(size);
21
22        let block1 = Block::default().borders(Borders::ALL).title(format!("Use <TAB> to switch active textbox, <ESC> to exit demo"));
23        f.render_widget(block1, vertical_chunks[0]);
24
25        let textbox = Textbox::default()
26            .render_cursor(self.focused_textbox == 0);
27        let textbox_rect = Rect {
28            x: 1,
29            y: 1,
30            width: 15,
31            height: 1,
32        };
33        f.render_stateful_widget(textbox, textbox_rect, &mut self.textbox_state);
34
35        let block2 = Block::default().borders(Borders::ALL);
36        f.render_widget(block2, vertical_chunks[1]);
37
38        let textbox2 = Textbox::default()
39            .fg(ratatui::style::Color::Yellow)
40            .bg(ratatui::style::Color::Green)
41            .hint_color(ratatui::style::Color::LightGreen)
42            .cursor_color(ratatui::style::Color::DarkGray)
43            .render_cursor(self.focused_textbox == 1);
44        f.render_stateful_widget(textbox2, vertical_chunks[1].inner(ratatui::layout::Margin::new(1, 1)), &mut self.textbox2_state);
45    }
Source

pub fn cursor_color(self, cursor: Color) -> Self

Defines the color of cursor

Examples found in repository?
examples/demo.rs (line 42)
14    pub fn ui(&mut self, f: &mut Frame) {
15        let size = f.area();
16
17        let vertical_chunks = Layout::default()
18            .direction(Direction::Vertical)
19            .constraints([Constraint::Length(3), Constraint::Length(3), Constraint::Percentage(100)])
20            .split(size);
21
22        let block1 = Block::default().borders(Borders::ALL).title(format!("Use <TAB> to switch active textbox, <ESC> to exit demo"));
23        f.render_widget(block1, vertical_chunks[0]);
24
25        let textbox = Textbox::default()
26            .render_cursor(self.focused_textbox == 0);
27        let textbox_rect = Rect {
28            x: 1,
29            y: 1,
30            width: 15,
31            height: 1,
32        };
33        f.render_stateful_widget(textbox, textbox_rect, &mut self.textbox_state);
34
35        let block2 = Block::default().borders(Borders::ALL);
36        f.render_widget(block2, vertical_chunks[1]);
37
38        let textbox2 = Textbox::default()
39            .fg(ratatui::style::Color::Yellow)
40            .bg(ratatui::style::Color::Green)
41            .hint_color(ratatui::style::Color::LightGreen)
42            .cursor_color(ratatui::style::Color::DarkGray)
43            .render_cursor(self.focused_textbox == 1);
44        f.render_stateful_widget(textbox2, vertical_chunks[1].inner(ratatui::layout::Margin::new(1, 1)), &mut self.textbox2_state);
45    }
Source

pub fn render_cursor(self, render: bool) -> Self

Defines the visibility of cursor

Examples found in repository?
examples/demo.rs (line 26)
14    pub fn ui(&mut self, f: &mut Frame) {
15        let size = f.area();
16
17        let vertical_chunks = Layout::default()
18            .direction(Direction::Vertical)
19            .constraints([Constraint::Length(3), Constraint::Length(3), Constraint::Percentage(100)])
20            .split(size);
21
22        let block1 = Block::default().borders(Borders::ALL).title(format!("Use <TAB> to switch active textbox, <ESC> to exit demo"));
23        f.render_widget(block1, vertical_chunks[0]);
24
25        let textbox = Textbox::default()
26            .render_cursor(self.focused_textbox == 0);
27        let textbox_rect = Rect {
28            x: 1,
29            y: 1,
30            width: 15,
31            height: 1,
32        };
33        f.render_stateful_widget(textbox, textbox_rect, &mut self.textbox_state);
34
35        let block2 = Block::default().borders(Borders::ALL);
36        f.render_widget(block2, vertical_chunks[1]);
37
38        let textbox2 = Textbox::default()
39            .fg(ratatui::style::Color::Yellow)
40            .bg(ratatui::style::Color::Green)
41            .hint_color(ratatui::style::Color::LightGreen)
42            .cursor_color(ratatui::style::Color::DarkGray)
43            .render_cursor(self.focused_textbox == 1);
44        f.render_stateful_widget(textbox2, vertical_chunks[1].inner(ratatui::layout::Margin::new(1, 1)), &mut self.textbox2_state);
45    }

Trait Implementations§

Source§

impl Default for Textbox

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl StatefulWidget for Textbox

Source§

type State = TextboxState

State associated with the stateful widget. Read more
Source§

fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom stateful widget.

Auto Trait Implementations§

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.