1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:17:35 +00:00

LibGfx: Unify Rect, Point, and Size

This commit unifies methods and method/param names between the above
classes, as well as adds [[nodiscard]] and ALWAYS_INLINE where
appropriate. It also renamed the various move_by methods to
translate_by, as that more closely matches the transformation
terminology.
This commit is contained in:
Matthew Olsson 2021-04-12 11:47:09 -07:00 committed by Andreas Kling
parent ac238b3bd6
commit 88cfaf7bf0
48 changed files with 282 additions and 187 deletions

View file

@ -188,7 +188,7 @@ void Application::tooltip_show_timer_did_fire()
const int margin = 30;
Gfx::IntPoint adjusted_pos = WindowServerConnection::the().send_sync<Messages::WindowServer::GetGlobalCursorPosition>()->position();
adjusted_pos.move_by(0, 18);
adjusted_pos.translate_by(0, 18);
if (adjusted_pos.x() + m_tooltip_window->width() >= desktop_rect.width() - margin) {
adjusted_pos = adjusted_pos.translated(-m_tooltip_window->width(), 0);

View file

@ -62,7 +62,7 @@ void Button::paint_event(PaintEvent& event)
painter.blit_filtered(icon_location.translated(1, 1), *m_icon, m_icon->rect(), [&shadow_color](auto) {
return shadow_color;
});
icon_location.move_by(-1, -1);
icon_location.translate_by(-1, -1);
}
if (m_icon) {
@ -77,7 +77,7 @@ void Button::paint_event(PaintEvent& event)
}
auto& font = is_checked() ? Gfx::FontDatabase::default_bold_font() : this->font();
if (m_icon && !text().is_empty()) {
content_rect.move_by(m_icon->width() + icon_spacing(), 0);
content_rect.translate_by(m_icon->width() + icon_spacing(), 0);
content_rect.set_width(content_rect.width() - m_icon->width() - icon_spacing());
}

View file

@ -246,7 +246,7 @@ void HeaderView::paint_horizontal(Painter& painter)
}
auto text_rect = cell_rect.shrunken(m_table_view.horizontal_padding() * 2, 0);
if (pressed)
text_rect.move_by(1, 1);
text_rect.translate_by(1, 1);
painter.draw_text(text_rect, text, font(), section_alignment(section), palette().button_text());
x_offset += section_width + m_table_view.horizontal_padding() * 2;
}
@ -274,7 +274,7 @@ void HeaderView::paint_vertical(Painter& painter)
String text = String::number(section);
auto text_rect = cell_rect.shrunken(m_table_view.horizontal_padding() * 2, 0);
if (pressed)
text_rect.move_by(1, 1);
text_rect.translate_by(1, 1);
painter.draw_text(text_rect, text, font(), section_alignment(section), palette().button_text());
y_offset += section_size;
}

View file

@ -381,7 +381,7 @@ void IconView::update_item_rects(int item_index, ItemData& item_data) const
{
auto item_rect = this->item_rect(item_index);
item_data.icon_rect.center_within(item_rect);
item_data.icon_rect.move_by(0, item_data.icon_offset_y);
item_data.icon_rect.translate_by(0, item_data.icon_offset_y);
item_data.text_rect.center_horizontally_within(item_rect);
item_data.text_rect.set_top(item_rect.y() + item_data.text_offset_y);
}
@ -418,7 +418,7 @@ void IconView::get_item_rects(int item_index, ItemData& item_data, const Gfx::Fo
item_data.icon_rect = { 0, 0, 32, 32 };
item_data.icon_rect.center_within(item_rect);
item_data.icon_offset_y = -font.glyph_height() - 6;
item_data.icon_rect.move_by(0, item_data.icon_offset_y);
item_data.icon_rect.translate_by(0, item_data.icon_offset_y);
int unwrapped_text_width = font.width(item_data.text);
int available_width = item_rect.width() - 6;

View file

@ -79,7 +79,7 @@ Gfx::IntRect Label::text_rect(size_t line) const
if (frame_thickness() > 0)
indent = font().glyph_width('x') / 2;
auto rect = frame_inner_rect();
rect.move_by(indent, line * (font().glyph_height() + 1));
rect.translate_by(indent, line * (font().glyph_height() + 1));
rect.set_width(rect.width() - indent * 2);
return rect;
}

View file

@ -127,7 +127,7 @@ void ListView::paint_list_item(Painter& painter, int row_index, int painted_item
else
text_color = index.data(ModelRole::ForegroundColor).to_color(palette().color(foreground_role()));
auto text_rect = row_rect;
text_rect.move_by(horizontal_padding(), 0);
text_rect.translate_by(horizontal_padding(), 0);
text_rect.set_width(text_rect.width() - horizontal_padding() * 2);
auto text_alignment = index.data(ModelRole::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft);
painter.draw_text(text_rect, data.to_string(), font, text_alignment, text_color);

View file

@ -225,16 +225,16 @@ Gfx::IntRect ScrollableWidget::widget_inner_rect() const
Gfx::IntPoint ScrollableWidget::to_content_position(const Gfx::IntPoint& widget_position) const
{
auto content_position = widget_position;
content_position.move_by(horizontal_scrollbar().value(), vertical_scrollbar().value());
content_position.move_by(-frame_thickness(), -frame_thickness());
content_position.translate_by(horizontal_scrollbar().value(), vertical_scrollbar().value());
content_position.translate_by(-frame_thickness(), -frame_thickness());
return content_position;
}
Gfx::IntPoint ScrollableWidget::to_widget_position(const Gfx::IntPoint& content_position) const
{
auto widget_position = content_position;
widget_position.move_by(-horizontal_scrollbar().value(), -vertical_scrollbar().value());
widget_position.move_by(frame_thickness(), frame_thickness());
widget_position.translate_by(-horizontal_scrollbar().value(), -vertical_scrollbar().value());
widget_position.translate_by(frame_thickness(), frame_thickness());
return widget_position;
}

View file

@ -201,14 +201,14 @@ void Scrollbar::paint_event(PaintEvent& event)
if (length(orientation()) > default_button_size()) {
auto decrement_location = decrement_button_rect().location().translated(3, 3);
if (decrement_pressed)
decrement_location.move_by(1, 1);
decrement_location.translate_by(1, 1);
if (!has_scrubber() || !is_enabled())
painter.draw_bitmap(decrement_location.translated(1, 1), orientation() == Orientation::Vertical ? *s_up_arrow_bitmap : *s_left_arrow_bitmap, palette().threed_highlight());
painter.draw_bitmap(decrement_location, orientation() == Orientation::Vertical ? *s_up_arrow_bitmap : *s_left_arrow_bitmap, (has_scrubber() && is_enabled()) ? palette().button_text() : palette().threed_shadow1());
auto increment_location = increment_button_rect().location().translated(3, 3);
if (increment_pressed)
increment_location.move_by(1, 1);
increment_location.translate_by(1, 1);
if (!has_scrubber() || !is_enabled())
painter.draw_bitmap(increment_location.translated(1, 1), orientation() == Orientation::Vertical ? *s_down_arrow_bitmap : *s_right_arrow_bitmap, palette().threed_highlight());
painter.draw_bitmap(increment_location, orientation() == Orientation::Vertical ? *s_down_arrow_bitmap : *s_right_arrow_bitmap, (has_scrubber() && is_enabled()) ? palette().button_text() : palette().threed_shadow1());

View file

@ -197,7 +197,7 @@ void TabWidget::paint_event(PaintEvent& event)
if (!icon)
return;
Gfx::IntRect icon_rect { button_rect.x(), button_rect.y(), 16, 16 };
icon_rect.move_by(4, 3);
icon_rect.translate_by(4, 3);
painter.draw_scaled_bitmap(icon_rect, *icon, icon->rect());
text_rect.set_x(icon_rect.right() + 1 + 4);
text_rect.intersect(button_rect);
@ -281,13 +281,13 @@ Gfx::IntRect TabWidget::button_rect(int index) const
}
Gfx::IntRect rect { x_offset, 0, m_uniform_tabs ? uniform_tab_width() : m_tabs[index].width(font()), bar_height() };
if (m_tabs[index].widget != m_active_widget) {
rect.move_by(0, m_tab_position == TabPosition::Top ? 2 : 0);
rect.translate_by(0, m_tab_position == TabPosition::Top ? 2 : 0);
rect.set_height(rect.height() - 2);
} else {
rect.move_by(-2, 0);
rect.translate_by(-2, 0);
rect.set_width(rect.width() + 4);
}
rect.move_by(bar_rect().location());
rect.translate_by(bar_rect().location());
return rect;
}

