mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 09:47:34 +00:00
LibGfx+Userland: Add width_rounded_up() helper
This commit is contained in:
parent
c9404c3a63
commit
55423b4ed0
21 changed files with 34 additions and 19 deletions
|
@ -105,7 +105,7 @@ void Button::paint_event(PaintEvent& event)
|
|||
content_rect.set_width(content_rect.width() - m_icon->width() - icon_spacing());
|
||||
}
|
||||
|
||||
Gfx::IntRect text_rect { 0, 0, static_cast<int>(ceilf(font.width(text()))), font.pixel_size_rounded_up() };
|
||||
Gfx::IntRect text_rect { 0, 0, font.width_rounded_up(text()), font.pixel_size_rounded_up() };
|
||||
if (text_rect.width() > content_rect.width())
|
||||
text_rect.set_width(content_rect.width());
|
||||
text_rect.align_within(content_rect, text_alignment());
|
||||
|
|
|
@ -65,7 +65,7 @@ void CheckBox::paint_event(PaintEvent& event)
|
|||
auto text_rect = rect();
|
||||
if (m_checkbox_position == CheckBoxPosition::Left)
|
||||
text_rect.set_left(box_rect.right() + 1 + gap_between_box_and_rect());
|
||||
text_rect.set_width(static_cast<int>(ceilf(font().width(text()))));
|
||||
text_rect.set_width(font().width_rounded_up(text()));
|
||||
text_rect.set_top(height() / 2 - font().pixel_size_rounded_up() / 2);
|
||||
text_rect.set_height(font().pixel_size_rounded_up());
|
||||
|
||||
|
@ -101,7 +101,7 @@ void CheckBox::set_autosize(bool autosize)
|
|||
|
||||
void CheckBox::size_to_fit()
|
||||
{
|
||||
set_fixed_width(box_rect().width() + gap_between_box_and_rect() + static_cast<int>(ceilf(font().width(text()))) + horizontal_padding() * 2);
|
||||
set_fixed_width(box_rect().width() + gap_between_box_and_rect() + font().width_rounded_up(text()) + horizontal_padding() * 2);
|
||||
}
|
||||
|
||||
Optional<UISize> CheckBox::calculated_min_size() const
|
||||
|
|
|
@ -43,7 +43,7 @@ void GroupBox::paint_event(PaintEvent& event)
|
|||
Gfx::StylePainter::paint_frame(painter, frame_rect, palette(), Gfx::FrameShape::Box, Gfx::FrameShadow::Sunken, 2);
|
||||
|
||||
if (!m_title.is_empty()) {
|
||||
Gfx::IntRect text_rect { 6, 1, static_cast<int>(ceilf(font().width(m_title) + 6)), font().pixel_size_rounded_up() };
|
||||
Gfx::IntRect text_rect { 6, 1, font().width_rounded_up(m_title) + 6, font().pixel_size_rounded_up() };
|
||||
painter.fill_rect(text_rect, palette().button());
|
||||
painter.draw_text(text_rect, m_title, Gfx::TextAlignment::CenterLeft, palette().button_text());
|
||||
}
|
||||
|
|
|
@ -272,7 +272,7 @@ void HeaderView::paint_horizontal(Painter& painter)
|
|||
painter.draw_text(text_rect, text, font(), section_data.alignment, palette().button_text());
|
||||
|
||||
if (is_key_column && (m_table_view.sort_order() != SortOrder::None)) {
|
||||
Gfx::IntPoint offset { text_rect.x() + static_cast<int>(ceilf(font().width(text))) + sorting_arrow_offset, sorting_arrow_offset };
|
||||
Gfx::IntPoint offset { text_rect.x() + font().width_rounded_up(text) + sorting_arrow_offset, sorting_arrow_offset };
|
||||
auto coordinates = m_table_view.sort_order() == SortOrder::Ascending
|
||||
? ascending_arrow_coordinates.span()
|
||||
: descending_arrow_coordinates.span();
|
||||
|
|
|
@ -428,7 +428,7 @@ void IconView::get_item_rects(int item_index, ItemData& item_data, Gfx::Font con
|
|||
item_data.icon_offset_y = -font.pixel_size_rounded_up() - 6;
|
||||
item_data.icon_rect.translate_by(0, item_data.icon_offset_y);
|
||||
|
||||
int unwrapped_text_width = static_cast<int>(ceilf(font.width(item_data.text)));
|
||||
int unwrapped_text_width = font.width_rounded_up(item_data.text);
|
||||
int available_width = item_rect.width() - 6;
|
||||
|
||||
item_data.text_rect = { 0, item_data.icon_rect.bottom() + 6 + 1, 0, font.pixel_size_rounded_up() };
|
||||
|
|
|
@ -116,7 +116,7 @@ void Label::size_to_fit()
|
|||
|
||||
int Label::text_calculated_preferred_width() const
|
||||
{
|
||||
return static_cast<int>(ceilf(font().width(m_text))) + m_autosize_padding * 2;
|
||||
return font().width_rounded_up(m_text) + m_autosize_padding * 2;
|
||||
}
|
||||
|
||||
int Label::text_calculated_preferred_height() const
|
||||
|
|
|
@ -81,7 +81,7 @@ void LinkLabel::paint_event(PaintEvent& event)
|
|||
GUI::Painter painter(*this);
|
||||
|
||||
if (m_hovered)
|
||||
painter.draw_line({ 0, rect().bottom() }, { static_cast<int>(ceilf(font().width(text()))), rect().bottom() }, palette().link());
|
||||
painter.draw_line({ 0, rect().bottom() }, { font().width_rounded_up(text()), rect().bottom() }, palette().link());
|
||||
|
||||
if (is_focused())
|
||||
painter.draw_focus_rect(text_rect(), palette().focus_outline());
|
||||
|
|
|
@ -51,7 +51,7 @@ void RadioButton::paint_event(PaintEvent& event)
|
|||
|
||||
Gfx::StylePainter::paint_radio_button(painter, circle_rect, palette(), is_checked(), is_being_pressed());
|
||||
|
||||
Gfx::IntRect text_rect { circle_rect.right() + 5 + horizontal_padding(), 0, static_cast<int>(ceilf(font().width(text()))), font().pixel_size_rounded_up() };
|
||||
Gfx::IntRect text_rect { circle_rect.right() + 5 + horizontal_padding(), 0, font().width_rounded_up(text()), font().pixel_size_rounded_up() };
|
||||
text_rect.center_vertically_within(rect());
|
||||
paint_text(painter, text_rect, font(), Gfx::TextAlignment::TopLeft);
|
||||
|
||||
|
@ -69,7 +69,7 @@ void RadioButton::click(unsigned)
|
|||
Optional<UISize> RadioButton::calculated_min_size() const
|
||||
{
|
||||
auto const& font = this->font();
|
||||
int width = horizontal_padding() * 2 + circle_size().width() + static_cast<int>(ceilf(font.width(text())));
|
||||
int width = horizontal_padding() * 2 + circle_size().width() + font.width_rounded_up(text());
|
||||
int height = max(22, max(font.pixel_size_rounded_up() + 8, circle_size().height()));
|
||||
return UISize(width, height);
|
||||
}
|
||||
|
|
|
@ -452,7 +452,7 @@ Gfx::IntRect TabWidget::close_button_rect(size_t index) const
|
|||
|
||||
int TabWidget::TabData::width(Gfx::Font const& font) const
|
||||
{
|
||||
auto width = 16 + static_cast<int>(ceilf(font.width(title))) + (icon ? (16 + 4) : 0);
|
||||
auto width = 16 + font.width_rounded_up(title) + (icon ? (16 + 4) : 0);
|
||||
// NOTE: This needs to always be an odd number, because the button rect
|
||||
// includes 3px of light and shadow on the left and right edges. If
|
||||
// the button rect width is not an odd number, the area left for the
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue