Skip to content

Commit

Permalink
Fix deprecated shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
eerii committed Feb 14, 2024
1 parent 886395c commit e7701ac
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 63 deletions.
4 changes: 2 additions & 2 deletions examples/render_to_image_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn setup(
egui_user_textures.add_image(image_handle.clone());
commands.insert_resource(CubePreviewImage(image_handle.clone()));

let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 4.0 }));
let cube_handle = meshes.add(Mesh::from(Cuboid::new(4.0, 4.0, 4.0)));
let default_material = StandardMaterial {
base_color: Color::rgb(0.8, 0.7, 0.6),
reflectance: 0.02,
Expand Down Expand Up @@ -115,7 +115,7 @@ fn setup(
.insert(preview_pass_layer);

let cube_size = 4.0;
let cube_handle = meshes.add(Mesh::from(shape::Box::new(cube_size, cube_size, cube_size)));
let cube_handle = meshes.add(Mesh::from(Cuboid::new(cube_size, cube_size, cube_size)));

let main_material_handle = materials.add(default_material);

Expand Down
7 changes: 2 additions & 5 deletions examples/side_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,12 @@ fn setup_system(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane {
size: 5.0,
subdivisions: 0,
})),
mesh: meshes.add(Mesh::from(Plane3d::default().mesh().size(5.0, 5.0))),
material: materials.add(Color::rgb(0.3, 0.5, 0.3)),
..Default::default()
});
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
mesh: meshes.add(Mesh::from(Cuboid::new(1.0, 1.0, 1.0))),
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..Default::default()
Expand Down
114 changes: 58 additions & 56 deletions src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bevy::{
system::{Local, Res, ResMut, SystemParam},
},
input::{
keyboard::{KeyCode, KeyboardInput},
keyboard::{Key, KeyCode, KeyboardInput},
mouse::{MouseButton, MouseButtonInput, MouseScrollUnit, MouseWheel},
touch::TouchInput,
ButtonInput, ButtonState,
Expand Down Expand Up @@ -244,7 +244,7 @@ pub fn process_input_system(
})
{
for ev in input_events.ev_keyboard_input.read() {
if let Some(key) = bevy_to_egui_key(ev.key_code) {
if let Some(key) = bevy_to_egui_key(&ev.logical_key) {
let pressed = match ev.state {
ButtonState::Pressed => true,
ButtonState::Released => false,
Expand Down Expand Up @@ -524,60 +524,62 @@ fn egui_to_winit_cursor_icon(cursor_icon: egui::CursorIcon) -> Option<bevy::wind
}
}

fn bevy_to_egui_key(key_code: KeyCode) -> Option<egui::Key> {
let key = match key_code {
KeyCode::ArrowDown => egui::Key::ArrowDown,
KeyCode::ArrowLeft => egui::Key::ArrowLeft,
KeyCode::ArrowRight => egui::Key::ArrowRight,
KeyCode::ArrowUp => egui::Key::ArrowUp,
KeyCode::Escape => egui::Key::Escape,
KeyCode::Tab => egui::Key::Tab,
KeyCode::Backspace => egui::Key::Backspace,
KeyCode::Enter => egui::Key::Enter,
KeyCode::NumpadEnter => egui::Key::Enter,
KeyCode::Space => egui::Key::Space,
KeyCode::Insert => egui::Key::Insert,
KeyCode::Delete => egui::Key::Delete,
KeyCode::Home => egui::Key::Home,
KeyCode::End => egui::Key::End,
KeyCode::PageUp => egui::Key::PageUp,
KeyCode::PageDown => egui::Key::PageDown,
KeyCode::Numpad0 | KeyCode::Digit0 => egui::Key::Num0,
KeyCode::Numpad1 | KeyCode::Digit1 => egui::Key::Num1,
KeyCode::Numpad2 | KeyCode::Digit2 => egui::Key::Num2,
KeyCode::Numpad3 | KeyCode::Digit3 => egui::Key::Num3,
KeyCode::Numpad4 | KeyCode::Digit4 => egui::Key::Num4,
KeyCode::Numpad5 | KeyCode::Digit5 => egui::Key::Num5,
KeyCode::Numpad6 | KeyCode::Digit6 => egui::Key::Num6,
KeyCode::Numpad7 | KeyCode::Digit7 => egui::Key::Num7,
KeyCode::Numpad8 | KeyCode::Digit8 => egui::Key::Num8,
KeyCode::Numpad9 | KeyCode::Digit9 => egui::Key::Num9,
KeyCode::KeyA => egui::Key::A,
KeyCode::KeyB => egui::Key::B,
KeyCode::KeyC => egui::Key::C,
KeyCode::KeyD => egui::Key::D,
KeyCode::KeyE => egui::Key::E,
KeyCode::KeyF => egui::Key::F,
KeyCode::KeyG => egui::Key::G,
KeyCode::KeyH => egui::Key::H,
KeyCode::KeyI => egui::Key::I,
KeyCode::KeyJ => egui::Key::J,
KeyCode::KeyK => egui::Key::K,
KeyCode::KeyL => egui::Key::L,
KeyCode::KeyM => egui::Key::M,
KeyCode::KeyN => egui::Key::N,
KeyCode::KeyO => egui::Key::O,
KeyCode::KeyP => egui::Key::P,
KeyCode::KeyQ => egui::Key::Q,
KeyCode::KeyR => egui::Key::R,
KeyCode::KeyS => egui::Key::S,
KeyCode::KeyT => egui::Key::T,
KeyCode::KeyU => egui::Key::U,
KeyCode::KeyV => egui::Key::V,
KeyCode::KeyW => egui::Key::W,
KeyCode::KeyX => egui::Key::X,
KeyCode::KeyY => egui::Key::Y,
KeyCode::KeyZ => egui::Key::Z,
fn bevy_to_egui_key(key: &Key) -> Option<egui::Key> {
let key = match key {
Key::ArrowDown => egui::Key::ArrowDown,
Key::ArrowLeft => egui::Key::ArrowLeft,
Key::ArrowRight => egui::Key::ArrowRight,
Key::ArrowUp => egui::Key::ArrowUp,
Key::Escape => egui::Key::Escape,
Key::Tab => egui::Key::Tab,
Key::Backspace => egui::Key::Backspace,
Key::Enter => egui::Key::Enter,
Key::Space => egui::Key::Space,
Key::Insert => egui::Key::Insert,
Key::Delete => egui::Key::Delete,
Key::Home => egui::Key::Home,
Key::End => egui::Key::End,
Key::PageUp => egui::Key::PageUp,
Key::PageDown => egui::Key::PageDown,
Key::Character(c) => match c.to_string().to_lowercase().as_str() {
"0" => egui::Key::Num0,
"1" => egui::Key::Num1,
"2" => egui::Key::Num2,
"3" => egui::Key::Num3,
"4" => egui::Key::Num4,
"5" => egui::Key::Num5,
"6" => egui::Key::Num6,
"7" => egui::Key::Num7,
"8" => egui::Key::Num8,
"9" => egui::Key::Num9,
"a" => egui::Key::A,
"b" => egui::Key::B,
"c" => egui::Key::C,
"d" => egui::Key::D,
"e" => egui::Key::E,
"f" => egui::Key::F,
"g" => egui::Key::G,
"h" => egui::Key::H,
"i" => egui::Key::I,
"j" => egui::Key::J,
"k" => egui::Key::K,
"l" => egui::Key::L,
"m" => egui::Key::M,
"n" => egui::Key::N,
"o" => egui::Key::O,
"p" => egui::Key::P,
"q" => egui::Key::Q,
"r" => egui::Key::R,
"s" => egui::Key::S,
"t" => egui::Key::T,
"u" => egui::Key::U,
"v" => egui::Key::V,
"w" => egui::Key::W,
"x" => egui::Key::X,
"y" => egui::Key::Y,
"z" => egui::Key::Z,
_ => return None,
},
_ => return None,
};
Some(key)
Expand Down

0 comments on commit e7701ac

Please sign in to comment.