Skip to content

Commit f005070

Browse files
committed
[update] documentation.
1 parent c18f402 commit f005070

File tree

3 files changed

+141
-9
lines changed

3 files changed

+141
-9
lines changed

docs/tutorials/basic-triangle.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ document_id: "basic-triangle-tutorial-2025-12-16"
44
status: "draft"
55
created: "2025-12-16T00:00:00Z"
66
last_updated: "2026-01-16T00:00:00Z"
7-
version: "0.2.1"
7+
version: "0.2.3"
88
engine_workspace_version: "2023.1.30"
99
wgpu_version: "28.0.0"
1010
shader_backend_default: "naga"
1111
winit_version: "0.29.10"
12-
repo_commit: "9435ad1491b5930054117406abe08dd1c37f2102"
12+
repo_commit: "87aa423aca541823f271101e5bac390f5ca54c42"
1313
owners: ["lambda-sh"]
1414
reviewers: ["engine", "rendering"]
1515
tags: ["tutorial", "graphics", "triangle", "rust", "wgpu"]
@@ -189,6 +189,28 @@ stored dimensions.
189189
The viewport and scissor MUST match the surface dimensions to avoid clipping or
190190
undefined behavior when the window resizes.
191191

192+
Implement resize handling using `event_mask()` and `on_window_event`.
193+
194+
```rust
195+
use lambda::events::{EventMask, WindowEvent};
196+
197+
// Inside `impl Component<ComponentResult, String> for DemoComponent`.
198+
fn event_mask(&self) -> EventMask {
199+
return EventMask::WINDOW;
200+
}
201+
202+
fn on_window_event(&mut self, event: &WindowEvent) -> Result<(), String> {
203+
if let WindowEvent::Resize { width, height } = event {
204+
self.width = *width;
205+
self.height = *height;
206+
}
207+
return Ok(());
208+
}
209+
```
210+
211+
This setup ensures the runtime only dispatches window events to the component,
212+
and the component keeps a current width/height for viewport creation.
213+
192214
## Validation <a name="validation"></a>
193215

194216
- Build: `cargo build --workspace`
@@ -232,7 +254,9 @@ shaders, build a render pass and pipeline, and issue a draw using
232254

233255
## Changelog <a name="changelog"></a>
234256

235-
- 0.2.1 (2026-01-16): Replace deprecated `on_event` references with granular handlers.
257+
- 0.2.3 (2026-01-16): Normalize event handler terminology.
258+
- 0.2.2 (2026-01-16): Add `event_mask()` and `on_window_event` resize example.
259+
- 0.2.1 (2026-01-16): Replace deprecated `on_event` references with per-category handlers.
236260
- 0.2.0 (2026-01-05): Update for wgpu v28; rename push constants to immediates in exercises.
237261
- 0.1.0 (2025-12-16): Initial draft aligned with
238262
`crates/lambda-rs/examples/triangle.rs`.

docs/tutorials/immediates-multiple-triangles.md

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ title: "Immediates: Draw Multiple 2D Triangles"
33
document_id: "immediates-multiple-triangles-tutorial-2025-12-16"
44
status: "draft"
55
created: "2025-12-16T00:00:00Z"
6-
last_updated: "2026-01-07T00:00:00Z"
7-
version: "0.2.1"
6+
last_updated: "2026-01-16T00:00:00Z"
7+
version: "0.2.3"
88
engine_workspace_version: "2023.1.30"
99
wgpu_version: "28.0.0"
1010
shader_backend_default: "naga"
1111
winit_version: "0.29.10"
12-
repo_commit: "183a0499250a2c16e0a09b22107201720016fc48"
12+
repo_commit: "87aa423aca541823f271101e5bac390f5ca54c42"
1313
owners: ["lambda-sh"]
1414
reviewers: ["engine", "rendering"]
1515
tags: ["tutorial", "graphics", "immediates", "triangle", "rust", "wgpu"]
@@ -172,6 +172,60 @@ Update component state from events:
172172

173173
These updates are reflected on the next `on_render` call.
174174

175+
Implement input and resize handling using `event_mask()` and `on_*_event`
176+
handlers.
177+
178+
```rust
179+
use lambda::events::{EventMask, Key, VirtualKey, WindowEvent};
180+
181+
// Inside `impl Component<ComponentResult, String> for TrianglesExample`.
182+
fn event_mask(&self) -> EventMask {
183+
return EventMask::WINDOW | EventMask::KEYBOARD;
184+
}
185+
186+
fn on_window_event(&mut self, event: &WindowEvent) -> Result<(), String> {
187+
if let WindowEvent::Resize { width, height } = event {
188+
self.width = *width;
189+
self.height = *height;
190+
}
191+
return Ok(());
192+
}
193+
194+
fn on_keyboard_event(&mut self, event: &Key) -> Result<(), String> {
195+
match event {
196+
Key::Pressed {
197+
scan_code: _,
198+
virtual_key: Some(VirtualKey::KeyW),
199+
} => {
200+
self.position.1 -= 0.01;
201+
}
202+
Key::Pressed {
203+
scan_code: _,
204+
virtual_key: Some(VirtualKey::KeyS),
205+
} => {
206+
self.position.1 += 0.01;
207+
}
208+
Key::Pressed {
209+
scan_code: _,
210+
virtual_key: Some(VirtualKey::KeyA),
211+
} => {
212+
self.position.0 -= 0.01;
213+
}
214+
Key::Pressed {
215+
scan_code: _,
216+
virtual_key: Some(VirtualKey::KeyD),
217+
} => {
218+
self.position.0 += 0.01;
219+
}
220+
_ => {}
221+
}
222+
return Ok(());
223+
}
224+
```
225+
226+
This setup declares interest in window and keyboard categories and avoids
227+
per-component pattern matching over the full `Events` enum.
228+
175229
## Validation <a name="validation"></a>
176230

177231
- Build: `cargo build --workspace`
@@ -219,6 +273,8 @@ issuing repeated draws within one render pass.
219273

220274
## Changelog <a name="changelog"></a>
221275

276+
- 0.2.3 (2026-01-16): Normalize event handler terminology.
277+
- 0.2.2 (2026-01-16): Add `event_mask()` and `on_*_event` handler examples.
222278
- 0.2.1 (2026-01-07): Remove stage usage from immediates API examples.
223279
- 0.2.0 (2026-01-05): Updated to use wgpu v28 immediates terminology.
224280
- 0.1.0 (2025-12-16): Initial draft aligned with

docs/tutorials/reflective-room.md

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ title: "Reflective Floor: Stencil‑Masked Planar Reflections"
33
document_id: "reflective-room-tutorial-2025-11-17"
44
status: "draft"
55
created: "2025-11-17T00:00:00Z"
6-
last_updated: "2026-01-07T00:00:00Z"
7-
version: "0.4.1"
6+
last_updated: "2026-01-16T00:00:00Z"
7+
version: "0.4.3"
88
engine_workspace_version: "2023.1.30"
99
wgpu_version: "28.0.0"
1010
shader_backend_default: "naga"
1111
winit_version: "0.29.10"
12-
repo_commit: "183a0499250a2c16e0a09b22107201720016fc48"
12+
repo_commit: "87aa423aca541823f271101e5bac390f5ca54c42"
1313
owners: ["lambda-sh"]
1414
reviewers: ["engine", "rendering"]
1515
tags: ["tutorial", "graphics", "stencil", "depth", "msaa", "mirror", "3d", "immediates", "wgpu", "rust"]
@@ -434,6 +434,56 @@ Support runtime toggles to observe the impact of each setting:
434434

435435
Reference: `crates/lambda-rs/examples/reflective_room.rs:164`.
436436

437+
Implement resize and toggles using `event_mask()` and `on_*_event` handlers.
438+
439+
```rust
440+
use lambda::events::{EventMask, Key, VirtualKey, WindowEvent};
441+
442+
// Inside `impl Component<ComponentResult, String> for ReflectiveRoomExample`.
443+
fn event_mask(&self) -> EventMask {
444+
return EventMask::WINDOW | EventMask::KEYBOARD;
445+
}
446+
447+
fn on_window_event(&mut self, event: &WindowEvent) -> Result<(), String> {
448+
if let WindowEvent::Resize { width, height } = event {
449+
self.width = *width;
450+
self.height = *height;
451+
}
452+
return Ok(());
453+
}
454+
455+
fn on_keyboard_event(&mut self, event: &Key) -> Result<(), String> {
456+
match event {
457+
Key::Pressed {
458+
scan_code: _,
459+
virtual_key: Some(VirtualKey::KeyM),
460+
} => {
461+
self.msaa_samples = if self.msaa_samples > 1 { 1 } else { 4 };
462+
self.needs_rebuild = true;
463+
}
464+
Key::Pressed {
465+
scan_code: _,
466+
virtual_key: Some(VirtualKey::KeyS),
467+
} => {
468+
self.stencil_enabled = !self.stencil_enabled;
469+
self.needs_rebuild = true;
470+
}
471+
Key::Pressed {
472+
scan_code: _,
473+
virtual_key: Some(VirtualKey::KeyD),
474+
} => {
475+
self.depth_test_enabled = !self.depth_test_enabled;
476+
self.needs_rebuild = true;
477+
}
478+
_ => {}
479+
}
480+
return Ok(());
481+
}
482+
```
483+
484+
When a toggle flips, set `needs_rebuild = true` so pipelines and passes are
485+
rebuilt on the next frame with the updated MSAA/depth/stencil settings.
486+
437487
## Validation <a name="validation"></a>
438488

439489
- Build and run: `cargo run --example reflective_room`.
@@ -477,6 +527,8 @@ The reflective floor combines a simple stencil mask with an optional depth test
477527

478528
## Changelog <a name="changelog"></a>
479529

530+
- 2026-01-16, 0.4.3: Normalize event handler terminology.
531+
- 2026-01-16, 0.4.2: Add `event_mask()` and `on_*_event` handler examples.
480532
- 2026-01-07, 0.4.1: Remove stage usage from immediates API examples.
481533
- 2026-01-05, 0.4.0: Update for wgpu v28; rename push constants to immediates; update struct references to `ImmediateData`.
482534
- 2025-12-15, 0.3.0: Update builder API calls to use `ctx.gpu()` and add `surface_format`/`depth_format` parameters to `RenderPassBuilder` and `RenderPipelineBuilder`.

0 commit comments

Comments
 (0)