Przeglądaj źródła

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.
sin-ack 4 lat temu
rodzic
commit
4c9c85ac01

+ 2 - 2
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;
     }
 

+ 1 - 1
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;

+ 1 - 1
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;

+ 1 - 1
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());

+ 4 - 4
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();
 }
-
 }

+ 1 - 1
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());

+ 7 - 7
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);

+ 4 - 4
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());
 }