Repository navigation
Commit e1561a7
UI: a panel widget, and a border that stays inside the box it was given (#1740)
`UIPanel` is a rectangular surface with a background, an optional border and
children: the thing every menu, dialog and HUD frame starts by writing by
hand. One example in this repository had three of them, each repeating the
same half dozen renderer calls and the same correction for the way
`setColor` folds a colour's own alpha into the global one. That correction
is why this is a widget rather than a snippet: leaving it out does not fail,
it renders the panel at the wrong opacity.
It is a `UIBaseElement`, so children are positioned relative to it and are
asked about a click before it is, and `blocking` decides whether a click
that misses every child is swallowed rather than reaching the game beneath.
`bobAmplitude` / `bobPeriod` give it the slow float an idle dialogue or
pause panel usually has. The offset goes into `getAbsolutePosition()`, which
is the one hook both bounds paths funnel through, so the panel is clickable
WHERE IT IS DRAWN and so is every widget inside it, at any depth. `pos` is
left alone, so a caller still reads and writes the resting place rather than
a value that moves under them. `currentTransform` was the obvious route and
is a dead end: it reaches a renderable's own bounds but not its children's,
so a bobbing panel's swallow rectangle would drift off the widgets sitting
in it.
`ProgressBar` and `UIPanel` now share the shape and colour plumbing, which
is how the border came to be drawn two different ways in two widgets that
look the same. Two shipped `ProgressBar` defects go with it:
- Its border was centred on the bar's own edge, so half of it fell outside
the width and height the bar was given and painted over its neighbour,
while `getBounds()` knew nothing about those pixels. A square border is
four fills tiling the frame exactly; a rounded one is stroked on a path
inset by half the border width with its radius pulled in to match. This
also fixes a square border at the default width of 1 losing all four
corners, since the renderers only generate corner joins above a line
width of one.
- Destroying one twice threw `Instance is already in pool.` It handed its
cached colour back without clearing the handle, and a pool refuses a
double release.
The bob offset is rounded, which is not cosmetic: the renderers snap a
translation with `|0`, truncating toward zero, so an amplitude of 3 moved
4px instead of 6 and spent half the cycle parked at the extremes. Handing
the renderer a whole number makes its own snap a no-op, and makes the drawn
position and the hit area agree exactly.
Closes part 4 of #1722.
Claude-Session: https://claude.ai/code/session_01NGvtaUNATVCVxD2qcbiY4t
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>1 parent 454a89e commit e1561a7
9 files changed
Lines changed: 1598 additions & 143 deletions
File tree
- packages/melonjs
- skills/melonjs-ui-and-text
- src
- renderable/ui
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| 44 | + | |
| 45 | + | |
43 | 46 | | |
44 | 47 | | |
45 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | | - | |
208 | | - | |
209 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
210 | 211 | | |
211 | 212 | | |
212 | 213 | | |
| |||
294 | 295 | | |
295 | 296 | | |
296 | 297 | | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
297 | 380 | | |
298 | 381 | | |
299 | 382 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
194 | 195 | | |
195 | 196 | | |
196 | 197 | | |
| 198 | + | |
197 | 199 | | |
198 | 200 | | |
199 | 201 | | |
| |||
301 | 303 | | |
302 | 304 | | |
303 | 305 | | |
| 306 | + | |
304 | 307 | | |
305 | 308 | | |
306 | 309 | | |
| |||
0 commit comments