Skip to content

Commit

Permalink
Added helpful function to calculate center of rectangle.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Sep 2, 2024
1 parent 1508241 commit f52d39f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ui/rect.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ namespace pos {
return w->y() + w->height();
}

/*
rect::center(mywidget);
*/
[[nodiscard]] inline QPoint center(const QRect &r) {
return { r.left() + r.width() / 2, r.top() + r.height() / 2 };
}

[[nodiscard]] inline QPointF center(const QRectF &r) {
return { r.left() + r.width() / 2, r.top() + r.height() / 2 };
}

[[nodiscard]] inline QPoint center(not_null<const QWidget*> w) {
return { w->x() + w->width() / 2, w->y() + w->height() / 2 };
}

} // namespace rect

/*
Expand Down

0 comments on commit f52d39f

Please sign in to comment.