#![allow(missing_docs)]
#![cfg_attr(test, allow(clippy::all))]
#![cfg_attr(feature = "mini", no_std)]
extern crate alloc;
pub mod compat;
pub mod action;
#[cfg(feature = "desktop")]
pub mod asset;
#[cfg(feature = "desktop")]
pub mod bindings;
pub mod clipboard;
pub mod control_backend;
pub mod core;
pub mod data_binding;
#[cfg(feature = "embedded")]
pub mod embedded;
pub mod error;
pub mod event;
#[cfg(feature = "touch")]
pub mod gesture;
pub mod gpu;
#[cfg(feature = "desktop")]
pub mod i18n;
#[cfg(not(feature = "mini"))]
pub mod json;
pub mod layout;
pub mod memory;
#[cfg(feature = "advanced-widgets")]
pub mod menu_config;
pub mod object;
pub mod performance;
pub mod platform;
pub mod quality;
pub mod render;
pub mod render_engine;
pub mod shortcut;
pub mod signal;
pub mod style;
pub mod test;
#[cfg(feature = "desktop")]
pub mod theme;
pub mod undo;
pub mod util;
pub mod web;
#[cfg(feature = "gpu-wgpu")]
pub mod wgpu_backend;
pub mod widget;
pub use widget::*;
#[cfg(not(feature = "desktop"))]
#[macro_export]
macro_rules! tr {
($key:expr) => {
$key.to_string()
};
($key:expr, $count:expr) => {
$key.to_string()
};
($key:expr, $context:expr, $count:expr) => {
$key.to_string()
};
}
pub mod app;
#[cfg(feature = "chart")]
pub mod chart;
pub mod index;
#[cfg(feature = "pdf")]
pub mod pdf;
#[cfg(feature = "print")]
pub mod print;
pub fn init() {
trace_runtime_route("init");
init_runtime_backend();
init_i18n_runtime();
}
pub fn run() {
trace_runtime_route("run");
run_runtime_backend();
}
pub fn quit() {
trace_runtime_route("quit");
quit_runtime_backend();
}
fn trace_runtime_route(stage: &str) {
if std::env::var("RUST_WIDGETS_TRACE_RUNTIME").ok().as_deref() == Some("1") {
log::info!(
"[rust_widgets.runtime] stage={} profile={} backend={} route={}",
stage,
runtime_profile_name(),
platform::get_platform().backend_name(),
runtime_route_name()
);
}
}
#[cfg(feature = "desktop")]
fn runtime_profile_name() -> &'static str {
"desktop"
}
#[cfg(all(
feature = "tablet",
not(any(feature = "desktop", feature = "mobile", feature = "embedded"))
))]
fn runtime_profile_name() -> &'static str {
"tablet"
}
#[cfg(all(
feature = "mobile",
not(any(feature = "desktop", feature = "tablet", feature = "embedded"))
))]
fn runtime_profile_name() -> &'static str {
"mobile"
}
#[cfg(all(
feature = "embedded",
not(any(feature = "desktop", feature = "tablet", feature = "mobile"))
))]
fn runtime_profile_name() -> &'static str {
"embedded"
}
#[cfg(all(
feature = "profile-embedded-mini",
not(any(feature = "desktop", feature = "tablet", feature = "mobile"))
))]
fn runtime_profile_name() -> &'static str {
"embedded-mini"
}
#[cfg(all(
feature = "embedded",
not(any(
feature = "desktop",
feature = "tablet",
feature = "mobile",
feature = "profile-embedded-mini"
))
))]
fn runtime_profile_name() -> &'static str {
"embedded"
}
#[cfg(not(any(
feature = "desktop",
feature = "tablet",
feature = "mobile",
feature = "embedded",
feature = "profile-embedded-mini"
)))]
fn runtime_profile_name() -> &'static str {
"unknown"
}
#[cfg(not(any(feature = "embedded", feature = "profile-embedded-mini")))]
fn runtime_route_name() -> &'static str {
"native-platform"
}
#[cfg(any(feature = "embedded", feature = "profile-embedded-mini"))]
fn runtime_route_name() -> &'static str {
"embedded-render-engine"
}
#[cfg(not(any(feature = "embedded", feature = "profile-embedded-mini")))]
fn init_runtime_backend() {
platform::init();
}
#[cfg(any(feature = "embedded", feature = "profile-embedded-mini"))]
fn init_runtime_backend() {
render_engine::default_render_engine().init();
}
#[cfg(not(feature = "embedded"))]
fn run_runtime_backend() {
platform::run();
}
#[cfg(feature = "embedded")]
fn run_runtime_backend() {
render_engine::default_render_engine().run();
}
#[cfg(not(feature = "embedded"))]
fn quit_runtime_backend() {
platform::quit();
}
#[cfg(feature = "embedded")]
fn quit_runtime_backend() {
render_engine::default_render_engine().quit();
}
#[cfg(feature = "desktop")]
fn init_i18n_runtime() {
i18n::init();
}
#[cfg(all(not(feature = "desktop"), any(feature = "tablet", feature = "mobile")))]
fn init_i18n_runtime() {
log::debug!("i18n init skipped — i18n module not loaded on this device profile");
}
#[cfg(all(
feature = "embedded",
not(any(feature = "desktop", feature = "tablet", feature = "mobile"))
))]
fn init_i18n_runtime() {
log::debug!("i18n init skipped in embedded mode — no i18n module loaded");
}
#[cfg(not(any(
feature = "desktop",
feature = "tablet",
feature = "mobile",
feature = "embedded"
)))]
fn init_i18n_runtime() {
log::debug!("i18n init skipped — unknown device profile, no i18n module loaded");
}
pub fn create_window(
title: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_window(title, x, y, width, height)
}
pub fn create_button(
parent: crate::core::ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_button(parent, text, x, y, width, height)
}
pub fn create_checkbox(
parent: crate::core::ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_checkbox(parent, text, x, y, width, height)
}
pub fn create_line_edit(
parent: crate::core::ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_line_edit(parent, text, x, y, width, height)
}
pub fn create_label(
parent: crate::core::ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_label(parent, text, x, y, width, height)
}
pub fn create_radio_button(
parent: crate::core::ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_radio_button(parent, text, x, y, width, height)
}
pub fn create_slider(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_slider(parent, x, y, width, height)
}
pub fn create_progress_bar(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_progress_bar(parent, x, y, width, height)
}
pub fn create_combo_box(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_combo_box(parent, x, y, width, height)
}
pub fn create_list_box(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_list_box(parent, x, y, width, height)
}
pub fn create_panel(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_panel(parent, x, y, width, height)
}
pub fn create_message_box(
parent: crate::core::ObjectId,
title: &str,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_message_box(parent, title, text, x, y, width, height)
}
pub fn create_file_dialog(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_file_dialog(parent, x, y, width, height)
}
pub fn create_color_dialog(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_color_dialog(parent, x, y, width, height)
}
pub fn create_font_dialog(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_font_dialog(parent, x, y, width, height)
}
pub fn create_spin_box(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_spin_box(parent, x, y, width, height)
}
pub fn create_list_view(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_list_view(parent, x, y, width, height)
}
pub fn create_scroll_area(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_scroll_area(parent, x, y, width, height)
}
pub fn show_widget(widget_id: crate::core::ObjectId) {
platform::get_platform().show_widget(widget_id);
}
pub fn hide_widget(widget_id: crate::core::ObjectId) {
platform::get_platform().hide_widget(widget_id);
}
pub fn set_widget_geometry(
widget_id: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) {
platform::get_platform().set_widget_geometry(widget_id, x, y, width, height);
}
pub fn set_widget_text(widget_id: crate::core::ObjectId, text: &str) {
platform::get_platform().set_widget_text(widget_id, text);
}
pub fn get_widget_text(widget_id: crate::core::ObjectId) -> String {
platform::get_platform().get_widget_text(widget_id)
}
pub fn set_widget_enabled(widget_id: crate::core::ObjectId, enabled: bool) {
platform::get_platform().set_widget_enabled(widget_id, enabled);
}
pub fn is_widget_enabled(widget_id: crate::core::ObjectId) -> bool {
platform::get_platform().is_widget_enabled(widget_id)
}
pub fn set_widget_visible(widget_id: crate::core::ObjectId, visible: bool) {
platform::get_platform().set_widget_visible(widget_id, visible);
}
pub fn is_widget_visible(widget_id: crate::core::ObjectId) -> bool {
platform::get_platform().is_widget_visible(widget_id)
}
pub fn combo_box_add_item(combo_box: crate::core::ObjectId, text: &str) -> bool {
platform::get_platform().combo_box_add_item(combo_box, text)
}
pub fn combo_box_clear_items(combo_box: crate::core::ObjectId) -> bool {
platform::get_platform().combo_box_clear_items(combo_box)
}
pub fn combo_box_set_current_index(combo_box: crate::core::ObjectId, index: usize) -> bool {
platform::get_platform().combo_box_set_current_index(combo_box, index)
}
pub fn combo_box_current_index(combo_box: crate::core::ObjectId) -> Option<usize> {
platform::get_platform().combo_box_current_index(combo_box)
}
pub fn combo_box_item_count(combo_box: crate::core::ObjectId) -> usize {
platform::get_platform().combo_box_item_count(combo_box)
}
pub fn combo_box_item_text(combo_box: crate::core::ObjectId, index: usize) -> Option<String> {
platform::get_platform().combo_box_item_text(combo_box, index)
}
pub fn list_box_add_item(list_box: crate::core::ObjectId, text: &str) -> bool {
platform::get_platform().list_box_add_item(list_box, text)
}
pub fn list_box_remove_item(list_box: crate::core::ObjectId, index: usize) -> bool {
platform::get_platform().list_box_remove_item(list_box, index)
}
pub fn list_box_clear_items(list_box: crate::core::ObjectId) -> bool {
platform::get_platform().list_box_clear_items(list_box)
}
pub fn list_box_set_current_index(list_box: crate::core::ObjectId, index: usize) -> bool {
platform::get_platform().list_box_set_current_index(list_box, index)
}
pub fn list_box_current_index(list_box: crate::core::ObjectId) -> Option<usize> {
platform::get_platform().list_box_current_index(list_box)
}
pub fn list_box_item_count(list_box: crate::core::ObjectId) -> usize {
platform::get_platform().list_box_item_count(list_box)
}
pub fn list_box_item_text(list_box: crate::core::ObjectId, index: usize) -> Option<String> {
platform::get_platform().list_box_item_text(list_box, index)
}
pub fn poll_widget_triggered() -> Option<crate::core::ObjectId> {
platform::get_platform().poll_widget_triggered()
}
pub fn poll_widget_trigger_event() -> Option<WidgetTriggerEvent> {
platform::get_platform().poll_widget_trigger_event()
}
pub fn inject_widget_trigger_event(
widget_id: crate::core::ObjectId,
kind: WidgetTriggerKind,
) -> bool {
platform::get_platform().inject_widget_trigger_event(widget_id, kind)
}
pub fn set_clipboard_text(text: &str) -> bool {
platform::get_platform().set_clipboard_text(text)
}
pub fn get_clipboard_text() -> String {
platform::get_platform().get_clipboard_text()
}
pub fn platform_clipboard() -> Option<&'static dyn crate::platform::clipboard::RichClipboardBackend>
{
platform::get_platform().clipboard_backend()
}
pub fn create_menu_bar(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_menu_bar(parent, x, y, width, height)
}
pub fn create_menu(
parent: crate::core::ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_menu(parent, text, x, y, width, height)
}
pub fn attach_menu_bar_to_window(
window: crate::core::ObjectId,
menu_bar: crate::core::ObjectId,
) -> bool {
platform::get_platform().attach_menu_bar_to_window(window, menu_bar)
}
pub fn menu_add_item(
parent_menu: crate::core::ObjectId,
text: &str,
shortcut: Option<&str>,
) -> crate::core::ObjectId {
platform::get_platform().menu_add_item(parent_menu, text, shortcut)
}
pub fn poll_menu_triggered() -> Option<crate::core::ObjectId> {
platform::get_platform().poll_menu_triggered()
}
pub fn inject_menu_trigger(menu_item_id: crate::core::ObjectId) -> bool {
platform::get_platform().inject_menu_trigger(menu_item_id)
}
pub fn create_tool_bar(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_tool_bar(parent, x, y, width, height)
}
pub fn create_status_bar(
parent: crate::core::ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
platform::get_platform().create_status_bar(parent, text, x, y, width, height)
}
pub fn begin_drag(source_widget_id: crate::core::ObjectId, mime: &str, payload: &[u8]) -> bool {
platform::get_platform().begin_drag(source_widget_id, mime, payload)
}
pub fn poll_drop_event() -> Option<DropEvent> {
platform::get_platform().poll_drop_event()
}
pub fn inject_drop_event(event: DropEvent) -> bool {
platform::get_platform().inject_drop_event(event)
}
pub fn set_widget_ime_enabled(widget_id: crate::core::ObjectId, enabled: bool) -> bool {
platform::get_platform().set_widget_ime_enabled(widget_id, enabled)
}
pub fn is_widget_ime_enabled(widget_id: crate::core::ObjectId) -> bool {
platform::get_platform().is_widget_ime_enabled(widget_id)
}
pub fn platform_ime_bridge() -> Option<&'static dyn crate::platform::ime::ImeBridge> {
platform::get_platform().ime_bridge()
}
pub fn set_widget_accessibility_name(widget_id: crate::core::ObjectId, name: &str) -> bool {
platform::get_platform().set_widget_accessibility_name(widget_id, name)
}
pub fn get_widget_accessibility_name(widget_id: crate::core::ObjectId) -> String {
platform::get_platform().get_widget_accessibility_name(widget_id)
}
pub use platform::{
capabilities, dpi_scale_factor, get_platform, init as platform_init, quit as platform_quit,
run as platform_run, runtime_gui_mode, runtime_gui_mode_for, CapabilityContract,
DesktopBackend, DropEvent, EmbeddedCapabilityContract, MobileBackend, NativeCapabilityContract,
PlatformCapabilities, RuntimeGuiMode, WidgetTriggerEvent, WidgetTriggerKind,
};