Skip to content

Commit aaa7eda

Browse files
authored
Code cleanup
Code cleanup
1 parent 30c29f0 commit aaa7eda

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

egui-opengl-internal/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ default-target = "x86_64-pc-windows-msvc"
1414
targets = ["i686-pc-windows-msvc", "x86_64-pc-windows-msvc"]
1515

1616
[dependencies]
17+
#egui = "0.27.2"
1718
egui = "0.28.1"
1819
gl = "0.14.0"
1920
spin = { version = "0.9.8", optional = true, features = ["lock_api"] }

egui-opengl-internal/src/app.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ pub struct OpenGLApp<T = ()> {
4141
hwnd: OnceCell<HWND>,
4242
}
4343

44+
impl<T> Default for OpenGLApp<T> {
45+
fn default() -> Self {
46+
Self::new()
47+
}
48+
}
49+
50+
51+
4452
impl<T> OpenGLApp<T> {
4553
/// Creates new [`OpenGLApp`] in const context. You are supposed to create a single static item to store the application state.
4654
pub const fn new() -> Self {
@@ -155,7 +163,7 @@ impl<T: Default> OpenGLApp<T> {
155163

156164
impl<T> OpenGLApp<T> {
157165
/// Present call. Should be called once per original present call, before or inside of hook.
158-
#[allow(clippy::cast_ref_to_mut)]
166+
#[allow(invalid_reference_casting)]
159167
pub fn render(&self, hdc: HDC) {
160168
unsafe {
161169
let this = &mut *self.lock_data();

egui-opengl-internal/src/input.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,9 @@ fn get_key_modifiers(msg: u32) -> Modifiers {
350350

351351
fn get_key(wparam: usize) -> Option<Key> {
352352
match wparam {
353-
0x30..=0x39 => unsafe { Some(std::mem::transmute::<_, Key>(wparam as u8 - 0x10)) }, // 0-9
354-
0x41..=0x5A => unsafe { Some(std::mem::transmute::<_, Key>(wparam as u8 - 0x17)) }, // A-Z
355-
0x70..=0x83 => unsafe { Some(std::mem::transmute::<_, Key>(wparam as u8 - 0x2C)) }, // F1-F20
353+
0x30..=0x39 => unsafe { Some(std::mem::transmute::<u8, Key>(wparam as u8 - 0x10)) }, // 0-9
354+
0x41..=0x5A => unsafe { Some(std::mem::transmute::<u8, Key>(wparam as u8 - 0x17)) }, // A-Z
355+
0x70..=0x83 => unsafe { Some(std::mem::transmute::<u8, Key>(wparam as u8 - 0x2C)) }, // F1-F20
356356
_ => match VIRTUAL_KEY(wparam as u16) {
357357
VK_DOWN => Some(Key::ArrowDown),
358358
VK_LEFT => Some(Key::ArrowLeft),

egui-opengl-internal/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn get_module(module_name: &str) -> HMODULE {
4141
module
4242
} else {
4343
// this also shouldn't silently error
44-
HMODULE(0 as *mut c_void)
44+
HMODULE(std::ptr::null_mut::<c_void>())
4545
}
4646
}
4747
}

example-wnd/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ extern "system" fn DllMain(hinst: usize, reason: u32, _reserved: *mut c_void) ->
4747
unsafe {
4848
WglSwapBuffersHook.disable().unwrap();
4949
let wnd_proc = OLD_WND_PROC.unwrap().unwrap();
50-
let _: Option<WNDPROC> = Some(transmute(SetWindowLongPtrA(
50+
let _: Option<WNDPROC> = Some(transmute::<i32,
51+
Option<unsafe extern "system"
52+
fn(HWND, u32, WPARAM, LPARAM) -> LRESULT>>(
53+
SetWindowLongPtrA(
5154
APP.get_window(),
5255
GWLP_WNDPROC,
5356
wnd_proc as usize as _,
@@ -80,7 +83,9 @@ fn hk_wgl_swap_buffers(hdc: HDC) -> HRESULT {
8083

8184
APP.init_default(hdc, window, ui);
8285

83-
OLD_WND_PROC = Some(transmute(SetWindowLongPtrA(
86+
OLD_WND_PROC = Some(transmute::<i32, Option<unsafe extern "system"
87+
fn(HWND, u32, WPARAM, LPARAM) -> LRESULT>>(
88+
SetWindowLongPtrA(
8489
window,
8590
GWLP_WNDPROC,
8691
hk_wnd_proc as usize as _,

0 commit comments

Comments
 (0)