cool_rust_input

Trait CustomInputHandler

Source
pub trait CustomInputHandler {
    // Provided methods
    fn handle_key_press(
        &mut self,
        key: &Event,
        ctx: HandlerContext<'_>,
    ) -> KeyPressResult { ... }
    fn before_draw_text(&mut self, ctx: HandlerContext<'_>) { ... }
    fn after_draw_text(&mut self, ctx: HandlerContext<'_>) { ... }
    fn get_offset(&mut self, ctx: HandlerContext<'_>) -> (u16, u16) { ... }
    fn get_size(&mut self, ctx: HandlerContext<'_>) -> (u16, u16) { ... }
}
Expand description

Trait that allows custom implementations / behaviour of an input

Provided Methods§

Source

fn handle_key_press( &mut self, key: &Event, ctx: HandlerContext<'_>, ) -> KeyPressResult

Called before handling of every key press.

Source

fn before_draw_text(&mut self, ctx: HandlerContext<'_>)

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, ctx: HandlerContext<'_>)

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, ctx: HandlerContext<'_>) -> (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, ctx: HandlerContext<'_>) -> (u16, u16)

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

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

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

Implementors§