@@ -29,32 +29,40 @@ export function BouncingBall() {
2929 function render ( t ) {
3030 const dt = ( t - time ) / 10 ;
3131 time = t ;
32-
33- setBallX ( prevX => {
32+
33+ setBallX ( ( prevX ) => {
3434 let newX = prevX + vx . current * dt ;
3535
3636 // Bounce off left/right walls
37- if ( newX - ballRadius <= borderThickness || newX + ballRadius >= contentWidth - borderThickness ) {
37+ if (
38+ newX - ballRadius <= borderThickness ||
39+ newX + ballRadius >= contentWidth - borderThickness
40+ ) {
3841 vx . current = - vx . current ;
3942 // Clamp position to stay within bounds
40- newX = newX - ballRadius <= borderThickness
41- ? borderThickness + ballRadius
42- : contentWidth - borderThickness - ballRadius ;
43+ newX =
44+ newX - ballRadius <= borderThickness
45+ ? borderThickness + ballRadius
46+ : contentWidth - borderThickness - ballRadius ;
4347 }
4448
4549 return newX ;
4650 } ) ;
4751
48- setBallY ( prevY => {
52+ setBallY ( ( prevY ) => {
4953 let newY = prevY + vy . current * dt ;
5054
5155 // Bounce off top/bottom walls
52- if ( newY - ballRadius <= borderThickness || newY + ballRadius >= contentHeight - borderThickness ) {
56+ if (
57+ newY - ballRadius <= borderThickness ||
58+ newY + ballRadius >= contentHeight - borderThickness
59+ ) {
5360 vy . current = - vy . current ;
5461 // Clamp position to stay within bounds
55- newY = newY - ballRadius <= borderThickness
56- ? borderThickness + ballRadius
57- : contentHeight - borderThickness - ballRadius ;
62+ newY =
63+ newY - ballRadius <= borderThickness
64+ ? borderThickness + ballRadius
65+ : contentHeight - borderThickness - ballRadius ;
5866 }
5967
6068 return newY ;
@@ -72,13 +80,47 @@ export function BouncingBall() {
7280 { /* flags=64 is ImGuiWindowFlags_AlwaysAutoResize */ }
7381 < child width = { contentWidth } height = { contentHeight } noPadding noScrollbar >
7482 { /* White borders - top, left, bottom, right */ }
75- < rect x = { 0 } y = { 0 } width = { contentWidth } height = { borderThickness } color = "#FFFFFF" filled />
76- < rect x = { 0 } y = { 0 } width = { borderThickness } height = { contentHeight } color = "#FFFFFF" filled />
77- < rect x = { 0 } y = { contentHeight - borderThickness } width = { contentWidth } height = { borderThickness } color = "#FFFFFF" filled />
78- < rect x = { contentWidth - borderThickness } y = { 0 } width = { borderThickness } height = { contentHeight } color = "#FFFFFF" filled />
83+ < rect
84+ x = { 0 }
85+ y = { 0 }
86+ width = { contentWidth }
87+ height = { borderThickness }
88+ color = "#FFFFFF"
89+ filled
90+ />
91+ < rect
92+ x = { 0 }
93+ y = { 0 }
94+ width = { borderThickness }
95+ height = { contentHeight }
96+ color = "#FFFFFF"
97+ filled
98+ />
99+ < rect
100+ x = { 0 }
101+ y = { contentHeight - borderThickness }
102+ width = { contentWidth }
103+ height = { borderThickness }
104+ color = "#FFFFFF"
105+ filled
106+ />
107+ < rect
108+ x = { contentWidth - borderThickness }
109+ y = { 0 }
110+ width = { borderThickness }
111+ height = { contentHeight }
112+ color = "#FFFFFF"
113+ filled
114+ />
79115
80116 { /* Green bouncing ball */ }
81- < circle x = { ballX } y = { ballY } radius = { ballRadius } color = "#00FF00" filled />
117+ < circle
118+ x = { ballX }
119+ y = { ballY }
120+ radius = { ballRadius }
121+ color = "#00FF00"
122+ filled
123+ />
82124 </ child >
83125 </ window >
84126 ) ;
0 commit comments