From 3d356128f507177054b19c528b069da0a8400e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=96R=C3=96K=20Attila?= Date: Fri, 14 Nov 2025 15:01:08 +0100 Subject: [PATCH 1/2] Add UIBackend, currently only for soft keyboard --- src/lib.rs | 2 ++ src/ui.rs | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/ui.rs diff --git a/src/lib.rs b/src/lib.rs index f5977c91..21bc5174 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ mod java; mod keycodes; mod navigator; mod trace; +mod ui; use custom_event::RuffleEvent; @@ -269,6 +270,7 @@ async fn run(app: AndroidApp) { .with_storage(Box::new(DiskStorageBackend::new(android_storage_dir.clone()))) .with_navigator(navigator) .with_log(FileLogBackend::new(trace_output.as_deref())) + .with_ui(ui::AndroidUiBackend::new(app.clone())) .with_video( ruffle_video_software::backend::SoftwareVideoBackend::new(), ) diff --git a/src/ui.rs b/src/ui.rs new file mode 100644 index 00000000..a7b58bdc --- /dev/null +++ b/src/ui.rs @@ -0,0 +1,94 @@ +use std::str::FromStr; + +use android_activity::AndroidApp; +use ruffle_core::backend::ui::{LanguageIdentifier, UiBackend}; +use url::Url; + +#[derive(Clone)] +pub struct AndroidUiBackend { + app: AndroidApp, +} + +impl AndroidUiBackend { + pub fn new(app: AndroidApp) -> Self { + Self { app } + } +} + +impl UiBackend for AndroidUiBackend { + fn mouse_visible(&self) -> bool { + false + } + + fn set_mouse_visible(&mut self, visible: bool) {} + + fn set_mouse_cursor(&mut self, cursor: ruffle_core::backend::ui::MouseCursor) {} + + fn clipboard_content(&mut self) -> String { + "".into() + } + + fn set_clipboard_content(&mut self, content: String) {} + + fn set_fullscreen( + &mut self, + is_full: bool, + ) -> Result<(), ruffle_core::backend::ui::FullscreenError> { + Ok(()) + } + + fn display_root_movie_download_failed_message( + &self, + _invalid_swf: bool, + _fetched_error: String, + ) { + } + + fn message(&self, message: &str) {} + + fn open_virtual_keyboard(&self) { + self.app.show_soft_input(false); + } + + fn close_virtual_keyboard(&self) { + self.app.hide_soft_input(false); + } + + fn language(&self) -> ruffle_core::backend::ui::LanguageIdentifier { + LanguageIdentifier::from_str("en-US").unwrap() + } + + fn display_unsupported_video(&self, url: Url) {} + + fn load_device_font( + &self, + query: &ruffle_core::FontQuery, + register: &mut dyn FnMut(ruffle_core::backend::ui::FontDefinition), + ) { + } + + fn sort_device_fonts( + &self, + query: &ruffle_core::FontQuery, + register: &mut dyn FnMut(ruffle_core::backend::ui::FontDefinition), + ) -> Vec { + Vec::new() + } + + fn display_file_open_dialog( + &mut self, + filters: Vec, + ) -> Option { + None + } + + fn display_file_save_dialog( + &mut self, + file_name: String, + title: String, + ) -> Option { + None + } + + fn close_file_dialog(&mut self) {} +} From 9c867efb5f5bb43307e69d78fbc1d667abab2ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=96R=C3=96K=20Attila?= Date: Fri, 14 Nov 2025 15:36:55 +0100 Subject: [PATCH 2/2] IME events? no preedit tho --- src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 21bc5174..d6e9f514 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -395,6 +395,15 @@ async fn run(app: AndroidApp) { InputStatus::Handled } + InputEvent::TextEvent(state) => { + if let Some(player) = playerbox.as_ref() { + let event = PlayerEvent::Ime( + ruffle_core::events::ImeEvent::Commit(state.text.clone()), + ); + player.player.lock().unwrap().handle_event(event); + } + InputStatus::Handled + } _ => InputStatus::Unhandled, }) {} }