mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 17:58:18 +03:00
LibGfx: Add a Gfx::TextAlignment parameter to Painter::draw_ui_text()
This commit is contained in:
parent
b7a25bfaac
commit
2b9bc605d2
Notes:
sideshowbarker
2024-07-18 20:37:44 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/2b9bc605d21
@ -1806,7 +1806,7 @@ void Painter::blit_tiled(const IntRect& dst_rect, const Gfx::Bitmap& bitmap, con
|
||||
}
|
||||
}
|
||||
|
||||
void Gfx::Painter::draw_ui_text(const Gfx::IntRect& rect, const StringView& text, const Gfx::Font& font, Gfx::Color color)
|
||||
void Gfx::Painter::draw_ui_text(const Gfx::IntRect& rect, const StringView& text, const Gfx::Font& font, Gfx::TextAlignment text_alignment, Gfx::Color color)
|
||||
{
|
||||
auto parse_ampersand_string = [](const StringView& raw_text, Optional<size_t>& underline_offset) -> String {
|
||||
if (raw_text.is_empty())
|
||||
@ -1831,9 +1831,9 @@ void Gfx::Painter::draw_ui_text(const Gfx::IntRect& rect, const StringView& text
|
||||
auto name_to_draw = parse_ampersand_string(text, underline_offset);
|
||||
|
||||
Gfx::IntRect text_rect { 0, 0, font.width(name_to_draw), font.glyph_height() };
|
||||
text_rect.center_within(rect);
|
||||
text_rect.align_within(rect, text_alignment);
|
||||
|
||||
draw_text(text_rect, name_to_draw, font, Gfx::TextAlignment::CenterLeft, color);
|
||||
draw_text(text_rect, name_to_draw, font, text_alignment, color);
|
||||
|
||||
if (underline_offset.has_value()) {
|
||||
Utf8View utf8_view { name_to_draw };
|
||||
|
@ -85,7 +85,7 @@ public:
|
||||
void draw_text(Function<void(const IntRect&, u32)>, const IntRect&, const StringView&, const Font&, TextAlignment = TextAlignment::TopLeft, TextElision = TextElision::None);
|
||||
void draw_text(Function<void(const IntRect&, u32)>, const IntRect&, const Utf8View&, const Font&, TextAlignment = TextAlignment::TopLeft, TextElision = TextElision::None);
|
||||
void draw_text(Function<void(const IntRect&, u32)>, const IntRect&, const Utf32View&, const Font&, TextAlignment = TextAlignment::TopLeft, TextElision = TextElision::None);
|
||||
void draw_ui_text(const Gfx::IntRect&, const StringView&, const Gfx::Font&, 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, const Font&, Color);
|
||||
void draw_emoji(const IntPoint&, const Gfx::Bitmap&, const Font&);
|
||||
|
@ -317,7 +317,7 @@ void WindowFrame::paint_menubar(Gfx::Painter& painter)
|
||||
if (paint_as_pressed || paint_as_hovered) {
|
||||
Gfx::StylePainter::paint_button(painter, menu.rect_in_window_menubar(), palette, Gfx::ButtonStyle::CoolBar, paint_as_pressed, paint_as_hovered);
|
||||
}
|
||||
painter.draw_ui_text(text_rect, menu.name(), font, text_color);
|
||||
painter.draw_ui_text(text_rect, menu.name(), font, Gfx::TextAlignment::Center, text_color);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user