diff --git a/src/ui.rs b/src/ui.rs index 30ac898..2d6449b 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -129,6 +129,9 @@ pub fn sdl_close() { } pub fn get_dirs() -> Dirs { + #[cfg(target_os = "android")] + return android::get_dirs(); + #[cfg(not(target_os = "android"))] { let exe_path = std::env::current_exe().unwrap(); @@ -148,10 +151,6 @@ pub fn get_dirs() -> Dirs { } } } - #[cfg(target_os = "android")] - { - android::get_dirs() - } } impl Ui { diff --git a/src/ui/android.rs b/src/ui/android.rs index 129864f..7e479c0 100644 --- a/src/ui/android.rs +++ b/src/ui/android.rs @@ -312,6 +312,21 @@ pub fn get_dirs() -> ui::Dirs { } } +pub fn get_controller_names() -> Vec { + let mut controllers: Vec = list_controllers().into_iter().map(|c| c.name).collect(); + controllers.insert(0, "None".into()); + controllers +} + +pub fn get_controller_paths() -> Vec { + let mut controller_paths: Vec = list_controllers() + .into_iter() + .map(|c| c.descriptor) + .collect(); + controller_paths.insert(0, String::new()); + controller_paths +} + pub fn rom_exists(path: &str) -> bool { let path = path.to_string(); diff --git a/src/ui/gui.rs b/src/ui/gui.rs index 8bb9ed9..71818c8 100644 --- a/src/ui/gui.rs +++ b/src/ui/gui.rs @@ -48,18 +48,16 @@ fn check_latest_version(weak: slint::Weak) { }); } -#[cfg(not(target_os = "android"))] pub fn open_uri(path: impl AsRef) { + #[cfg(target_os = "android")] + return ui::android::open_uri(path.as_ref().to_str().unwrap()); + + #[cfg(not(target_os = "android"))] if let Err(e) = open::that_detached(path) { eprintln!("Error opening path: {}", e); } } -#[cfg(target_os = "android")] -pub fn open_uri(path: impl AsRef) { - ui::android::open_uri(path.as_ref().to_str().unwrap()) -} - fn run_with_path(weak: slint::Weak, path: std::path::PathBuf) { let weak2 = weak.clone(); weak.upgrade_in_event_loop(move |handle| { @@ -608,6 +606,9 @@ pub fn run_rom( } pub async fn select_rom(rom_dir: slint::SharedString) -> Option { + #[cfg(target_os = "android")] + return ui::android::select_rom(rom_dir).await; + #[cfg(not(target_os = "android"))] { if !rom_dir.is_empty() && std::fs::exists(&rom_dir).unwrap_or(false) { @@ -621,13 +622,12 @@ pub async fn select_rom(rom_dir: slint::SharedString) -> Option Option { + #[cfg(target_os = "android")] + return ui::android::select_gb_rom(player).await; + #[cfg(not(target_os = "android"))] { rfd::AsyncFileDialog::new() @@ -637,13 +637,12 @@ pub async fn select_gb_rom(player: i32) -> Option { .await .map(|file| file.path().to_path_buf()) } - #[cfg(target_os = "android")] - { - ui::android::select_gb_rom(player).await - } } pub async fn select_gb_ram(player: i32) -> Option { + #[cfg(target_os = "android")] + return ui::android::select_gb_ram(player).await; + #[cfg(not(target_os = "android"))] { rfd::AsyncFileDialog::new() @@ -653,10 +652,6 @@ pub async fn select_gb_ram(player: i32) -> Option { .await .map(|file| file.path().to_path_buf()) } - #[cfg(target_os = "android")] - { - ui::android::select_gb_ram(player).await - } } fn open_rom(app: &AppWindow) { diff --git a/src/ui/gui/appwindow.slint b/src/ui/gui/appwindow.slint index e7b6ae6..856a788 100644 --- a/src/ui/gui/appwindow.slint +++ b/src/ui/gui/appwindow.slint @@ -1,7 +1,7 @@ // Copyright © SixtyFPS GmbH // SPDX-License-Identifier: MIT -import { StandardButton } from "std-widgets.slint"; +import { StandardButton, VerticalBox, HorizontalBox } from "std-widgets.slint"; import { LocalGame, ControllerConfig, Netplay, Cheats, RetroAchievements, Settings, About } from "pages.slint"; import { SideBar } from "side_bar.slint"; import { SettingsData } from "settings_page.slint"; @@ -250,14 +250,29 @@ export component AppWindow inherits Window { } } -export component ErrorDialog inherits Dialog { +export component ErrorDialog inherits Window { in-out property text; title: @tr("Error"); - Text { - text: text; - } + callback close_clicked; + VerticalBox { + alignment: start; + vertical-stretch: 1; + padding-left: root.safe-area-insets.left; + padding-top: root.safe-area-insets.top; + padding-right: root.safe-area-insets.right; + padding-bottom: root.safe-area-insets.bottom; + Text { + text: text; + } - StandardButton { - kind: close; + HorizontalBox { + alignment: end; + StandardButton { + kind: close; + clicked => { + close_clicked(); + } + } + } } } diff --git a/src/ui/gui/input_profile.slint b/src/ui/gui/input_profile.slint index 704b6b1..b6eced8 100644 --- a/src/ui/gui/input_profile.slint +++ b/src/ui/gui/input_profile.slint @@ -1,4 +1,4 @@ -import { StandardButton, HorizontalBox, VerticalBox, Button, LineEdit, Switch, Slider } from "std-widgets.slint"; +import { HorizontalBox, VerticalBox, Button, LineEdit, Switch, Slider } from "std-widgets.slint"; export global InputProfileData { in-out property dinput; diff --git a/src/ui/gui/netplay_page.slint b/src/ui/gui/netplay_page.slint index 0c33703..36ebbe8 100644 --- a/src/ui/gui/netplay_page.slint +++ b/src/ui/gui/netplay_page.slint @@ -77,7 +77,7 @@ export component Netplay inherits Page { } } -export component CustomNetplayServer inherits Dialog { +export component CustomNetplayServer inherits Window { in-out property custom_server_url <=> NetplayData.custom_server_url; title: @tr("Custom Netplay Server"); preferred-width: 400px; @@ -94,14 +94,16 @@ export component CustomNetplayServer inherits Dialog { text: NetplayData.custom_server_url; placeholder-text: "example.com:45000"; } - } - StandardButton { - vertical-stretch: 0; - kind: ok; - clicked => { - NetplayData.custom_server_url = server_url.text; - ok_clicked(NetplayData.custom_server_url); + HorizontalBox { + alignment: end; + StandardButton { + kind: ok; + clicked => { + NetplayData.custom_server_url = server_url.text; + ok_clicked(NetplayData.custom_server_url); + } + } } } } diff --git a/src/ui/input.rs b/src/ui/input.rs index 42563af..3c62168 100644 --- a/src/ui/input.rs +++ b/src/ui/input.rs @@ -343,60 +343,49 @@ fn hotkey_pressed( pressed } -#[cfg(not(target_os = "android"))] pub fn get_controller_names() -> Vec { - let mut controllers: Vec = vec![]; + #[cfg(target_os = "android")] + return ui::android::get_controller_names(); - for joystick in get_joysticks().iter() { - let name = unsafe { sdl3_sys::joystick::SDL_GetJoystickNameForID(*joystick) }; - controllers.push(if name.is_null() { - "Unknown controller".to_string() - } else { - unsafe { std::ffi::CStr::from_ptr(name).to_str().unwrap() }.to_string() - }); + #[cfg(not(target_os = "android"))] + { + let mut controllers: Vec = vec![]; + + for joystick in get_joysticks().iter() { + let name = unsafe { sdl3_sys::joystick::SDL_GetJoystickNameForID(*joystick) }; + controllers.push(if name.is_null() { + "Unknown controller".to_string() + } else { + unsafe { std::ffi::CStr::from_ptr(name).to_str().unwrap() }.to_string() + }); + } + controllers.insert(0, "None".into()); + + controllers } - controllers.insert(0, "None".into()); - - controllers } -#[cfg(target_os = "android")] -pub fn get_controller_names() -> Vec { - let mut controllers: Vec = ui::android::list_controllers() - .into_iter() - .map(|c| c.name) - .collect(); - controllers.insert(0, "None".into()); - controllers -} - -#[cfg(not(target_os = "android"))] #[cfg(feature = "gui")] pub fn get_controller_paths() -> Vec { - let mut controller_paths: Vec = vec![]; + #[cfg(target_os = "android")] + return ui::android::get_controller_paths(); - for joystick in get_joysticks().iter() { - let path = unsafe { sdl3_sys::joystick::SDL_GetJoystickPathForID(*joystick) }; - controller_paths.push(if path.is_null() { - String::new() - } else { - unsafe { std::ffi::CStr::from_ptr(path).to_str().unwrap() }.to_string() - }); + #[cfg(not(target_os = "android"))] + { + let mut controller_paths: Vec = vec![]; + + for joystick in get_joysticks().iter() { + let path = unsafe { sdl3_sys::joystick::SDL_GetJoystickPathForID(*joystick) }; + controller_paths.push(if path.is_null() { + String::new() + } else { + unsafe { std::ffi::CStr::from_ptr(path).to_str().unwrap() }.to_string() + }); + } + controller_paths.insert(0, String::new()); + + controller_paths } - controller_paths.insert(0, String::new()); - - controller_paths -} - -#[cfg(target_os = "android")] -#[cfg(feature = "gui")] -pub fn get_controller_paths() -> Vec { - let mut controller_paths: Vec = ui::android::list_controllers() - .into_iter() - .map(|c| c.descriptor) - .collect(); - controller_paths.insert(0, String::new()); - controller_paths } fn handle_joystick_events(ui: &mut ui::Ui) {