1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-19 08:17:38 +00:00

Userland: Make TextWrapping::Wrap opt-in

This was breaking many places which didn't expect text to wrap. Now,
the only place where text currently wraps is in GUI::Label.
This commit is contained in:
sin-ack 2021-07-27 19:33:03 +00:00 committed by Andreas Kling
parent 2dc9ae00af
commit 4c9c85ac01
8 changed files with 21 additions and 21 deletions

View file

@ -176,8 +176,8 @@ void AbstractButton::paint_text(Painter& painter, const Gfx::IntRect& rect, cons
auto clipped_rect = rect.intersected(this->rect()); auto clipped_rect = rect.intersected(this->rect());
if (!is_enabled()) { if (!is_enabled()) {
painter.draw_text(clipped_rect.translated(1, 1), text(), font, text_alignment, Color::White, Gfx::TextElision::Right); painter.draw_text(clipped_rect.translated(1, 1), text(), font, text_alignment, Color::White, Gfx::TextElision::Right, text_wrapping);
painter.draw_text(clipped_rect, text(), font, text_alignment, Color::from_rgb(0x808080), Gfx::TextElision::Right); painter.draw_text(clipped_rect, text(), font, text_alignment, Color::from_rgb(0x808080), Gfx::TextElision::Right, text_wrapping);
return; return;
} }

View file

@ -52,7 +52,7 @@ protected:
virtual void leave_event(Core::Event&) override; virtual void leave_event(Core::Event&) override;
virtual void change_event(Event&) override; virtual void change_event(Event&) override;
void paint_text(Painter&, const Gfx::IntRect&, const Gfx::Font&, Gfx::TextAlignment, Gfx::TextWrapping); void paint_text(Painter&, const Gfx::IntRect&, const Gfx::Font&, Gfx::TextAlignment, Gfx::TextWrapping = Gfx::TextWrapping::DontWrap);
private: private:
String m_text; String m_text;

View file

@ -85,7 +85,7 @@ void Button::paint_event(PaintEvent& event)
if (text_rect.width() > content_rect.width()) if (text_rect.width() > content_rect.width())
text_rect.set_width(content_rect.width()); text_rect.set_width(content_rect.width());
text_rect.align_within(content_rect, text_alignment()); text_rect.align_within(content_rect, text_alignment());
paint_text(painter, text_rect, font, text_alignment(), Gfx::TextWrapping::DontWrap); paint_text(painter, text_rect, font, text_alignment());
if (is_focused()) { if (is_focused()) {
Gfx::IntRect focus_rect; Gfx::IntRect focus_rect;

View file

@ -56,7 +56,7 @@ void CheckBox::paint_event(PaintEvent& event)
Gfx::StylePainter::paint_check_box(painter, box_rect, palette(), is_enabled(), is_checked(), is_being_pressed()); Gfx::StylePainter::paint_check_box(painter, box_rect, palette(), is_enabled(), is_checked(), is_being_pressed());
paint_text(painter, text_rect, font(), Gfx::TextAlignment::TopLeft, Gfx::TextWrapping::DontWrap); paint_text(painter, text_rect, font(), Gfx::TextAlignment::TopLeft);
if (is_focused()) if (is_focused())
painter.draw_focus_rect(text_rect.inflated(6, 6), palette().focus_outline()); painter.draw_focus_rect(text_rect.inflated(6, 6), palette().focus_outline());

View file

@ -11,6 +11,7 @@
#include <LibGfx/Font.h> #include <LibGfx/Font.h>
#include <LibGfx/Palette.h> #include <LibGfx/Palette.h>
#include <LibGfx/TextLayout.h> #include <LibGfx/TextLayout.h>
#include <LibGfx/TextWrapping.h>
REGISTER_WIDGET(GUI, Label) REGISTER_WIDGET(GUI, Label)
@ -95,10 +96,10 @@ void Label::paint_event(PaintEvent& event)
auto text_rect = this->text_rect(); auto text_rect = this->text_rect();
if (is_enabled()) { if (is_enabled()) {
painter.draw_text(text_rect, text(), m_text_alignment, palette().color(foreground_role()), Gfx::TextElision::Right); painter.draw_text(text_rect, text(), m_text_alignment, palette().color(foreground_role()), Gfx::TextElision::Right, Gfx::TextWrapping::Wrap);
} else { } else {
painter.draw_text(text_rect.translated(1, 1), text(), font(), text_alignment(), Color::White, Gfx::TextElision::Right); painter.draw_text(text_rect.translated(1, 1), text(), font(), text_alignment(), Color::White, Gfx::TextElision::Right, Gfx::TextWrapping::Wrap);
painter.draw_text(text_rect, text(), font(), text_alignment(), Color::from_rgb(0x808080), Gfx::TextElision::Right); painter.draw_text(text_rect, text(), font(), text_alignment(), Color::from_rgb(0x808080), Gfx::TextElision::Right, Gfx::TextWrapping::Wrap);
} }
} }
@ -113,5 +114,4 @@ int Label::preferred_height() const
// a constant instead. // a constant instead.
return Gfx::TextLayout(&font(), Utf8View { m_text }, text_rect()).bounding_rect(Gfx::TextWrapping::Wrap, 4).height(); return Gfx::TextLayout(&font(), Utf8View { m_text }, text_rect()).bounding_rect(Gfx::TextWrapping::Wrap, 4).height();
} }
} }

View file

