use crate::platform::{IPlatformIconLoader, IWindowImpl, IWindowingPlatform};
use ferroui_base::animation::IGlobalClock;
use ferroui_base::input::{
IAccessKeyHandler, IInputManager, IKeyboardDevice, IKeyboardNavigationHandler, IMouseDevice, InputManager,
KeyboardDevice, KeyboardNavigationHandler,
};
use ferroui_base::platform::{
IAssetLoader, ICursorFactory, IPlatformRenderInterface, IPlatformSettings, StandardAssetLoader,
};
use ferroui_base::styling::IStyle;
use std::rc::Rc;
#[derive(Clone, Default)]
pub struct TestServices {
pub asset_loader: Option<Rc<dyn IAssetLoader>>,
pub input_manager: Option<Rc<dyn IInputManager>>,
pub global_clock: Option<Rc<dyn IGlobalClock>>,
pub access_key_handler: Option<Rc<dyn Fn() -> Option<Rc<dyn IAccessKeyHandler>>>>,
pub keyboard_device: Option<Rc<dyn Fn() -> Option<Rc<dyn IKeyboardDevice>>>>,
pub keyboard_navigation: Option<Rc<dyn Fn() -> Option<Rc<dyn IKeyboardNavigationHandler>>>>,
pub mouse_device: Option<Rc<dyn Fn() -> Option<Rc<dyn IMouseDevice>>>>,
pub render_interface: Option<Rc<dyn IPlatformRenderInterface>>,
pub font_manager_impl: Option<Rc<dyn ferroui_base::platform::IFontManagerImpl>>,
pub text_shaper_impl: Option<Rc<dyn ferroui_base::platform::ITextShaperImpl>>,
pub platform_settings: Option<Rc<dyn IPlatformSettings>>,
pub standard_cursor_factory: Option<Rc<dyn ICursorFactory>>,
pub theme: Option<Rc<dyn Fn() -> Rc<dyn IStyle>>>,
pub window_impl: Option<Rc<dyn IWindowImpl>>,
pub windowing_platform: Option<Rc<dyn IWindowingPlatform>>,
pub platform: Option<Rc<dyn ferroui_base::platform::IRuntimePlatform>>,
pub icon_loader: Option<Rc<dyn IPlatformIconLoader>>,
}
impl TestServices {
pub fn new() -> Self {
Self::default()
}
pub fn mock_platform_render_interface() -> Self {
Self { asset_loader: Some(Rc::new(StandardAssetLoader::new(None))), ..Self::default() }
}
pub fn mock_platform_wrapper() -> Self {
Self { platform: Some(Rc::new(MockRuntimePlatform)), ..Self::default() }
}
pub fn mock_threading_interface() -> Self {
Self { asset_loader: Some(Rc::new(StandardAssetLoader::new(None))), ..Self::default() }
}
pub fn real_focus() -> Self {
Self {
keyboard_device: Some(Rc::new(|| Some(KeyboardDevice::new() as Rc<dyn IKeyboardDevice>))),
keyboard_navigation: Some(Rc::new(|| {
Some(KeyboardNavigationHandler::new() as Rc<dyn IKeyboardNavigationHandler>)
})),
input_manager: Some(Rc::new(InputManager::new())),
asset_loader: Some(Rc::new(StandardAssetLoader::new(None))),
..Self::default()
}
}
pub fn text_services() -> Self {
Self { asset_loader: Some(Rc::new(StandardAssetLoader::new(None))), ..Self::default() }
}
pub fn with_asset_loader(mut self, value: Rc<dyn IAssetLoader>) -> Self {
self.asset_loader = Some(value);
self
}
pub fn with_input_manager(mut self, value: Rc<dyn IInputManager>) -> Self {
self.input_manager = Some(value);
self
}
pub fn with_global_clock(mut self, value: Rc<dyn IGlobalClock>) -> Self {
self.global_clock = Some(value);
self
}
pub fn with_access_key_handler(mut self, value: impl Fn() -> Option<Rc<dyn IAccessKeyHandler>> + 'static) -> Self {
self.access_key_handler = Some(Rc::new(value));
self
}
pub fn with_keyboard_device(mut self, value: impl Fn() -> Option<Rc<dyn IKeyboardDevice>> + 'static) -> Self {
self.keyboard_device = Some(Rc::new(value));
self
}
pub fn with_keyboard_navigation(
mut self,
value: impl Fn() -> Option<Rc<dyn IKeyboardNavigationHandler>> + 'static,
) -> Self {
self.keyboard_navigation = Some(Rc::new(value));
self
}
pub fn with_mouse_device(mut self, value: impl Fn() -> Option<Rc<dyn IMouseDevice>> + 'static) -> Self {
self.mouse_device = Some(Rc::new(value));
self
}
pub fn with_render_interface(mut self, value: Rc<dyn IPlatformRenderInterface>) -> Self {
self.render_interface = Some(value);
self
}
pub fn with_font_manager_impl(mut self, value: Rc<dyn ferroui_base::platform::IFontManagerImpl>) -> Self {
self.font_manager_impl = Some(value);
self
}
pub fn with_text_shaper_impl(mut self, value: Rc<dyn ferroui_base::platform::ITextShaperImpl>) -> Self {
self.text_shaper_impl = Some(value);
self
}
pub fn with_platform_settings(mut self, value: Rc<dyn IPlatformSettings>) -> Self {
self.platform_settings = Some(value);
self
}
pub fn with_standard_cursor_factory(mut self, value: Rc<dyn ICursorFactory>) -> Self {
self.standard_cursor_factory = Some(value);
self
}
pub fn with_theme(mut self, value: impl Fn() -> Rc<dyn IStyle> + 'static) -> Self {
self.theme = Some(Rc::new(value));
self
}
pub fn with_window_impl(mut self, value: Rc<dyn IWindowImpl>) -> Self {
self.window_impl = Some(value);
self
}
pub fn with_platform(mut self, value: Rc<dyn ferroui_base::platform::IRuntimePlatform>) -> Self {
self.platform = Some(value);
self
}
pub fn with_windowing_platform(mut self, value: Rc<dyn IWindowingPlatform>) -> Self {
self.windowing_platform = Some(value);
self
}
pub fn with_icon_loader(mut self, value: Rc<dyn IPlatformIconLoader>) -> Self {
self.icon_loader = Some(value);
self
}
}
pub struct MockRuntimePlatform;
impl ferroui_base::platform::IRuntimePlatform for MockRuntimePlatform {
fn get_runtime_info(&self) -> ferroui_base::platform::RuntimePlatformInfo {
ferroui_base::platform::RuntimePlatformInfo::default()
}
}