/** * @file EditorWidget.h * @author apio (cloudapio.eu) * @brief Multiline text editing widget. * * @copyright Copyright (c) 2024, the Luna authors. * */ #include #include #include #include class EditorWidget : public ui::Widget { public: EditorWidget(SharedPtr font); Result load_file(const os::Path& path); Result save_file(); Result handle_key_event(const ui::KeyEventRequest& request) override; Result draw(ui::Canvas& canvas) override; private: SharedPtr m_font; Buffer m_data; struct Line { usize begin; usize end; }; Vector m_lines; usize m_cursor { 0 }; ui::Point m_cursor_position { 0, 0 }; OwnedPtr m_cursor_timer; bool m_cursor_activated = true; os::Path m_path { AT_FDCWD }; void tick_cursor(); Result recalculate_lines(); void recalculate_cursor_position(); void recalculate_cursor_index(); };