Skip to content

Commit 6b72d1d

Browse files
authored
Fixed solution overlay for small areas (#55)
## Motivation Fix overlay hints overlapping with the game grid area, making them unreadable and interfering with gameplay. ## Proposal - Increased z-index from 10 to 1000 for overlay boxes to ensure they render above game cells - Added smart text positioning that places labels above small overlay boxes (< 100px width or < 40px height) instead of inside them - Improved font size calculation for better responsiveness ## Test Plan Tested it manually here is a before and after Before: <img width="729" height="893" alt="image" src="https://github.com/user-attachments/assets/82496896-bd6b-4943-97b8-8db58fd626dd" /> After: <img width="872" height="856" alt="image" src="https://github.com/user-attachments/assets/5de85298-fbc8-49f2-ae50-752da4cd8218" />
1 parent dea61a3 commit 6b72d1d

File tree

1 file changed

+51
-13
lines changed

1 file changed

+51
-13
lines changed

frontend/src/components/game-of-life/RectangleOverlays.tsx

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ function createCombinedRectangleOverlay(
2424
): JSX.Element {
2525
const width = (initialRect.x_range.end - initialRect.x_range.start) * cellSize;
2626
const height = (initialRect.y_range.end - initialRect.y_range.start) * cellSize;
27-
const fontSize = Math.max(11, Math.min(14, Math.min(width, height) / 10));
27+
const fontSize = Math.max(11, Math.min(16, Math.min(width, height) / 8));
28+
29+
// Determine if the area is too small for text inside
30+
const isSmallArea = width < 100 || height < 40;
2831

2932
return (
3033
<div
3134
key="combined-rect"
32-
className="absolute pointer-events-none flex flex-col items-end justify-end"
35+
className="absolute pointer-events-none"
3336
style={{
3437
left: initialRect.x_range.start * cellSize,
3538
top: initialRect.y_range.start * cellSize,
@@ -40,13 +43,29 @@ function createCombinedRectangleOverlay(
4043
border: "2px solid",
4144
borderImage: "linear-gradient(135deg, rgba(34, 197, 94, 0.6), rgba(59, 130, 246, 0.6)) 1",
4245
borderRadius: "6px",
43-
zIndex: 10,
44-
padding: "8px",
46+
zIndex: 1000,
4547
}}
4648
>
47-
<div className="flex flex-col gap-1">
49+
<div
50+
className="flex flex-col gap-1"
51+
style={{
52+
position: "absolute",
53+
...(isSmallArea
54+
? {
55+
// Position above the box when small
56+
bottom: "100%",
57+
left: "0",
58+
marginBottom: "4px",
59+
}
60+
: {
61+
// Position inside the box when large enough
62+
bottom: "8px",
63+
right: "8px",
64+
}),
65+
}}
66+
>
4867
<div
49-
className="font-medium px-2 py-1 rounded"
68+
className="font-medium px-2 py-1 rounded whitespace-nowrap"
5069
style={{
5170
fontSize: `${fontSize}px`,
5271
color: "rgb(34, 197, 94)",
@@ -57,7 +76,7 @@ function createCombinedRectangleOverlay(
5776
{getRectangleLabel(initialRect, "initial")}
5877
</div>
5978
<div
60-
className="font-medium px-2 py-1 rounded"
79+
className="font-medium px-2 py-1 rounded whitespace-nowrap"
6180
style={{
6281
fontSize: `${fontSize}px`,
6382
color: "rgb(59, 130, 246)",
@@ -91,13 +110,16 @@ function createSingleRectangleOverlay(
91110

92111
const width = (rect.x_range.end - rect.x_range.start) * cellSize;
93112
const height = (rect.y_range.end - rect.y_range.start) * cellSize;
94-
const fontSize = Math.max(11, Math.min(14, Math.min(width, height) / 10));
113+
const fontSize = Math.max(11, Math.min(16, Math.min(width, height) / 8));
95114
const label = getRectangleLabel(rect, type);
96115

116+
// Determine if the area is too small for text inside
117+
const isSmallArea = width < 100 || height < 40;
118+
97119
return (
98120
<div
99121
key={`${type}-rect-${index}`}
100-
className="absolute pointer-events-none flex items-end justify-end"
122+
className="absolute pointer-events-none"
101123
style={{
102124
left: rect.x_range.start * cellSize,
103125
top: rect.y_range.start * cellSize,
@@ -106,13 +128,26 @@ function createSingleRectangleOverlay(
106128
border: `2px dashed rgba(${color}, 0.5)`,
107129
backgroundColor: `rgba(${color}, 0.06)`,
108130
borderRadius: "6px",
109-
zIndex: 10,
110-
padding: "8px",
131+
zIndex: 1000,
111132
}}
112133
>
134+
{/* Text label */}
113135
<div
114-
className="font-medium px-2 py-1 rounded"
136+
className="font-medium px-2 py-1 rounded whitespace-nowrap"
115137
style={{
138+
position: "absolute",
139+
...(isSmallArea
140+
? {
141+
// Position above the box when small
142+
bottom: "100%",
143+
left: "0",
144+
marginBottom: "4px",
145+
}
146+
: {
147+
// Position inside the box when large enough
148+
bottom: "8px",
149+
right: "8px",
150+
}),
116151
fontSize: `${fontSize}px`,
117152
color: `rgb(${color})`,
118153
backgroundColor: "rgba(255, 255, 255, 0.95)",
@@ -178,7 +213,10 @@ export function RectangleOverlays({
178213
}, [initialConditions, finalConditions, cellSize]);
179214

180215
return (
181-
<div className="absolute inset-0 pointer-events-none" style={{ zIndex: 100 }}>
216+
<div
217+
className="absolute inset-0 pointer-events-none overflow-visible"
218+
style={{ zIndex: 1000 }}
219+
>
182220
{rectangleOverlays}
183221
</div>
184222
);

0 commit comments

Comments
 (0)