1- use egui:: { Color32 , Context , Key , Modifiers , RichText , ScrollArea , Slider , Widget } ;
2- use egui_opengl_internal:: { utils, OpenGLApp } ;
3- use retour:: static_detour;
41use std:: { intrinsics:: transmute, sync:: Once } ;
52use std:: ffi:: c_void;
3+ use std:: ops:: DerefMut ;
4+ use std:: sync:: { Arc , Mutex } ;
5+
6+ use egui:: { Color32 , Context , Key , Modifiers , RichText , ScrollArea , Slider , Widget } ;
7+ use once_cell:: unsync:: Lazy ;
8+ use retour:: static_detour;
69use windows:: {
710 core:: HRESULT ,
811 Win32 :: {
912 Foundation :: { HWND , LPARAM , LRESULT , WPARAM } ,
10- Graphics :: Gdi :: { WindowFromDC , HDC } ,
11- UI :: WindowsAndMessaging :: { CallWindowProcW , SetWindowLongPtrA , GWLP_WNDPROC , WNDPROC } ,
13+ Graphics :: Gdi :: { HDC , WindowFromDC } ,
14+ UI :: WindowsAndMessaging :: { CallWindowProcW , GWLP_WNDPROC , WNDPROC } ,
1215 } ,
1316} ;
1417use windows:: Win32 :: Foundation :: { BOOL , TRUE } ;
18+ use windows:: Win32 :: UI :: WindowsAndMessaging :: SetWindowLongPtrW ;
1519
16- use std:: sync:: { Arc , Mutex } ;
17- use once_cell:: unsync:: Lazy ;
20+ use egui_opengl_internal:: { OpenGLApp , utils} ;
1821
1922struct UIState {
2023 ui_check : bool ,
21- text : Option < String > ,
24+ text : String ,
2225 value : f32 ,
2326 color : [ f32 ; 3 ] ,
2427}
@@ -27,7 +30,7 @@ impl UIState {
2730 fn new ( ) -> Self {
2831 Self {
2932 ui_check : true ,
30- text : Some ( String :: from ( "Test" ) ) ,
33+ text : String :: from ( "Test" ) ,
3134 value : 0.0 ,
3235 color : [ 0.0 , 0.0 , 0.0 ] ,
3336 }
@@ -50,7 +53,7 @@ extern "system" fn DllMain(hinst: usize, reason: u32, _reserved: *mut c_void) ->
5053 let _: Option < WNDPROC > = Some ( transmute :: < i32 ,
5154 Option < unsafe extern "system"
5255 fn ( HWND , u32 , WPARAM , LPARAM ) -> LRESULT > > (
53- SetWindowLongPtrA (
56+ SetWindowLongPtrW (
5457 APP . get_window ( ) ,
5558 GWLP_WNDPROC ,
5659 wnd_proc as usize as _ ,
@@ -85,15 +88,15 @@ fn hk_wgl_swap_buffers(hdc: HDC) -> HRESULT {
8588
8689 OLD_WND_PROC = Some ( transmute :: < i32 , Option < unsafe extern "system"
8790 fn ( HWND , u32 , WPARAM , LPARAM ) -> LRESULT > > (
88- SetWindowLongPtrA (
91+ SetWindowLongPtrW (
8992 window,
9093 GWLP_WNDPROC ,
9194 hk_wnd_proc as usize as _ ,
9295 ) ) ) ;
9396 } ) ;
9497
9598 if !APP . get_window ( ) . eq ( & window) {
96- SetWindowLongPtrA ( window, GWLP_WNDPROC , hk_wnd_proc as usize as _ ) ;
99+ SetWindowLongPtrW ( window, GWLP_WNDPROC , hk_wnd_proc as usize as _ ) ;
97100 }
98101
99102 APP . render ( hdc) ;
@@ -137,7 +140,7 @@ unsafe fn main_thread(_hinst: usize) {
137140 utils:: alloc_console ( ) ;
138141
139142 let wgl_swap_buffers = utils:: get_proc_address ( "wglSwapBuffers" ) ;
140- let fn_wgl_swap_buffers: FnWglSwapBuffers = std :: mem :: transmute ( wgl_swap_buffers) ;
143+ let fn_wgl_swap_buffers: FnWglSwapBuffers = transmute ( wgl_swap_buffers) ;
141144
142145 println ! ( "wglSwapBuffers: {:X}" , wgl_swap_buffers as usize ) ;
143146
@@ -153,7 +156,7 @@ unsafe fn main_thread(_hinst: usize) {
153156}
154157
155158unsafe fn test_ui ( ctx : & Context , ui : & mut egui:: Ui ) {
156- let mut state = STATE . lock ( ) . unwrap ( ) ; // Lock the state
159+ let state = STATE . as_ref ( ) ;
157160
158161 // UI Elements
159162 ui. label ( RichText :: new ( "Test" ) . color ( Color32 :: LIGHT_BLUE ) ) ;
@@ -178,8 +181,15 @@ unsafe fn test_ui(ctx: &Context, ui: &mut egui::Ui) {
178181 }
179182
180183 // Checkbox and Text Input
181- ui. checkbox ( & mut state. ui_check , "Some checkbox" ) ;
182- ui. text_edit_singleline ( state. text . as_mut ( ) . unwrap ( ) ) ;
184+ let mut binding = state. lock ( ) . unwrap ( ) ;
185+ let ui_state = binding. deref_mut ( ) ;
186+ if ui. checkbox ( & mut ui_state. ui_check , "Some checkbox" ) . changed ( ) {
187+ println ! ( "Checkbox toggled to: {}" , ui_state. ui_check) ;
188+ }
189+ if ui. text_edit_singleline ( & mut ui_state. text ) . changed ( )
190+ {
191+ println ! ( "Set edit singleline to: {}" , ui_state. text) ;
192+ }
183193
184194 // Scroll Area
185195 ScrollArea :: vertical ( ) . max_height ( 200.0 ) . show ( ui, |ui| {
@@ -189,10 +199,16 @@ unsafe fn test_ui(ctx: &Context, ui: &mut egui::Ui) {
189199 } ) ;
190200
191201 // Slider
192- Slider :: new ( & mut state. value , -1.0 ..=1.0 ) . ui ( ui) ;
202+ if Slider :: new ( & mut ui_state. value , -1.0 ..=1.0 ) . ui ( ui) . changed ( )
203+ {
204+ println ! ( "Slider set value to: {}" , ui_state. value) ;
205+ }
193206
194207 // Color Picker
195- ui. color_edit_button_rgb ( & mut state. color ) ;
208+ if ui. color_edit_button_rgb ( & mut ui_state. color ) . changed ( )
209+ {
210+ println ! ( "Color edit button set color to: {:?}" , ui_state. color) ;
211+ }
196212
197213 // Display Pointer Info
198214 ui. label ( format ! (
0 commit comments