1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:47:45 +00:00

GTextEditor: Add support for different text alignments.

Currently only CenterLeft and CenterRight are supported, but it would be
very straightforward to add other alignments as well.
This commit is contained in:
Andreas Kling 2019-04-24 22:24:16 +02:00
parent 16f6a3af3c
commit 62f0aae4ca
2 changed files with 57 additions and 9 deletions

View file

@ -3,6 +3,7 @@
#include <LibGUI/GScrollableWidget.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <SharedGraphics/TextAlignment.h>
class GAction;
class GMenu;
@ -69,6 +70,9 @@ public:
GTextEditor(Type, GWidget* parent);
virtual ~GTextEditor() override;
TextAlignment text_alignment() const { return m_text_alignment; }
void set_text_alignment(TextAlignment);
Type type() const { return m_type; }
bool is_single_line() const { return m_type == SingleLine; }
bool is_multi_line() const { return m_type == MultiLine; }
@ -173,11 +177,13 @@ private:
void insert_at_cursor_or_replace_selection(const String&);
void delete_selection();
void did_update_selection();
int content_x_for_position(const GTextPosition&) const;
Type m_type { MultiLine };
Vector<OwnPtr<Line>> m_lines;
GTextPosition m_cursor;
TextAlignment m_text_alignment { TextAlignment::CenterLeft };
bool m_cursor_state { true };
bool m_in_drag_select { false };
bool m_ruler_visible { true };