Skip to content

Commit 754c6ee

Browse files
authored
Merge pull request #16 from gaarutyunov/claude/fix-cube-example-01VhpkmZkoUefZUFknZqaKjP
fix: Fix WebGPU cube example loading and rotation issues
2 parents 9c94470 + 7872d2f commit 754c6ee

14 files changed

Lines changed: 184 additions & 111 deletions

File tree

examples/calculator/calculator_gen.go

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/counter/counter_gen.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/webgpu-cube/app.gx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,23 @@ func App() (Component) {
1717
}()
1818

1919
go func() {
20+
log("[App] Command processing goroutine started")
2021
for cmd := range commands {
2122
log(fmt.Sprintf("[App] Received command: %s", cmd.String()))
2223

2324
switch cmd.Type {
2425
case "rotX":
2526
rotationX += float64(cmd.Value)
27+
log(fmt.Sprintf("[App] Updated rotationX to: %.2f", rotationX))
2628
case "rotY":
2729
rotationY += float64(cmd.Value)
30+
log(fmt.Sprintf("[App] Updated rotationY to: %.2f", rotationY))
2831
case "autoRotate":
2932
autoRotate = !autoRotate
33+
log(fmt.Sprintf("[App] Toggled autoRotate to: %t", autoRotate))
3034
case "speed":
3135
speed = float64(cmd.Value)
36+
log(fmt.Sprintf("[App] Updated speed to: %.2f", speed))
3237
}
3338

3439
state := ControlState{AutoRotate: autoRotate, Speed: float32(speed)}
@@ -39,15 +44,24 @@ func App() (Component) {
3944
log("[App] Channel full, skipping state update")
4045
}
4146
}
47+
log("[App] Command processing goroutine ended")
4248
}()
4349

50+
renderUpdate := func(delta float64, rendererInterface interface{}) {
51+
if autoRotate {
52+
rotationY = rotationY + (delta * speed)
53+
rotationX = rotationX + (delta * speed * 0.5)
54+
}
55+
}
56+
4457
Div(
4558
Class("webgpu-container")
4659
) {
4760
Canvas(
4861
ID("webgpu-canvas"),
49-
Width(600),
50-
Height(400)
62+
Width(500),
63+
Height(375),
64+
GPURenderUpdate(renderUpdate)
5165
) {
5266
GPUScene(NewCubeScene(float32(rotationX), float32(rotationY)))
5367
}

examples/webgpu-cube/app_gen.go

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/webgpu-cube/controls.gx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type ControlState struct {
1515

1616
@props func Controls(commands chan ControlCommand, state chan ControlState) (Component) {
1717
currentState := <-state
18-
log(fmt.Sprintf("[Controls] Received state: %s", currentState.String()))
18+
log(fmt.Sprintf("[Controls] Received initial state: %s", currentState.String()))
1919

2020
Div(ID("controls"), Class("controls-panel")) {
2121
// Arrow buttons
@@ -45,7 +45,11 @@ type ControlState struct {
4545
ID("btn-toggle"),
4646
Class("control-button toggle"),
4747
OnClick(func(e Event) {
48-
commands <- ControlCommand{Type: "autoRotate"}
48+
log("[Controls] Toggle button clicked!")
49+
cmd := ControlCommand{Type: "autoRotate"}
50+
log(fmt.Sprintf("[Controls] Sending command: %s", cmd.String()))
51+
commands <- cmd
52+
log("[Controls] Command sent to channel")
4953
})
5054
) {
5155
if currentState.AutoRotate {

examples/webgpu-cube/controls_gen.go

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/webgpu-cube/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,20 @@
3636
padding: 24px;
3737
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
3838
backdrop-filter: blur(10px);
39+
max-width: 100%;
40+
width: fit-content;
3941
}
4042

4143
canvas {
4244
display: block;
4345
border-radius: 8px;
4446
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
47+
max-width: 100%;
48+
height: auto;
49+
}
50+
51+
.webgpu-container {
52+
max-width: 100%;
4553
}
4654

4755
.loading {
@@ -88,6 +96,8 @@
8896
background: rgba(255, 255, 255, 0.03);
8997
border-radius: 12px;
9098
border: 1px solid rgba(255, 255, 255, 0.1);
99+
position: relative;
100+
z-index: 10;
91101
}
92102

93103
/* Arrow Buttons Layout */
@@ -120,6 +130,9 @@
120130
align-items: center;
121131
justify-content: center;
122132
user-select: none;
133+
pointer-events: auto;
134+
position: relative;
135+
z-index: 1;
123136
}
124137

125138
.control-button:hover {

examples/webgpu-cube/tests/webgpu-cube.spec.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,11 @@ test.describe('WebGPU Rotating Cube', () => {
194194
// Wait for canvas to be rendered
195195
await page.waitForSelector('canvas', { timeout: 5000 });
196196

197-
// Wait for either controls or error to appear
198-
await page.waitForSelector('#btn-toggle, div[style*="background: #ff4444"]', { timeout: 5000 });
197+
// Wait for controls to appear and be fully loaded
198+
await page.waitForSelector('#btn-toggle', { timeout: 5000, state: 'visible' });
199+
200+
// Additional wait for components to be fully interactive
201+
await page.waitForTimeout(500);
199202

200203
// Print all console messages for debugging
201204
console.log('\n=== Console Messages (should respond to button clicks) ===');
@@ -207,22 +210,28 @@ test.describe('WebGPU Rotating Cube', () => {
207210
const errorCount = await errorDivs.count();
208211
expect(errorCount).toBe(0);
209212

210-
// Get initial button text
211-
const toggleButton = await page.locator('#btn-toggle');
213+
// Get toggle button and verify it's visible and enabled
214+
const toggleButton = page.locator('#btn-toggle');
215+
await expect(toggleButton).toBeVisible();
216+
217+
// Scroll button into view to ensure it's clickable
218+
await toggleButton.scrollIntoViewIfNeeded();
219+
await page.waitForTimeout(100);
220+
212221
const initialText = await toggleButton.textContent();
213222
expect(initialText).toBe('⏸'); // Should be pause icon initially
214223

215224
// Click toggle button
216225
await toggleButton.click();
217-
await page.waitForTimeout(100);
226+
await page.waitForTimeout(300);
218227

219228
// Check that button text changed
220229
const newText = await toggleButton.textContent();
221230
expect(newText).toBe('▶'); // Should be play icon now
222231

223232
// Click again to toggle back
224233
await toggleButton.click();
225-
await page.waitForTimeout(100);
234+
await page.waitForTimeout(300);
226235

227236
const finalText = await toggleButton.textContent();
228237
expect(finalText).toBe('⏸'); // Should be pause icon again
@@ -241,8 +250,11 @@ test.describe('WebGPU Rotating Cube', () => {
241250
// Wait for canvas to be rendered
242251
await page.waitForSelector('canvas', { timeout: 5000 });
243252

244-
// Wait for either controls or error to appear
245-
await page.waitForSelector('#speed-control, div[style*="background: #ff4444"]', { timeout: 5000 });
253+
// Wait for speed control to appear
254+
await page.waitForSelector('#speed-control', { timeout: 5000, state: 'visible' });
255+
256+
// Additional wait for full interactivity
257+
await page.waitForTimeout(500);
246258

247259
// Print all console messages for debugging
248260
console.log('\n=== Console Messages (should show speed control when auto-rotate is enabled) ===');
@@ -255,13 +267,16 @@ test.describe('WebGPU Rotating Cube', () => {
255267
expect(errorCount).toBe(0);
256268

257269
// Speed control should be visible initially (auto-rotate is on by default)
258-
const speedControl = await page.locator('#speed-control');
270+
const speedControl = page.locator('#speed-control');
259271
await expect(speedControl).toBeVisible();
260272

261273
// Toggle auto-rotate off
262-
const toggleButton = await page.locator('#btn-toggle');
274+
const toggleButton = page.locator('#btn-toggle');
275+
await expect(toggleButton).toBeVisible();
276+
await toggleButton.scrollIntoViewIfNeeded();
277+
await page.waitForTimeout(100);
263278
await toggleButton.click();
264-
await page.waitForTimeout(200);
279+
await page.waitForTimeout(300);
265280

266281
// Speed control should not be rendered (not in DOM) when auto-rotate is off
267282
const speedControlCount = await page.locator('#speed-control').count();

pkg/ast/ast.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ type Type struct {
8686
IsChannel bool `@("<-")?`
8787
IsChan bool `@("chan")?`
8888
IsSlice bool `@("[" "]")?`
89-
Name string `@Ident`
89+
IsInterface bool `@("interface" "{" "}")?` // Empty interface type
90+
Name string `@Ident?`
9091
Generic *Type `("[" @@ "]")?`
9192
IsPointer bool `@("*")?`
9293
IsFunc bool `@("func")?`

0 commit comments

Comments
 (0)