/** * @file TextInput.h * @author apio (cloudapio.eu) * @brief Base class for text inputs. * * @copyright Copyright (c) 2024, the Luna authors. * */ #pragma once #include #include #include #include namespace ui { class TextInput : public Widget { public: TextInput(Window* window, Widget* parent); virtual Result handle_key_event(const ui::KeyEventRequest& request) = 0; virtual Result draw(ui::Canvas& canvas) = 0; void show_tree(int indent) override { os::println("%*s- ui::TextInput (%d,%d,%d,%d)", indent, "", m_rect.pos.x, m_rect.pos.y, m_rect.width, m_rect.height); } protected: Buffer m_data; usize m_cursor { 0 }; ui::Point m_cursor_position { 0, 0 }; OwnedPtr m_cursor_timer; bool m_cursor_activated = true; void tick_cursor(); void update_cursor(); Result delete_current_character(); Result insert_character(char c); }; }