@@ -649,7 +649,7 @@ impl eframe::App for App {
649649 eprintln ! ( "[DEBUG] Applying auto-centering with content size: {}x{}" , actual_size. x, actual_size. y) ;
650650
651651 // Cross-platform screen size detection
652- let ( screen_width, screen_height, method_used) = get_cross_platform_screen_size ( ) ;
652+ let ( screen_width, screen_height, method_used) = e_window_native :: get_cross_platform_screen_size ( ) ;
653653
654654 // Check if the window should be resized to fit content instead of using default size
655655 // This handles the case where egui applies a default size (like 1024x768) instead of content size
@@ -666,15 +666,15 @@ impl eframe::App for App {
666666
667667 // Resize window to fit content
668668 ctx. send_viewport_cmd ( egui:: ViewportCommand :: InnerSize ( egui:: vec2 ( target_width, target_height) ) ) ;
669- ( target_width, target_height)
669+ ( target_width as u32 , target_height as u32 )
670670 } else {
671- ( actual_size. x , actual_size. y )
671+ ( actual_size. x as u32 , actual_size. y as u32 )
672672 } ;
673673
674674 // Calculate center position based on final window size
675675 if screen_width > final_width && screen_height > final_height {
676- let center_x = ( screen_width - final_width) / 2.0 ;
677- let center_y = ( screen_height - final_height) / 2.0 ;
676+ let center_x = ( screen_width as f32 - final_width as f32 ) / 2.0 ;
677+ let center_y = ( screen_height as f32 - final_height as f32 ) / 2.0 ;
678678
679679 eprintln ! ( "[DEBUG] Auto-centering ({}): screen={}x{}, window={}x{}, center=({}, {})" ,
680680 method_used, screen_width, screen_height, final_width, final_height, center_x, center_y) ;
@@ -712,9 +712,9 @@ impl eframe::App for App {
712712 // and we're still at origin position AND auto-centering is enabled
713713 if self . should_auto_center && old_size != new_size && current_pos. x as i32 == 0 && current_pos. y as i32 == 0 {
714714 // Use cross-platform screen detection
715- let ( screen_width, screen_height, method_used) = get_cross_platform_screen_size ( ) ;
716- let new_center_x = ( ( screen_width - new_size. 0 as f32 ) / 2.0 ) as i32 ;
717- let new_center_y = ( ( screen_height - new_size. 1 as f32 ) / 2.0 ) as i32 ;
715+ let ( screen_width, screen_height, method_used) = e_window_native :: get_cross_platform_screen_size ( ) ;
716+ let new_center_x = ( ( screen_width as f32 - new_size. 0 as f32 ) / 2.0 ) . round ( ) as i32 ;
717+ let new_center_y = ( ( screen_height as f32 - new_size. 1 as f32 ) / 2.0 ) . round ( ) as i32 ;
718718
719719 eprintln ! ( "[App] Auto-centering ({}): old_size={}x{}, new_size={}x{}, screen={}x{}, new_center=({}, {})" ,
720720 method_used, old_size. 0 , old_size. 1 , new_size. 0 , new_size. 1 , screen_width, screen_height, new_center_x, new_center_y) ;
@@ -1542,59 +1542,3 @@ anchor: Click me! | e_window --title "you clicked!" --width 800 --height 600 --x
15421542pub fn default_card_with_hwnd ( hwnd : usize ) -> String {
15431543 DEFAULT_CARD_TEMPLATE . replace ( "{PARENT_HWND}" , & format ! ( "0x{:X}" , hwnd) )
15441544}
1545-
1546- /// Cross-platform screen size detection
1547- fn get_cross_platform_screen_size ( ) -> ( f32 , f32 , & ' static str ) {
1548- #[ cfg( target_os = "windows" ) ]
1549- {
1550- use winapi:: um:: winuser:: { GetSystemMetrics , SM_CXSCREEN , SM_CYSCREEN } ;
1551-
1552- let width = unsafe { GetSystemMetrics ( SM_CXSCREEN ) } as f32 ;
1553- let height = unsafe { GetSystemMetrics ( SM_CYSCREEN ) } as f32 ;
1554-
1555- eprintln ! ( "[DEBUG] Windows GetSystemMetrics screen size: {}x{}" , width, height) ;
1556- ( width, height, "windows_getsystemmetrics" )
1557- }
1558-
1559- #[ cfg( target_os = "macos" ) ]
1560- {
1561- // macOS screen detection using Core Graphics
1562- use core_graphics:: display:: CGMainDisplay ;
1563-
1564- let display = CGMainDisplay ( ) ;
1565- let width = display. pixels_wide ( ) as f32 ;
1566- let height = display. pixels_high ( ) as f32 ;
1567-
1568- eprintln ! ( "[DEBUG] macOS Core Graphics screen size: {}x{}" , width, height) ;
1569- ( width, height, "macos_coregraphics" )
1570- }
1571-
1572- #[ cfg( target_os = "linux" ) ]
1573- {
1574- // Linux screen detection using X11
1575- use x11:: xlib:: * ;
1576- use std:: ptr;
1577-
1578- unsafe {
1579- let display = XOpenDisplay ( ptr:: null ( ) ) ;
1580- if !display. is_null ( ) {
1581- let screen = XDefaultScreen ( display) ;
1582- let width = XDisplayWidth ( display, screen) as f32 ;
1583- let height = XDisplayHeight ( display, screen) as f32 ;
1584- XCloseDisplay ( display) ;
1585-
1586- eprintln ! ( "[DEBUG] Linux X11 screen size: {}x{}" , width, height) ;
1587- ( width, height, "linux_x11" )
1588- } else {
1589- eprintln ! ( "[DEBUG] Failed to open X11 display, using fallback" ) ;
1590- ( 1920.0 , 1080.0 , "linux_fallback" )
1591- }
1592- }
1593- }
1594-
1595- #[ cfg( not( any( target_os = "windows" , target_os = "macos" , target_os = "linux" ) ) ) ]
1596- {
1597- eprintln ! ( "[DEBUG] Unsupported platform, using fallback screen size" ) ;
1598- ( 1920.0 , 1080.0 , "platform_fallback" )
1599- }
1600- }
0 commit comments