#![deny(unsafe_code)]
#![deny(missing_docs)]
#[cfg(all(feature = "android", target_os = "android"))]
mod android_file_picker;
#[cfg(all(feature = "android", target_os = "android"))]
pub use android_file_picker::open_content_uri;
#[cfg(any(
test,
all(feature = "desktop-shell", feature = "renderer-wgpu"),
all(feature = "android", feature = "renderer-wgpu", target_os = "android"),
all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"),
all(feature = "web", feature = "renderer-wgpu", target_arch = "wasm32")
))]
mod accessibility;
#[cfg(all(feature = "android", feature = "renderer-wgpu", target_os = "android"))]
mod android_accessibility;
#[cfg(any(
test,
all(feature = "android", feature = "renderer-wgpu", target_os = "android")
))]
mod android_accessibility_wire;
#[cfg(all(feature = "android", target_os = "android"))]
mod android_app_info;
#[cfg(all(feature = "android", target_os = "android"))]
mod android_camera;
#[cfg(all(feature = "android", target_os = "android"))]
mod android_media;
#[cfg(all(feature = "android", feature = "renderer-wgpu", target_os = "android"))]
mod android_display;
mod android_entry;
#[cfg(all(feature = "android", target_os = "android"))]
mod android_finish;
#[cfg(all(feature = "android", target_os = "android"))]
mod android_font_scale;
#[cfg(all(feature = "android", target_os = "android"))]
mod android_frame_rate;
#[cfg(all(feature = "android", target_os = "android"))]
mod android_frame_telemetry;
#[cfg(any(
test,
all(feature = "android", feature = "renderer-wgpu", target_os = "android")
))]
mod android_haptics_queue;
#[cfg(all(feature = "android", target_os = "android"))]
mod android_host;
#[cfg_attr(not(all(feature = "android", target_os = "android")), allow(dead_code))]
mod android_host_window;
mod android_input;
#[cfg(all(feature = "android", target_os = "android"))]
mod android_jni;
#[cfg(all(feature = "android", feature = "renderer-wgpu", target_os = "android"))]
mod android_keyboard;
#[cfg(any(test, all(feature = "android", target_os = "android")))]
mod android_launch_args;
#[cfg(all(feature = "android", feature = "renderer-wgpu", target_os = "android"))]
mod android_overlay_window;
#[cfg(all(feature = "android", target_os = "android"))]
mod android_perf_hint;
#[cfg(any(
test,
all(feature = "android", feature = "playbilling", target_os = "android")
))]
mod android_purchase_wire;
#[cfg(all(
feature = "android",
feature = "playbilling",
feature = "renderer-wgpu",
target_os = "android"
))]
mod android_purchases;
#[cfg(all(feature = "android", feature = "renderer-wgpu", target_os = "android"))]
mod android_services;
#[cfg(all(feature = "android", feature = "renderer-wgpu", target_os = "android"))]
mod android_surface;
#[cfg(all(feature = "android", feature = "renderer-wgpu", target_os = "android"))]
mod android_text_input;
#[cfg(all(feature = "android", target_os = "android"))]
mod android_vsync;
#[cfg(all(feature = "android", target_os = "android"))]
mod android_writable_folder;
mod app_launcher;
mod host_environment;
#[cfg(all(feature = "ios", target_os = "ios"))]
mod ios_host;
mod native_window;
#[cfg(all(feature = "android", target_os = "android"))]
pub use android_activity::AndroidApp;
#[cfg(all(feature = "android", feature = "renderer-wgpu", target_os = "android"))]
pub use android_host_window::{
rememberAndroidHostWindowState, AndroidHostWindowPositionError, AndroidHostWindowSizeError,
AndroidHostWindowSizeStatus, AndroidHostWindowState,
};
#[cfg(all(
feature = "renderer-wgpu",
any(feature = "desktop-shell", all(feature = "ios", target_os = "ios"))
))]
pub use app_launcher::LaunchError;
pub use app_launcher::{AndroidOverlayWindowOptions, AppLauncher, AppSettings};
pub use cranpose_render_common::font_source::{
FontLoadError, SoftwareTextFontRegistry, ANDROID_SYSTEM_FONT_DIR, DEFAULT_SYSTEM_FAMILY_WEIGHTS,
};
pub use host_environment::{host_density, system_font_directory};
pub use native_window::{
current_native_window_surface_origin, rememberWindowState, Window, WindowAttachPolicy,
WindowConfig, WindowGroup, WindowId, WindowModifierExt, WindowMoveMode, WindowNode,
WindowResizeDirection, WindowState,
};
#[cfg(all(
feature = "renderer-wgpu",
any(
feature = "desktop-shell",
all(feature = "android", target_os = "android"),
all(feature = "ios", target_os = "ios"),
all(feature = "web", target_arch = "wasm32")
)
))]
mod present_mode;
#[cfg(all(
feature = "renderer-wgpu",
any(
feature = "desktop-shell",
all(feature = "android", target_os = "android"),
all(feature = "ios", target_os = "ios"),
all(feature = "web", target_arch = "wasm32")
)
))]
mod surface_format;
#[cfg(all(
feature = "renderer-wgpu",
any(
feature = "desktop-shell",
all(feature = "android", target_os = "android"),
all(feature = "ios", target_os = "ios"),
all(feature = "web", target_arch = "wasm32")
)
))]
mod wgpu_surface;
pub use cranpose_services::*;
pub use cranpose_ui::*;
pub use cranpose_liquid as liquid;
#[cfg(feature = "audio")]
pub use cranpose_audio::{install as install_audio, AudioEngine};
#[cfg(feature = "media-desktop")]
pub use cranpose_media::{path_from_uri, uri_for_path, DesktopMediaPlayer};
pub use cranpose_core::{
delay, interval, launchBlocking, mutableStateOf, produceState, remember,
rememberCoroutineScope, rememberMutableStateOf, rememberMutableStateOfNeverEqual,
rememberUpdatedState, CoroutineScope, MutableState, SnapshotStateList, SnapshotStateMap, State,
};
static KEEP_SCREEN_ON_EFFECTS: std::sync::atomic::AtomicUsize =
std::sync::atomic::AtomicUsize::new(0);
#[allow(non_snake_case)]
pub fn KeepScreenOn(enabled: bool) {
cranpose_core::DisposableEffect!(enabled, move |scope| {
if !enabled {
return cranpose_core::DisposableEffectResult::default();
}
if KEEP_SCREEN_ON_EFFECTS.fetch_add(1, std::sync::atomic::Ordering::AcqRel) == 0 {
cranpose_services::set_keep_screen_on(true);
}
scope.on_dispose(move || {
if KEEP_SCREEN_ON_EFFECTS.fetch_sub(1, std::sync::atomic::Ordering::AcqRel) == 1 {
cranpose_services::set_keep_screen_on(false);
}
})
});
}
#[cfg(not(target_arch = "wasm32"))]
#[allow(non_snake_case)]
pub fn BundledAssetInstallEffect<K: std::hash::Hash>(
keys: K,
spec: cranpose_services::BundledAssetInstallSpec,
on_result: impl FnOnce(
Result<
cranpose_services::BundledAssetInstallOutcome,
cranpose_services::BundledAssetError,
>,
) + 'static,
) {
cranpose_core::LaunchedEffect!(keys, move |scope| {
scope.launch_background(
move |_token| async move { cranpose_services::install_bundled_asset_set(&spec) },
on_result,
);
});
}
#[allow(non_snake_case)]
pub fn LifecycleEffect<K: std::hash::Hash + 'static>(
keys: K,
observer: impl FnMut(cranpose_services::LifecycleEvent) + 'static,
) {
let transitions = cranpose_services::rememberLifecycleEvents();
cranpose_core::CollectEvents(transitions, keys, observer);
}
static ACTIVE_BACK_HANDLERS: std::sync::atomic::AtomicUsize =
std::sync::atomic::AtomicUsize::new(0);
#[allow(non_snake_case)]
pub fn BackHandler(enabled: bool, mut on_back: impl FnMut() + 'static) {
let requests = cranpose_core::rememberEventStream(enabled, move |sender| {
if !enabled {
return None;
}
if ACTIVE_BACK_HANDLERS.fetch_add(1, std::sync::atomic::Ordering::AcqRel) == 0 {
cranpose_services::set_back_interception(true);
}
let registration = cranpose_services::observe_back_requests(move || {
let count = cranpose_services::take_back_requests();
if count > 0 {
sender.send(count);
}
});
Some(BackInterception {
_registration: registration,
})
});
if enabled {
cranpose_core::CollectEvents(requests, enabled, move |count: usize| {
for _ in 0..count {
on_back();
}
});
}
}
struct BackInterception {
_registration: cranpose_services::BackRequestObserver,
}
impl Drop for BackInterception {
fn drop(&mut self) {
if ACTIVE_BACK_HANDLERS.fetch_sub(1, std::sync::atomic::Ordering::AcqRel) == 1 {
cranpose_services::set_back_interception(false);
}
}
}
#[allow(non_snake_case)]
pub fn rememberAppUpdateState() -> cranpose_core::State<cranpose_services::AppUpdateStatus> {
let updates = cranpose_core::rememberEventStream((), |sender| {
cranpose_services::observe_app_update_status(move |status| sender.send(status))
});
cranpose_core::collectAsState(updates, (), cranpose_services::app_update_status())
}
#[allow(non_snake_case)]
pub fn FrameEffect<K: std::hash::Hash>(
keys: K,
running: bool,
on_frame: impl FnMut(u64) + 'static,
) {
let on_frame: std::rc::Rc<std::cell::RefCell<dyn FnMut(u64)>> =
std::rc::Rc::new(std::cell::RefCell::new(on_frame));
let on_frame = cranpose_core::rememberUpdatedState(on_frame);
cranpose_core::LaunchedEffectAsync!((keys, running), move |scope| {
Box::pin(async move {
if !running {
return;
}
let clock = scope.runtime().frame_clock();
while scope.is_active() {
let now = clock.next_frame().await;
if !scope.is_active() {
break;
}
(on_frame.value().borrow_mut())(now);
}
})
});
}
#[doc(hidden)]
pub use cranpose_core::{
debug_label_current_scope, location_key, with_current_composer, CallbackHolder, Composer,
ParamState, ReturnSlot,
};
#[cfg(all(
feature = "desktop-shell",
feature = "robot",
feature = "renderer-wgpu"
))]
#[doc(hidden)]
pub type RobotAppHook = dyn FnMut(String, String) -> Result<Option<String>, String>;
pub mod prelude {
#[cfg(all(feature = "android", feature = "renderer-wgpu", target_os = "android"))]
pub use crate::{
rememberAndroidHostWindowState, AndroidHostWindowPositionError, AndroidHostWindowSizeError,
AndroidHostWindowSizeStatus, AndroidHostWindowState,
};
pub use crate::{
rememberWindowState, AndroidOverlayWindowOptions, AppLauncher, AppSettings, Window,
WindowAttachPolicy, WindowConfig, WindowGroup, WindowId, WindowModifierExt, WindowMoveMode,
WindowNode, WindowResizeDirection, WindowState,
};
pub use cranpose_core::{
delay, interval, mutableStateOf, produceState, remember, rememberCoroutineScope,
rememberMutableStateOf, rememberMutableStateOfNeverEqual, rememberUpdatedState,
CoroutineScope, MutableState, SnapshotStateList, SnapshotStateMap, State,
};
pub use cranpose_services::*;
pub use cranpose_ui::*;
}
#[cfg(any(
all(feature = "desktop-shell", feature = "renderer-wgpu"),
all(feature = "android", feature = "renderer-wgpu", target_os = "android"),
all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"),
all(feature = "web", feature = "renderer-wgpu", target_arch = "wasm32")
))]
pub(crate) mod platform_env;
#[cfg(all(feature = "android", feature = "renderer-wgpu", target_os = "android"))]
pub mod android;
#[cfg(feature = "renderer-wgpu")]
#[cfg_attr(
not(any(
all(feature = "android", target_os = "android"),
all(feature = "ios", target_os = "ios")
)),
allow(dead_code)
)]
pub(crate) mod gpu_limits;
#[cfg(all(feature = "desktop-shell", feature = "renderer-wgpu"))]
pub mod desktop;
#[cfg(all(feature = "desktop-shell", feature = "renderer-wgpu"))]
mod desktop_accessibility;
#[cfg(all(feature = "desktop-shell", feature = "renderer-wgpu"))]
mod desktop_bundled_assets;
#[cfg(all(feature = "desktop-shell", feature = "renderer-wgpu"))]
mod desktop_host_surface;
#[cfg(all(feature = "desktop-shell", feature = "renderer-wgpu"))]
mod desktop_incoming;
#[cfg(all(feature = "desktop-shell", feature = "renderer-wgpu"))]
mod desktop_input;
#[cfg(all(feature = "desktop-shell", feature = "renderer-wgpu"))]
mod desktop_power;
#[cfg(all(
unix,
feature = "renderer-wgpu",
any(
feature = "desktop-shell",
all(feature = "android", target_os = "android"),
all(feature = "ios", target_os = "ios")
)
))]
mod process_info;
#[cfg(any(
all(feature = "desktop-shell", feature = "renderer-wgpu"),
all(feature = "ios", feature = "renderer-wgpu", target_os = "ios")
))]
mod winit_pointer;
#[cfg(any(
all(feature = "desktop-shell", feature = "renderer-wgpu"),
all(feature = "ios", feature = "renderer-wgpu", target_os = "ios")
))]
#[cfg_attr(not(all(feature = "ios", target_os = "ios")), allow(dead_code))]
mod winit_touch;
#[cfg(all(feature = "desktop-shell", feature = "renderer-wgpu"))]
mod winit_wheel;
#[cfg(all(
feature = "robot",
feature = "desktop-shell",
feature = "renderer-wgpu"
))]
mod robot;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
pub mod ios;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_accessibility;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_file_picker;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_uri_handler;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_clipboard;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_share_sheet;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_image_picker;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_notifier;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_haptics;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_media;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_app_info;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_device_info;
#[cfg(any(
all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"),
all(
feature = "desktop-shell",
feature = "renderer-wgpu",
target_os = "macos"
)
))]
mod apple_thermal;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_writable_folder;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_camera;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_keyboard;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_back_gesture;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_background;
#[cfg(all(feature = "ios", feature = "renderer-wgpu", target_os = "ios"))]
mod ios_bundled_assets;
#[cfg(all(feature = "desktop-shell", feature = "renderer-wgpu"))]
pub mod recorder;
#[cfg(all(feature = "web", feature = "renderer-wgpu", target_arch = "wasm32"))]
pub mod web;
#[cfg(any(
all(feature = "web", feature = "renderer-wgpu", target_arch = "wasm32"),
test
))]
mod web_surface_scale;
#[cfg(any(
all(feature = "web", feature = "renderer-wgpu", target_arch = "wasm32"),
test
))]
mod web_wheel;
#[cfg(all(feature = "web", feature = "renderer-wgpu", target_arch = "wasm32"))]
mod web_accessibility;
#[cfg(all(feature = "web", feature = "renderer-wgpu", target_arch = "wasm32"))]
mod web_clipboard;
#[cfg(all(feature = "web", feature = "renderer-wgpu", target_arch = "wasm32"))]
mod web_host_surface;
#[cfg(all(feature = "web", feature = "renderer-wgpu", target_arch = "wasm32"))]
mod web_media;
#[cfg(all(feature = "web", feature = "renderer-wgpu", target_arch = "wasm32"))]
mod web_services;
#[cfg(all(feature = "web", feature = "renderer-wgpu", target_arch = "wasm32"))]
mod web_power;
#[cfg(all(feature = "web", feature = "renderer-wgpu", target_arch = "wasm32"))]
mod web_drop;
#[cfg(all(
feature = "desktop-shell",
feature = "robot",
feature = "renderer-wgpu"
))]
pub use robot::{
Robot, RobotScreenshot, RobotTimelineAction, RobotTimelineStep, SemanticElement, SemanticRect,
};
#[cfg(all(feature = "desktop-shell", feature = "renderer-wgpu"))]
pub use cranpose_app_shell::{DevOptions, FpsStats, FramePacingMode};
#[cfg(all(test, feature = "desktop-shell", feature = "renderer-wgpu"))]
pub(crate) fn test_scratch_dir(tag: &str) -> std::path::PathBuf {
cranpose_core::test_scratch_dir(env!("CARGO_MANIFEST_DIR"), tag)
}