Luna/editor/EditorWidget.h
apio 42e1700e7a
All checks were successful
Build and test / build (push) Successful in 1m47s
editor: Remove insert mode and use the arrow keys to navigate, plus Ctrl+S to save
2024-03-06 22:41:21 +01:00

54 lines
1.0 KiB
C++

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