Luna/gui/apps/editor/EditorWidget.h

50 lines
957 B
C
Raw Normal View History

2024-02-11 16:10:17 +00:00
/**
* @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>
2024-03-29 19:17:12 +00:00
#include <ui/TextInput.h>
2024-02-11 16:10:17 +00:00
#include <ui/Widget.h>
2024-03-29 19:17:12 +00:00
class EditorWidget : public ui::TextInput
2024-02-11 16:10:17 +00:00
{
public:
EditorWidget(SharedPtr<ui::Font> font);
Result<void> load_file(const os::Path& path);
2024-02-27 19:11:14 +00:00
Result<void> save_file();
2024-02-11 16:10:17 +00:00
Result<ui::EventResult> handle_key_event(const ui::KeyEventRequest& request) override;
Result<void> draw(ui::Canvas& canvas) override;
os::Path& path()
{
return m_path;
}
2024-02-11 16:10:17 +00:00
private:
SharedPtr<ui::Font> m_font;
struct Line
{
usize begin;
usize end;
};
Vector<Line> m_lines;
2024-02-27 19:11:14 +00:00
os::Path m_path { AT_FDCWD };
2024-02-11 16:10:17 +00:00
Result<void> recalculate_lines();
void recalculate_cursor_position();
void recalculate_cursor_index();
};