View file

@ -134,7 +134,7 @@ TextPosition TextEditor::text_position_at_content_position(const Gfx::IntPoint&
{
auto position = content_position;
if (is_single_line() && icon())
position.move_by(-(icon_size() + icon_padding()), 0);
position.translate_by(-(icon_size() + icon_padding()), 0);
size_t line_index = 0;
@ -194,9 +194,9 @@ TextPosition TextEditor::text_position_at_content_position(const Gfx::IntPoint&
TextPosition TextEditor::text_position_at(const Gfx::IntPoint& widget_position) const
{
auto content_position = widget_position;
content_position.move_by(horizontal_scrollbar().value(), vertical_scrollbar().value());
content_position.move_by(-(m_horizontal_content_padding + ruler_width()), 0);
content_position.move_by(-frame_thickness(), -frame_thickness());
content_position.translate_by(horizontal_scrollbar().value(), vertical_scrollbar().value());
content_position.translate_by(-(m_horizontal_content_padding + ruler_width()), 0);
content_position.translate_by(-frame_thickness(), -frame_thickness());
return text_position_at_content_position(content_position);
}
@ -435,8 +435,8 @@ void TextEditor::paint_event(PaintEvent& event)
height() - height_occupied_by_horizontal_scrollbar()
};
if (m_ruler_visible)
text_clip_rect.move_by(-ruler_width(), 0);
text_clip_rect.move_by(horizontal_scrollbar().value(), vertical_scrollbar().value());
text_clip_rect.translate_by(-ruler_width(), 0);
text_clip_rect.translate_by(horizontal_scrollbar().value(), vertical_scrollbar().value());
painter.add_clip_rect(text_clip_rect);
size_t span_index = 0;
@ -507,7 +507,7 @@ void TextEditor::paint_event(PaintEvent& event)
if (underline) {
painter.draw_line(span_rect.bottom_left().translated(0, 1), span_rect.bottom_right().translated(0, 1), color);
}
span_rect.move_by(span_rect.width(), 0);
span_rect.translate_by(span_rect.width(), 0);
};
for (;;) {
if (span_index >= document().spans().size()) {
@ -1015,8 +1015,8 @@ Gfx::IntRect TextEditor::line_widget_rect(size_t line_index) const
auto rect = line_content_rect(line_index);
rect.set_x(frame_thickness());
rect.set_width(frame_inner_rect().width());
rect.move_by(0, -(vertical_scrollbar().value()));
rect.move_by(0, frame_thickness());
rect.translate_by(0, -(vertical_scrollbar().value()));
rect.translate_by(0, frame_thickness());
rect.intersect(frame_inner_rect());
return rect;
}
@ -1567,7 +1567,7 @@ void TextEditor::for_each_visual_line(size_t line_index, Callback callback) cons
if (is_single_line()) {
visual_line_rect.center_vertically_within(editor_visible_text_rect);
if (m_icon)
visual_line_rect.move_by(icon_size() + icon_padding(), 0);
visual_line_rect.translate_by(icon_size() + icon_padding(), 0);
}
if (callback(visual_line_rect, visual_line_view, start_of_line, visual_line_index == visual_data.visual_line_breaks.size() - 1) == IterationDecision::Break)
break;

View file

@ -575,7 +575,7 @@ Gfx::IntRect Widget::window_relative_rect() const
{
auto rect = relative_rect();
for (auto* parent = parent_widget(); parent; parent = parent->parent_widget()) {
rect.move_by(parent->relative_position());
rect.translate_by(parent->relative_position());
}
return rect;
}
@ -957,7 +957,7 @@ void Widget::set_content_margins(const Margins& margins)
Gfx::IntRect Widget::content_rect() const
{
auto rect = relative_rect();
rect.move_by(m_content_margins.left(), m_content_margins.top());
rect.translate_by(m_content_margins.left(), m_content_margins.top());
rect.set_width(rect.width() - (m_content_margins.left() + m_content_margins.right()));
rect.set_height(rect.height() - (m_content_margins.top() + m_content_margins.bottom()));
return rect;