Skip to content

Commit

Permalink
Merge pull request #41 from Cobrand/main
Browse files Browse the repository at this point in the history
Update for rust-sdl2 v0.37
  • Loading branch information
ArjunNair authored Jun 14, 2024
2 parents 547045f + 866db39 commit e5a6afb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ include = ["**/*.rs", "Cargo.toml", "/shaders"]
ahash = "~0.8"
gl = "~0.14"
egui = "~0.27"
sdl2 = { version = "~0.36" }
sdl2 = { version = ">= 0.36, < 0.38" }
memoffset = "0.9.0"

[dependencies.epi]
Expand Down
114 changes: 56 additions & 58 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,65 +338,63 @@ pub fn input_to_egui(
}
}

pub fn translate_virtual_key_code(key: sdl2::keyboard::Keycode) -> Option<egui::Key> {
use Keycode::*;

pub fn translate_virtual_key_code(key: Keycode) -> Option<egui::Key> {
Some(match key {
Left => Key::ArrowLeft,
Up => Key::ArrowUp,
Right => Key::ArrowRight,
Down => Key::ArrowDown,

Escape => Key::Escape,
Tab => Key::Tab,
Backspace => Key::Backspace,
Space => Key::Space,
Return => Key::Enter,

Insert => Key::Insert,
Home => Key::Home,
Delete => Key::Delete,
End => Key::End,
PageDown => Key::PageDown,
PageUp => Key::PageUp,

Kp0 | Num0 => Key::Num0,
Kp1 | Num1 => Key::Num1,
Kp2 | Num2 => Key::Num2,
Kp3 | Num3 => Key::Num3,
Kp4 | Num4 => Key::Num4,
Kp5 | Num5 => Key::Num5,
Kp6 | Num6 => Key::Num6,
Kp7 | Num7 => Key::Num7,
Kp8 | Num8 => Key::Num8,
Kp9 | Num9 => Key::Num9,

A => Key::A,
B => Key::B,
C => Key::C,
D => Key::D,
E => Key::E,
F => Key::F,
G => Key::G,
H => Key::H,
I => Key::I,
J => Key::J,
K => Key::K,
L => Key::L,
M => Key::M,
N => Key::N,
O => Key::O,
P => Key::P,
Q => Key::Q,
R => Key::R,
S => Key::S,
T => Key::T,
U => Key::U,
V => Key::V,
W => Key::W,
X => Key::X,
Y => Key::Y,
Z => Key::Z,
Keycode::Left => Key::ArrowLeft,
Keycode::Up => Key::ArrowUp,
Keycode::Right => Key::ArrowRight,
Keycode::Down => Key::ArrowDown,

Keycode::Escape => Key::Escape,
Keycode::Tab => Key::Tab,
Keycode::Backspace => Key::Backspace,
Keycode::Space => Key::Space,
Keycode::Return => Key::Enter,

Keycode::Insert => Key::Insert,
Keycode::Home => Key::Home,
Keycode::Delete => Key::Delete,
Keycode::End => Key::End,
Keycode::PageDown => Key::PageDown,
Keycode::PageUp => Key::PageUp,

Keycode::Kp0 | Keycode::Num0 => Key::Num0,
Keycode::Kp1 | Keycode::Num1 => Key::Num1,
Keycode::Kp2 | Keycode::Num2 => Key::Num2,
Keycode::Kp3 | Keycode::Num3 => Key::Num3,
Keycode::Kp4 | Keycode::Num4 => Key::Num4,
Keycode::Kp5 | Keycode::Num5 => Key::Num5,
Keycode::Kp6 | Keycode::Num6 => Key::Num6,
Keycode::Kp7 | Keycode::Num7 => Key::Num7,
Keycode::Kp8 | Keycode::Num8 => Key::Num8,
Keycode::Kp9 | Keycode::Num9 => Key::Num9,

Keycode::A => Key::A,
Keycode::B => Key::B,
Keycode::C => Key::C,
Keycode::D => Key::D,
Keycode::E => Key::E,
Keycode::F => Key::F,
Keycode::G => Key::G,
Keycode::H => Key::H,
Keycode::I => Key::I,
Keycode::J => Key::J,
Keycode::K => Key::K,
Keycode::L => Key::L,
Keycode::M => Key::M,
Keycode::N => Key::N,
Keycode::O => Key::O,
Keycode::P => Key::P,
Keycode::Q => Key::Q,
Keycode::R => Key::R,
Keycode::S => Key::S,
Keycode::T => Key::T,
Keycode::U => Key::U,
Keycode::V => Key::V,
Keycode::W => Key::W,
Keycode::X => Key::X,
Keycode::Y => Key::Y,
Keycode::Z => Key::Z,

_ => {
return None;
Expand Down

0 comments on commit e5a6afb

Please sign in to comment.