View

Struct View 

Source
pub struct View {
    pub label: String,
    pub widgets: Vec<WidgetType>,
}

Fields§

§label: String§widgets: Vec<WidgetType>

Implementations§

Source§

impl View

Source

pub fn new(label: &str) -> Self

Examples found in repository?
examples/input.rs (line 4)
3fn main() -> std::io::Result<()> {
4    let mut view = View::new("User Information");
5
6    view.add(Input::new("Username", "Enter your name"));
7    view.add(Input::new("Email", "you@example.com"));
8
9    let selected = view.run()?;
10
11    println!("Collected values:");
12    for value in selected {
13        println!("{}", value);
14    }
15
16    Ok(())
17}
More examples
Hide additional examples
examples/basic.rs (line 4)
3fn main() -> std::io::Result<()> {
4    let mut view = View::new("Demo UI");
5
6    view.add(Label::new("Text Label"));
7    view.add(Slider::new("Slider", 0, 100, 50));
8    view.add(Label::new("Checkboxes         "));
9    view.add(Checkbox::new("Checkbox 1"));
10    view.add(Checkbox::new("Checkbox 2"));
11    view.add(Checkbox::new("Checkbox 3"));
12    view.add(Button::new("Submit"));
13    view.add(Input::new("Text Input", "Type here..."));
14    view.add(Label::new(
15        "Press TAB to switch, SPACE to toggle, ESC to exit",
16    ));
17
18    run(view)?;
19    Ok(())
20}
examples/options.rs (line 4)
3fn main() -> std::io::Result<()> {
4    let mut view = View::new("Ice Cream Selector");
5
6    view.add(Label::new("Choose your ice cream flavours:"));
7    view.add(Checkbox::new("Vanilla"));
8    view.add(Checkbox::new("Chocolate"));
9    view.add(Checkbox::new("Strawberry"));
10    view.add(Checkbox::new("Mint"));
11    view.add(Checkbox::new("Cookie Dough"));
12    view.add(Label::new(
13        "Press TAB to switch, SPACE to toggle, ESC to finish",
14    ));
15
16    let result = run(view)?;
17
18    println!("\nYour ice cream will include:");
19    for ingredient in result {
20        println!("- {}", ingredient);
21    }
22
23    Ok(())
24}
examples/views.rs (line 4)
3fn main() -> std::io::Result<()> {
4    let mut main_view = View::new("Level 1");
5    main_view.add(Checkbox::new("Option 1"));
6    main_view.add(Checkbox::new("Action 1"));
7    // Create first view
8    let mut view1 = View::new("Level 2");
9    view1.add(Checkbox::new("Option 2"));
10    view1.add(Checkbox::new("Action 2"));
11    view1.add(Slider::new("Slider", 0, 100, 50));
12    main_view.add(view1);
13
14    // Create second view
15    let mut view2 = View::new("Level 3");
16    view2.add(Label::new("Label"));
17    view2.add(Checkbox::new("Option 3"));
18    view2.add(Slider::new("Slider", 0, 100, 50));
19    view2.add(Checkbox::new("Action 3"));
20    main_view.add(view2);
21
22    run(main_view)?;
23
24    Ok(())
25}
Source

pub fn add(&mut self, widget: impl Into<WidgetType>)

Examples found in repository?
examples/input.rs (line 6)
3fn main() -> std::io::Result<()> {
4    let mut view = View::new("User Information");
5
6    view.add(Input::new("Username", "Enter your name"));
7    view.add(Input::new("Email", "you@example.com"));
8
9    let selected = view.run()?;
10
11    println!("Collected values:");
12    for value in selected {
13        println!("{}", value);
14    }
15
16    Ok(())
17}
More examples
Hide additional examples
examples/basic.rs (line 6)
3fn main() -> std::io::Result<()> {
4    let mut view = View::new("Demo UI");
5
6    view.add(Label::new("Text Label"));
7    view.add(Slider::new("Slider", 0, 100, 50));
8    view.add(Label::new("Checkboxes         "));
9    view.add(Checkbox::new("Checkbox 1"));
10    view.add(Checkbox::new("Checkbox 2"));
11    view.add(Checkbox::new("Checkbox 3"));
12    view.add(Button::new("Submit"));
13    view.add(Input::new("Text Input", "Type here..."));
14    view.add(Label::new(
15        "Press TAB to switch, SPACE to toggle, ESC to exit",
16    ));
17
18    run(view)?;
19    Ok(())
20}
examples/options.rs (line 6)
3fn main() -> std::io::Result<()> {
4    let mut view = View::new("Ice Cream Selector");
5
6    view.add(Label::new("Choose your ice cream flavours:"));
7    view.add(Checkbox::new("Vanilla"));
8    view.add(Checkbox::new("Chocolate"));
9    view.add(Checkbox::new("Strawberry"));
10    view.add(Checkbox::new("Mint"));
11    view.add(Checkbox::new("Cookie Dough"));
12    view.add(Label::new(
13        "Press TAB to switch, SPACE to toggle, ESC to finish",
14    ));
15
16    let result = run(view)?;
17
18    println!("\nYour ice cream will include:");
19    for ingredient in result {
20        println!("- {}", ingredient);
21    }
22
23    Ok(())
24}
examples/views.rs (line 5)
3fn main() -> std::io::Result<()> {
4    let mut main_view = View::new("Level 1");
5    main_view.add(Checkbox::new("Option 1"));
6    main_view.add(Checkbox::new("Action 1"));
7    // Create first view
8    let mut view1 = View::new("Level 2");
9    view1.add(Checkbox::new("Option 2"));
10    view1.add(Checkbox::new("Action 2"));
11    view1.add(Slider::new("Slider", 0, 100, 50));
12    main_view.add(view1);
13
14    // Create second view
15    let mut view2 = View::new("Level 3");
16    view2.add(Label::new("Label"));
17    view2.add(Checkbox::new("Option 3"));
18    view2.add(Slider::new("Slider", 0, 100, 50));
19    view2.add(Checkbox::new("Action 3"));
20    main_view.add(view2);
21
22    run(main_view)?;
23
24    Ok(())
25}
Source

pub fn flatten_focusable(&mut self) -> Vec<&mut WidgetType>

Source

pub fn handle_event(&mut self, event: &Event, focus_index: usize)

Source

pub fn render( &self, indent: usize, global_focus_index: usize, focusable_index: &mut usize, current_y: &mut u16, ) -> String

Source

pub fn get_values(&self) -> Vec<(String, WidgetValue)>

Source

pub fn run(&mut self) -> Result<Vec<String>>

Examples found in repository?
examples/input.rs (line 9)
3fn main() -> std::io::Result<()> {
4    let mut view = View::new("User Information");
5
6    view.add(Input::new("Username", "Enter your name"));
7    view.add(Input::new("Email", "you@example.com"));
8
9    let selected = view.run()?;
10
11    println!("Collected values:");
12    for value in selected {
13        println!("{}", value);
14    }
15
16    Ok(())
17}

Trait Implementations§

Source§

impl From<View> for WidgetType

Source§

fn from(value: View) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for View

§

impl RefUnwindSafe for View

§

impl Send for View

§

impl Sync for View

§

impl Unpin for View

§

impl UnwindSafe for View

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, 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.