@ -50,7 +50,7 @@ void RadioButton::paint_event(PaintEvent& event)
Gfx::IntRect text_rect { circle_rect.right() + 7, 0, font().width(text()), font().glyph_height() }; Gfx::IntRect text_rect { circle_rect.right() + 7, 0, font().width(text()), font().glyph_height() };
text_rect.center_vertically_within(rect()); text_rect.center_vertically_within(rect());
paint_text(painter, text_rect, font(), Gfx::TextAlignment::TopLeft, Gfx::TextWrapping::DontWrap); paint_text(painter, text_rect, font(), Gfx::TextAlignment::TopLeft);
if (is_focused()) if (is_focused())
painter.draw_focus_rect(text_rect.inflated(6, 6), palette().focus_outline()); painter.draw_focus_rect(text_rect.inflated(6, 6), palette().focus_outline());

View file

@ -62,13 +62,13 @@ public:
void blit_offset(const IntPoint&, const Gfx::Bitmap&, const IntRect& src_rect, const IntPoint&); void blit_offset(const IntPoint&, const Gfx::Bitmap&, const IntRect& src_rect, const IntPoint&);
void blit_disabled(const IntPoint&, const Gfx::Bitmap&, const IntRect&, const Palette&); void blit_disabled(const IntPoint&, const Gfx::Bitmap&, const IntRect&, const Palette&);
void blit_tiled(const IntRect&, const Gfx::Bitmap&, const IntRect& src_rect); void blit_tiled(const IntRect&, const Gfx::Bitmap&, const IntRect& src_rect);
void draw_text(const IntRect&, const StringView&, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None, TextWrapping = TextWrapping::Wrap); void draw_text(const IntRect&, const StringView&, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
void draw_text(const IntRect&, const StringView&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None, TextWrapping = TextWrapping::Wrap); void draw_text(const IntRect&, const StringView&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
void draw_text(const IntRect&, const Utf32View&, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None, TextWrapping = TextWrapping::Wrap); void draw_text(const IntRect&, const Utf32View&, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
void draw_text(const IntRect&, const Utf32View&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None, TextWrapping = TextWrapping::Wrap); void draw_text(const IntRect&, const Utf32View&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
void draw_text(Function<void(const IntRect&, u32)>, const IntRect&, const StringView&, const Font&, TextAlignment = TextAlignment::TopLeft, TextElision = TextElision::None, TextWrapping = TextWrapping::Wrap); void draw_text(Function<void(const IntRect&, u32)>, const IntRect&, const StringView&, const Font&, TextAlignment = TextAlignment::TopLeft, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
void draw_text(Function<void(const IntRect&, u32)>, const IntRect&, const Utf8View&, const Font&, TextAlignment = TextAlignment::TopLeft, TextElision = TextElision::None, TextWrapping = TextWrapping::Wrap); void draw_text(Function<void(const IntRect&, u32)>, const IntRect&, const Utf8View&, const Font&, TextAlignment = TextAlignment::TopLeft, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
void draw_text(Function<void(const IntRect&, u32)>, const IntRect&, const Utf32View&, const Font&, TextAlignment = TextAlignment::TopLeft, TextElision = TextElision::None, TextWrapping = TextWrapping::Wrap); void draw_text(Function<void(const IntRect&, u32)>, const IntRect&, const Utf32View&, const Font&, TextAlignment = TextAlignment::TopLeft, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
void draw_ui_text(const Gfx::IntRect&, const StringView&, const Gfx::Font&, TextAlignment, Gfx::Color); void draw_ui_text(const Gfx::IntRect&, const StringView&, const Gfx::Font&, TextAlignment, Gfx::Color);
void draw_glyph(const IntPoint&, u32, Color); void draw_glyph(const IntPoint&, u32, Color);
void draw_glyph(const IntPoint&, u32, const Font&, Color); void draw_glyph(const IntPoint&, u32, const Font&, Color);

View file

@ -71,8 +71,8 @@ static void paint_custom_progressbar(GUI::Painter& painter, const Gfx::IntRect&
painter.fill_rect_with_gradient(rect, start_color, end_color); painter.fill_rect_with_gradient(rect, start_color, end_color);
if (!text.is_null()) { if (!text.is_null()) {
painter.draw_text(text_rect.translated(1, 1), text, font, text_alignment, palette.base_text(), Gfx::TextElision::Right, Gfx::TextWrapping::DontWrap); painter.draw_text(text_rect.translated(1, 1), text, font, text_alignment, palette.base_text(), Gfx::TextElision::Right);
painter.draw_text(text_rect, text, font, text_alignment, palette.base_text().inverted(), Gfx::TextElision::Right, Gfx::TextWrapping::DontWrap); painter.draw_text(text_rect, text, font, text_alignment, palette.base_text().inverted(), Gfx::TextElision::Right);
} }
} }
@ -82,7 +82,7 @@ static void paint_custom_progressbar(GUI::Painter& painter, const Gfx::IntRect&
Gfx::PainterStateSaver saver(painter); Gfx::PainterStateSaver saver(painter);
painter.add_clip_rect(hole_rect); painter.add_clip_rect(hole_rect);
if (!text.is_null()) if (!text.is_null())
painter.draw_text(text_rect, text, font, text_alignment, palette.base_text(), Gfx::TextElision::Right, Gfx::TextWrapping::DontWrap); painter.draw_text(text_rect, text, font, text_alignment, palette.base_text(), Gfx::TextElision::Right);
} }
void TaskbarButton::paint_event(GUI::PaintEvent& event) void TaskbarButton::paint_event(GUI::PaintEvent& event)
@ -138,5 +138,5 @@ void TaskbarButton::paint_event(GUI::PaintEvent& event)
} }
if (!window.progress().has_value()) if (!window.progress().has_value())
paint_text(painter, text_rect, font, text_alignment(), Gfx::TextWrapping::DontWrap); paint_text(painter, text_rect, font, text_alignment());
} }