diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2021-07-27 19:33:03 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-27 22:05:20 +0200 |
commit | 4c9c85ac017ffe521990db19625fe2cbe9b36d46 (patch) | |
tree | 3ac56f9d76d56b63d1df59bc3d3186fb40d92e60 | |
parent | 2dc9ae00af130968af1f98cff4c39bf017149676 (diff) | |
download | serenity-4c9c85ac017ffe521990db19625fe2cbe9b36d46.zip |
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.
-rw-r--r-- | Userland/Libraries/LibGUI/AbstractButton.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/AbstractButton.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Button.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/CheckBox.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Label.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/RadioButton.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Painter.h | 14 | ||||
-rw-r--r-- | Userland/Services/Taskbar/TaskbarButton.cpp | 8 |
8 files changed, 21 insertions, 21 deletions
diff --git a/Userland/Libraries/LibGUI/AbstractButton.cpp b/Userland/Libraries/LibGUI/AbstractButton.cpp index eec057f9e1..ce8fa8bdb2 100644 --- a/Userland/Libraries/LibGUI/AbstractButton.cpp +++ b/Userland/Libraries/LibGUI/AbstractButton.cpp @@ -176,8 +176,8 @@ void AbstractButton::paint_text(Painter& painter, const Gfx::IntRect& rect, cons auto clipped_rect = rect.intersected(this->rect()); 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, text(), font, text_alignment, Color::from_rgb(0x808080), 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, text_wrapping); return; } diff --git a/Userland/Libraries/LibGUI/AbstractButton.h b/Userland/Libraries/LibGUI/AbstractButton.h index 421d182bca..23572bd9a0 100644 --- a/Userland/Libraries/LibGUI/AbstractButton.h +++ b/Userland/Libraries/LibGUI/AbstractButton.h @@ -52,7 +52,7 @@ protected: virtual void leave_event(Core::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: String m_text; diff --git a/Userland/Libraries/LibGUI/Button.cpp b/Userland/Libraries/LibGUI/Button.cpp index 2175f9a21e..107eaccbe5 100644 --- a/Userland/Libraries/LibGUI/Button.cpp +++ b/Userland/Libraries/LibGUI/Button.cpp @@ -85,7 +85,7 @@ void Button::paint_event(PaintEvent& event) if (text_rect.width() > content_rect.width()) text_rect.set_width(content_rect.width()); 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()) { Gfx::IntRect focus_rect; diff --git a/Userland/Libraries/LibGUI/CheckBox.cpp b/Userland/Libraries/LibGUI/CheckBox.cpp index 7acf65c729..2cfd26d88c 100644 --- a/Userland/Libraries/LibGUI/CheckBox.cpp +++ b/Userland/Libraries/LibGUI/CheckBox.cpp @@ -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()); - paint_text(painter, text_rect, font(), Gfx::TextAlignment::TopLeft, Gfx::TextWrapping::DontWrap); + paint_text(painter, text_rect, font(), Gfx::TextAlignment::TopLeft); if (is_focused()) painter.draw_focus_rect(text_rect.inflated(6, 6), palette().focus_outline()); diff --git a/Userland/Libraries/LibGUI/Label.cpp b/Userland/Libraries/LibGUI/Label.cpp index e0b9ea033e..2392d55848 100644 --- a/Userland/Libraries/LibGUI/Label.cpp +++ b/Userland/Libraries/LibGUI/Label.cpp @@ -11,6 +11,7 @@ #include <LibGfx/Font.h> #include <LibGfx/Palette.h> #include <LibGfx/TextLayout.h> +#include <LibGfx/TextWrapping.h> REGISTER_WIDGET(GUI, Label) @@ -95,10 +96,10 @@ void Label::paint_event(PaintEvent& event) auto text_rect = this->text_rect(); 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 { - painter.draw_text(text_rect.translated(1, 1), text(), font(), text_alignment(), Color::White, Gfx::TextElision::Right); - painter.draw_text(text_rect, text(), font(), text_alignment(), Color::from_rgb(0x808080), 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, Gfx::TextWrapping::Wrap); } } @@ -113,5 +114,4 @@ int Label::preferred_height() const // a constant instead. return Gfx::TextLayout(&font(), Utf8View { m_text }, text_rect()).bounding_rect(Gfx::TextWrapping::Wrap, 4).height(); } - } diff --git a/Userland/Libraries/LibGUI/RadioButton.cpp b/Userland/Libraries/LibGUI/RadioButton.cpp index 7d97a485b3..f4763976c6 100644 --- a/Userland/Libraries/LibGUI/RadioButton.cpp +++ b/Userland/Libraries/LibGUI/RadioButton.cpp @@ -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() }; 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()) painter.draw_focus_rect(text_rect.inflated(6, 6), palette().focus_outline()); diff --git a/Userland/Libraries/LibGfx/Painter.h b/Userland/Libraries/LibGfx/Painter.h index cc99629093..6083839f26 100644 --- a/Userland/Libraries/LibGfx/Painter.h +++ b/Userland/Libraries/LibGfx/Painter.h @@ -62,13 +62,13 @@ public: 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_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&, 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::Wrap); - void draw_text(const IntRect&, const Utf32View&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, 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::Wrap); - 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 Utf32View&, const Font&, TextAlignment = TextAlignment::TopLeft, 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::DontWrap); + 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::DontWrap); + 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::DontWrap); + 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_glyph(const IntPoint&, u32, Color); void draw_glyph(const IntPoint&, u32, const Font&, Color); diff --git a/Userland/Services/Taskbar/TaskbarButton.cpp b/Userland/Services/Taskbar/TaskbarButton.cpp index c405247ac2..e0a3087283 100644 --- a/Userland/Services/Taskbar/TaskbarButton.cpp +++ b/Userland/Services/Taskbar/TaskbarButton.cpp @@ -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); 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, text, font, text_alignment, palette.base_text().inverted(), 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); } } @@ -82,7 +82,7 @@ static void paint_custom_progressbar(GUI::Painter& painter, const Gfx::IntRect& Gfx::PainterStateSaver saver(painter); painter.add_clip_rect(hole_rect); 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) @@ -138,5 +138,5 @@ void TaskbarButton::paint_event(GUI::PaintEvent& event) } if (!window.progress().has_value()) - paint_text(painter, text_rect, font, text_alignment(), Gfx::TextWrapping::DontWrap); + paint_text(painter, text_rect, font, text_alignment()); } |