Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the component event handling system to replace the monolithic Component::on_event method with opt-in per-category event handlers and introduces EventMask for efficient O(1) event filtering. The changes reduce boilerplate in components and allow the runtime to skip dispatch to components that don't declare interest in specific event categories.
Changes:
- Introduced
EventMaskbitmask type with category constants and operations - Replaced
Component::on_eventwithevent_mask()and per-categoryon_*_eventhandlers - Updated
ApplicationRuntimeto filter event dispatch usingEventMask
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
crates/lambda-rs/src/events.rs |
Adds EventMask type with bitmask operations and Events::mask() method |
crates/lambda-rs/src/component.rs |
Removes on_event, adds event_mask() and per-category handlers with default implementations |
crates/lambda-rs/src/runtimes/application.rs |
Implements dispatch filtering logic and adds comprehensive unit tests |
tools/obj_loader/src/main.rs |
Migrates to new event handling API |
crates/lambda-rs/examples/*.rs |
Updates all examples to use new per-category handlers |
docs/tutorials/*.md |
Updates tutorial code examples and documentation to reflect new API |
docs/specs/component-event-handling.md |
New specification document detailing the event handling architecture |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the monolithic
Component::on_evententry point with opt-in per-categoryevent handlers (
on_window_event,on_keyboard_event, etc.) and introduceEventMaskfor O(1) event filtering at the runtime level. This reducesboilerplate pattern matching in components and allows runtimes to skip dispatch
for components that do not declare interest in a given event category.
Related Issues
Changes
EventMaskbitmask type with category constants (WINDOW,KEYBOARD,MOUSE,RUNTIME,COMPONENT) andcontains/unionoperationsEvents::mask()method to map event variants to their categoryComponent::on_eventfrom the public APIComponent::event_mask()with default returningEventMask::NONEon_*_eventhandlers with default no-op implementationsApplicationRuntimeto filter dispatch usingEventMaskdocs/rendering.mdwith new component examplesEventMaskbehavior and runtime dispatch filteringDefaultderive toEventMaskfor convenienceType of Change
Affected Crates
lambda-rslambda-rs-platformlambda-rs-argslambda-rs-loggingChecklist
cargo +nightly fmt --all)cargo clippy --workspace --all-targets -- -D warnings)cargo test --workspace)Testing
Commands run:
cargo build --workspace cargo test --workspace cargo +nightly fmt --all cargo clippy --workspace --all-targets -- -D warningsManual verification steps (if applicable):
cargo run -p lambda-rs --example minimalcargo run -p lambda-rs --example trianglecargo run -p lambda-rs --example reflective_roomreflective_roomexampleScreenshots/Recordings
N/A - No visual changes; API refactor only.
Platform Testing
Additional Notes
Breaking Change Migration
Components must migrate from
on_eventto the new per-category handlers:Before:
After:
Key API Changes
Component::on_event(&mut self, event: Events)Component::event_mask(&self) -> EventMaskComponent::on_window_event(&mut self, event: &WindowEvent)Component::on_keyboard_event(&mut self, event: &Key)Component::on_mouse_event(&mut self, event: &Mouse)Component::on_runtime_event(&mut self, event: &RuntimeEvent)Component::on_component_event(&mut self, event: &ComponentEvent)Performance
event_mask()does not include theevent category, reducing unnecessary handler invocations
EventMaskis au8bitmask with#[repr(transparent)], ensuring minimaloverhead for the filtering check