use crate::sys::platform;
use std::path::{Path, PathBuf};
pub use platform::*;
pub trait Initialize {
fn initialize(&mut self) -> anyhow::Result<()>;
}
pub trait BuilderExt {
fn with_platform(self, title: &str) -> Self;
}
pub fn open_file_dialog(
title: impl Into<String>,
name: impl Into<String>,
extensions: &[impl ToString],
dir: Option<impl AsRef<Path>>,
) -> anyhow::Result<Option<PathBuf>> {
platform::open_file_dialog_impl(title, name, extensions, dir)
}
#[allow(clippy::missing_const_for_fn)]
pub fn speak_text(text: &str) {
platform::speak_text_impl(text);
}
pub mod renderer {
use super::*;
use crate::nes::{config::Config, event::Response, renderer::Renderer};
pub fn constrain_window_to_viewport(
renderer: &Renderer,
desired_window_width: f32,
cfg: &Config,
) -> Response {
platform::renderer::constrain_window_to_viewport_impl(renderer, desired_window_width, cfg)
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[must_use]
pub enum Feature {
AbortOnExit,
Blocking,
ConstrainedViewport,
ConsumePaste,
Filesystem,
ScreenReader,
Storage,
Suspend,
OsViewports,
}
#[macro_export]
macro_rules! feature {
($feature: tt) => {{
use $crate::platform::Feature::*;
match $feature {
AbortOnExit => cfg!(target_arch = "wasm32"),
Blocking | Filesystem | OsViewports => {
cfg!(not(target_arch = "wasm32"))
}
ConstrainedViewport | ConsumePaste | ScreenReader => {
cfg!(target_arch = "wasm32")
}
Storage => true,
Suspend => cfg!(target_os = "android"),
}
}};
}