mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 22:38:12 +00:00
GTextEditor: Unbreak right-aligned single-line text boxes
This makes the Calculator app look right once again! :^)
This commit is contained in:
parent
fcf5b1ff5b
commit
caf1b37e75
1 changed files with 10 additions and 2 deletions
|
@ -13,6 +13,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
//#define DEBUG_GTEXTEDITOR
|
||||||
|
|
||||||
GTextEditor::GTextEditor(Type type, GWidget* parent)
|
GTextEditor::GTextEditor(Type type, GWidget* parent)
|
||||||
: GScrollableWidget(parent)
|
: GScrollableWidget(parent)
|
||||||
, m_type(type)
|
, m_type(type)
|
||||||
|
@ -357,10 +359,11 @@ void GTextEditor::paint_event(GPaintEvent& event)
|
||||||
|
|
||||||
int visual_line_index = 0;
|
int visual_line_index = 0;
|
||||||
line.for_each_visual_line([&](const Rect& visual_line_rect, const StringView& visual_line_text, int start_of_visual_line) {
|
line.for_each_visual_line([&](const Rect& visual_line_rect, const StringView& visual_line_text, int start_of_visual_line) {
|
||||||
// FIXME: Make sure we always fill the entire line.
|
|
||||||
//line_rect.set_width(exposed_width);
|
|
||||||
if (is_multi_line() && line_index == m_cursor.line())
|
if (is_multi_line() && line_index == m_cursor.line())
|
||||||
painter.fill_rect(visual_line_rect, Color(230, 230, 230));
|
painter.fill_rect(visual_line_rect, Color(230, 230, 230));
|
||||||
|
#ifdef DEBUG_GTEXTEDITOR
|
||||||
|
painter.draw_rect(visual_line_rect, Color::Cyan);
|
||||||
|
#endif
|
||||||
painter.draw_text(visual_line_rect, visual_line_text, m_text_alignment, Color::Black);
|
painter.draw_text(visual_line_rect, visual_line_text, m_text_alignment, Color::Black);
|
||||||
bool physical_line_has_selection = has_selection && line_index >= selection.start().line() && line_index <= selection.end().line();
|
bool physical_line_has_selection = has_selection && line_index >= selection.start().line() && line_index <= selection.end().line();
|
||||||
if (physical_line_has_selection) {
|
if (physical_line_has_selection) {
|
||||||
|
@ -1368,6 +1371,7 @@ void GTextEditor::Line::recompute_visual_lines()
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
void GTextEditor::Line::for_each_visual_line(Callback callback) const
|
void GTextEditor::Line::for_each_visual_line(Callback callback) const
|
||||||
{
|
{
|
||||||
|
auto editor_visible_text_rect = m_editor.visible_text_rect_in_inner_coordinates();
|
||||||
int start_of_line = 0;
|
int start_of_line = 0;
|
||||||
int line_index = 0;
|
int line_index = 0;
|
||||||
for (auto visual_line_break : m_visual_line_breaks) {
|
for (auto visual_line_break : m_visual_line_breaks) {
|
||||||
|
@ -1378,6 +1382,10 @@ void GTextEditor::Line::for_each_visual_line(Callback callback) const
|
||||||
m_editor.font().width(visual_line_view),
|
m_editor.font().width(visual_line_view),
|
||||||
m_editor.line_height()
|
m_editor.line_height()
|
||||||
};
|
};
|
||||||
|
if (is_right_text_alignment(m_editor.text_alignment()))
|
||||||
|
visual_line_rect.set_right_without_resize(editor_visible_text_rect.right());
|
||||||
|
if (!m_editor.is_multi_line())
|
||||||
|
visual_line_rect.center_vertically_within(editor_visible_text_rect);
|
||||||
if (callback(visual_line_rect, visual_line_view, start_of_line) == IterationDecision::Break)
|
if (callback(visual_line_rect, visual_line_view, start_of_line) == IterationDecision::Break)
|
||||||
break;
|
break;
|
||||||
start_of_line = visual_line_break;
|
start_of_line = visual_line_break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue