Skip to content

Commit 5fe0304

Browse files
committed
[add] mouse input support for the application runtime.
1 parent 17d092f commit 5fe0304

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

crates/lambda-rs-platform/src/shaderc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl ShaderCompilerBuilder {
1616
let compiler =
1717
shaderc::Compiler::new().expect("Failed to create shaderc compiler.");
1818

19-
let mut options = shaderc::CompileOptions::new()
19+
let options = shaderc::CompileOptions::new()
2020
.expect("Failed to create shaderc compile options.");
2121

2222
return ShaderCompiler {

crates/lambda-rs-platform/src/winit/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub mod winit_exports {
2525
event::{
2626
ElementState,
2727
Event,
28+
MouseButton,
2829
VirtualKeyCode,
2930
WindowEvent,
3031
},

crates/lambda-rs/src/events.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,20 @@ pub enum KeyEvent {
4141
},
4242
}
4343

44+
#[derive(Debug, Clone)]
45+
pub enum Button {
46+
Left,
47+
Right,
48+
Middle,
49+
Other(u16),
50+
}
51+
4452
#[derive(Debug, Clone)]
4553
pub enum Mouse {
4654
Moved { x: f64, y: f64, dx: f64, dy: f64 },
4755
WheelPressed { x: f64, y: f64, button: u32 },
48-
Pressed { x: f64, y: f64, button: u32 },
49-
Released { x: f64, y: f64, button: u32 },
56+
Pressed { x: f64, y: f64, button: Button },
57+
Released { x: f64, y: f64, button: Button },
5058
}
5159

5260
/// Generic Event Enum which encapsulates all possible events that will be

crates/lambda-rs/src/runtimes/application.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use lambda_platform::winit::{
88
winit_exports::{
99
ElementState,
1010
Event as WinitEvent,
11+
MouseButton,
1112
WindowEvent as WinitWindowEvent,
1213
},
1314
Loop,
@@ -18,6 +19,7 @@ use crate::{
1819
component::Component,
1920
core::runtime::Runtime,
2021
events::{
22+
Button,
2123
ComponentEvent,
2224
Events,
2325
KeyEvent,
@@ -257,14 +259,22 @@ impl Runtime for ApplicationRuntime {
257259
button,
258260
modifiers,
259261
} => {
262+
263+
let button = match button {
264+
MouseButton::Left => Button::Left,
265+
MouseButton::Right => Button::Right,
266+
MouseButton::Middle => Button::Middle,
267+
MouseButton::Other(other) => Button::Other(other),
268+
};
269+
260270
let event = match state {
261271
ElementState::Pressed => Mouse::Pressed {
262-
button: button.clone(),
272+
button,
263273
x: 0.0,
264274
y: 0.0,
265275
},
266276
ElementState::Released => Mouse::Released {
267-
button: button.into(),
277+
button,
268278
x: 0.0,
269279
y: 0.0
270280
},

0 commit comments

Comments
 (0)