Luna/gui/apps/editor/EditorWidget.h
apio fd26f40938
Some checks failed
Build and test / build (push) Failing after 1m32s
editor: Add "Save file as..." and error dialogs
2024-09-19 18:27:16 +02:00

51 lines
981 B
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/TextInput.h>
#include <ui/Widget.h>
class EditorWidget : public ui::TextInput
{
public:
EditorWidget(SharedPtr<ui::Font> font);
Result<void> load_file(const os::Path& path);
Result<void> save_file();
Result<void> save_file_as();
Result<ui::EventResult> handle_key_event(const ui::KeyEventRequest& request) override;
Result<void> draw(ui::Canvas& canvas) override;
os::Path path()
{
return m_path.view();
}
private:
SharedPtr<ui::Font> m_font;
struct Line
{
usize begin;
usize end;
};
Vector<Line> m_lines;
String m_path;
Result<void> recalculate_lines();
void recalculate_cursor_position();
void recalculate_cursor_index();
};