cool_rust_input

Trait CustomInput

Source
pub trait CustomInput {
    // Provided methods
    fn handle_key_press(
        &mut self,
        key: &Event,
        current_text: String,
    ) -> KeyPressResult { ... }
    fn before_draw_text(
        &mut self,
        terminal_size: (u16, u16),
        current_text: String,
    ) { ... }
    fn after_draw_text(
        &mut self,
        terminal_size: (u16, u16),
        current_text: String,
    ) { ... }
    fn get_offset(
        &mut self,
        terminal_size: (u16, u16),
        current_text: String,
    ) -> (u16, u16) { ... }
    fn get_size(
        &mut self,
        terminal_size: (u16, u16),
        current_text: String,
    ) -> (u16, u16) { ... }
}
Expand description

Trait that allows custom implementations / behaviour of an input

Provided Methods§

Source

fn handle_key_press( &mut self, key: &Event, current_text: String, ) -> KeyPressResult

Called before handling of every key press.

Source

fn before_draw_text(&mut self, terminal_size: (u16, u16), current_text: String)

Called before the user’s text input is drawn. Here you can ex. change color of the inputted text

Source

fn after_draw_text(&mut self, terminal_size: (u16, u16), current_text: String)

Called after the user’s text is drawn. Here you can ex. draw other text like information or a title of the document.

Source

fn get_offset( &mut self, terminal_size: (u16, u16), current_text: String, ) -> (u16, u16)

Called by the parent input to get the input area’s offset, I.e. where the user will start typing.

Source

fn get_size( &mut self, terminal_size: (u16, u16), current_text: String, ) -> (u16, u16)

Called by the parent input to get the input area’s size

Examples found in repository?
examples/full-custom-input.rs (line 45)
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
    fn after_draw_text(&mut self, terminal_size: (u16, u16), current_text: String) {
        let _ = queue!(stdout(), SetForegroundColor(Color::White));
        set_terminal_line(
            "Welcome to my cool text editor. Here you can write cool stuff!",
            5,
            0,
            true,
        )
        .unwrap();
        set_terminal_line("Rules:", 5, 1, true).unwrap();
        set_terminal_line("None!!", 10, 2, true).unwrap();

        let width = self.get_size(terminal_size, current_text).0;
        set_terminal_line(&String::from("_").repeat(width as usize), 5, 3, true).unwrap();
    }

Implementors§