Split Rect constructor into default and explicit ctors

Separate the default constructor from the parameterized constructor to allow value-initialization of Rect arrays without routing through an explicit constructor. The parameterized constructor remains explicit to prevent implicit int-to-Rect conversions. Member variables now use in-class initializers.
This commit is contained in:
Justin Mitchell
2026-06-15 16:39:32 -04:00
parent 8ad538c98b
commit 0036a220be
+9 -5
View File
@@ -10,12 +10,16 @@ class GfxRenderer;
struct RecentBook; struct RecentBook;
struct Rect { struct Rect {
int x; int x = 0;
int y; int y = 0;
int width; int width = 0;
int height; int height = 0;
explicit Rect(int x = 0, int y = 0, int width = 0, int height = 0) : x(x), y(y), width(width), height(height) {} // Non-explicit zero-init default ctor so value-initialization (e.g. arrays of
// structs embedding a Rect) does not route through an explicit constructor.
// The parameterized ctor stays explicit to block implicit int->Rect.
Rect() = default;
explicit Rect(int x, int y = 0, int width = 0, int height = 0) : x(x), y(y), width(width), height(height) {}
// Logical-coordinate point hit-test (used for touch target hit-testing). // Logical-coordinate point hit-test (used for touch target hit-testing).
bool contains(int px, int py) const { return px >= x && px < x + width && py >= y && py < y + height; } bool contains(int px, int py) const { return px >= x && px < x + width && py >= y && py < y + height; }