#![allow(missing_docs)]
#![cfg_attr(test, allow(clippy::needless_pass_by_value, clippy::unwrap_used))]
extern crate alloc;
pub mod compat;
pub mod action;
#[cfg(feature = "desktop")]
pub mod asset;
#[cfg(feature = "audio")]
pub mod audio;
#[cfg(all(any(feature = "desktop", feature = "jni", feature = "mobile-api"), not(alloc_frugal)))]
pub mod bindings;
pub mod clipboard;
pub mod control_backend;
pub mod core;
pub mod data_binding;
#[cfg(embedded_surface)]
pub mod embedded;
pub mod error;
pub mod event;
#[cfg(feature = "touch")]
pub mod gesture;
pub mod gpu;
#[cfg(feature = "i18n")]
pub mod i18n;
#[cfg(feature = "image")]
pub mod image;
#[cfg(all(any(feature = "desktop", feature = "tablet", feature = "mobile"), widgets_unstripped))]
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;
#[cfg(feature = "video")]
pub mod video;
#[cfg(widgets_unstripped)]
pub mod web;
#[cfg(feature = "gpu-wgpu")]
pub mod wgpu_backend;
pub mod widget;
pub use widget::*;
#[cfg(not(feature = "i18n"))]
#[macro_export]
macro_rules! tr {
($key:expr) => {{
log::warn!("i18n tr! called but the i18n feature is disabled, key={}", $key);
$key.to_string()
}};
($key:expr, $count:expr) => {{
log::warn!("i18n tr! called but the i18n feature is disabled, key={}", $key);
$key.to_string()
}};
($key:expr, $context:expr, $count:expr) => {{
log::warn!("i18n tr! called but the i18n feature is disabled, key={}", $key);
$key.to_string()
}};
}
#[cfg(all(any(feature = "desktop", feature = "tablet", feature = "mobile"), widgets_unstripped))]
pub mod app;
pub mod index;
#[cfg(feature = "pdf")]
pub mod pdf;
#[cfg(feature = "print")]
pub mod print;
pub fn init() {
trace_runtime_route("init");
platform::profile::runtime_init();
platform::profile::init_optional_subsystems();
}
pub fn run() {
trace_runtime_route("run");
platform::profile::runtime_run();
}
pub fn quit() {
trace_runtime_route("quit");
platform::profile::runtime_quit();
}
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,
platform::profile::profile_name(),
platform::platform_facts().backend_name(),
platform::profile::route_name()
);
}
}
#[cfg(not(alloc_frugal))]
fn backend_for_kind(kind: widget::WidgetKind) -> &'static dyn control_backend::ControlBackend {
control_backend::get_control_backend_for_widget(kind)
}
#[cfg(not(alloc_frugal))]
#[cfg(all(not(embedded_surface), feature = "desktop"))]
const KIND_MENU_BAR: widget::WidgetKind = widget::WidgetKind::MenuBar;
#[cfg(not(alloc_frugal))]
#[cfg(not(all(not(embedded_surface), feature = "desktop")))]
const KIND_MENU_BAR: widget::WidgetKind = widget::WidgetKind::Panel;
#[cfg(not(alloc_frugal))]
#[cfg(all(not(embedded_surface), feature = "desktop"))]
const KIND_MENU: widget::WidgetKind = widget::WidgetKind::Menu;
#[cfg(not(alloc_frugal))]
#[cfg(not(all(not(embedded_surface), feature = "desktop")))]
const KIND_MENU: widget::WidgetKind = widget::WidgetKind::Panel;
#[cfg(not(alloc_frugal))]
#[cfg(all(not(embedded_surface), feature = "desktop"))]
const KIND_TOOL_BAR: widget::WidgetKind = widget::WidgetKind::ToolBar;
#[cfg(not(alloc_frugal))]
#[cfg(not(all(not(embedded_surface), feature = "desktop")))]
const KIND_TOOL_BAR: widget::WidgetKind = widget::WidgetKind::Panel;
#[cfg(not(alloc_frugal))]
#[cfg(all(not(embedded_surface), feature = "desktop"))]
const KIND_STATUS_BAR: widget::WidgetKind = widget::WidgetKind::StatusBar;
#[cfg(not(alloc_frugal))]
#[cfg(not(all(not(embedded_surface), feature = "desktop")))]
const KIND_STATUS_BAR: widget::WidgetKind = widget::WidgetKind::Panel;
#[cfg(not(alloc_frugal))]
#[cfg(all(not(embedded_surface), feature = "desktop"))]
const KIND_LIST_VIEW: widget::WidgetKind = widget::WidgetKind::ListView;
#[cfg(not(alloc_frugal))]
#[cfg(not(all(not(embedded_surface), feature = "desktop")))]
const KIND_LIST_VIEW: widget::WidgetKind = widget::WidgetKind::Panel;
#[cfg(not(alloc_frugal))]
#[cfg(full_widgets)]
const KIND_MESSAGE_BOX: widget::WidgetKind = widget::WidgetKind::MessageBox;
#[cfg(not(alloc_frugal))]
#[cfg(not(full_widgets))]
const KIND_MESSAGE_BOX: widget::WidgetKind = widget::WidgetKind::Panel;
#[cfg(not(alloc_frugal))]
#[cfg(full_widgets)]
const KIND_FILE_DIALOG: widget::WidgetKind = widget::WidgetKind::FileDialog;
#[cfg(not(alloc_frugal))]
#[cfg(not(full_widgets))]
const KIND_FILE_DIALOG: widget::WidgetKind = widget::WidgetKind::Panel;
#[cfg(not(alloc_frugal))]
#[cfg(full_widgets)]
const KIND_COLOR_DIALOG: widget::WidgetKind = widget::WidgetKind::ColorDialog;
#[cfg(not(alloc_frugal))]
#[cfg(not(full_widgets))]
const KIND_COLOR_DIALOG: widget::WidgetKind = widget::WidgetKind::Panel;
#[cfg(not(alloc_frugal))]
#[cfg(full_widgets)]
const KIND_FONT_DIALOG: widget::WidgetKind = widget::WidgetKind::FontDialog;
#[cfg(not(alloc_frugal))]
#[cfg(not(full_widgets))]
const KIND_FONT_DIALOG: widget::WidgetKind = widget::WidgetKind::Panel;
#[cfg(not(alloc_frugal))]
pub fn create_window(
title: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(widget::WidgetKind::Window).create_window(title, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_button(
parent: crate::core::ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(widget::WidgetKind::Button).create_button(parent, text, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_checkbox(
parent: crate::core::ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(widget::WidgetKind::CheckBox)
.create_checkbox(parent, text, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_line_edit(
parent: crate::core::ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(widget::WidgetKind::LineEdit)
.create_line_edit(parent, text, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_label(
parent: crate::core::ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(widget::WidgetKind::Label).create_label(parent, text, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_radio_button(
parent: crate::core::ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(widget::WidgetKind::RadioButton)
.create_radio_button(parent, text, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_slider(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(widget::WidgetKind::Slider).create_slider(parent, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_progress_bar(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(widget::WidgetKind::ProgressBar)
.create_progress_bar(parent, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_combo_box(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(widget::WidgetKind::ComboBox).create_combo_box(parent, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_list_box(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(widget::WidgetKind::ListBox).create_list_box(parent, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_panel(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(widget::WidgetKind::Panel).create_panel(parent, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_message_box(
parent: crate::core::ObjectId,
title: &str,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(KIND_MESSAGE_BOX).create_message_box(parent, title, text, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_file_dialog(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(KIND_FILE_DIALOG).create_file_dialog(parent, "", x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_color_dialog(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(KIND_COLOR_DIALOG).create_color_dialog(parent, "", x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_font_dialog(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(KIND_FONT_DIALOG).create_font_dialog(parent, "", x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_spin_box(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(widget::WidgetKind::SpinBox).create_spin_box(parent, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_list_view(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(KIND_LIST_VIEW).create_list_view(parent, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_scroll_area(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(widget::WidgetKind::ScrollArea).create_scroll_area(parent, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn mount_surface(
parent: crate::core::ObjectId,
id: crate::core::ObjectId,
rect: crate::core::Rect,
) -> bool {
platform::get_platform().mount_surface(parent, id, rect)
}
#[cfg(not(alloc_frugal))]
pub fn resize_surface(id: crate::core::ObjectId, rect: crate::core::Rect) -> bool {
platform::get_platform().resize_surface(id, rect)
}
#[cfg(not(alloc_frugal))]
pub fn unmount_surface(id: crate::core::ObjectId) -> bool {
platform::get_platform().unmount_surface(id)
}
#[cfg(not(alloc_frugal))]
pub fn invalidate_surface(id: crate::core::ObjectId) -> bool {
platform::get_platform().invalidate_surface(id)
}
#[cfg(not(alloc_frugal))]
pub fn supports_surfaces() -> bool {
platform::get_platform().supports_surfaces()
}
#[cfg(not(alloc_frugal))]
fn mount_widget_object(
parent: crate::core::ObjectId,
widget: Box<dyn widget::Widget>,
rect: crate::core::Rect,
) -> Result<crate::core::ObjectId, widget::runtime::SurfaceMountError> {
use widget::runtime::SurfaceMountError;
let id = widget::runtime::register(widget).ok_or(SurfaceMountError::NoRegistryOnThread)?;
widget::runtime::set_geometry(id, rect);
if !platform::get_platform().mount_surface(parent, id, rect) {
widget::runtime::unregister(id);
if !supports_surfaces() {
return Err(SurfaceMountError::UnsupportedByBackend(backend_name()));
}
return Err(SurfaceMountError::RejectedByBackend(backend_name()));
}
Ok(id)
}
#[cfg(not(alloc_frugal))]
pub fn create_widget_of_kind(
kind: widget::WidgetKind,
parent: crate::core::ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
widget: Option<Box<dyn widget::Widget>>,
) -> crate::core::ObjectId {
let rect = crate::core::Rect::new(x, y, width, height);
let widget = widget.or_else(|| {
#[cfg(any(feature = "desktop", feature = "tablet", feature = "mobile"))]
{
widget::WidgetFactory::new_with_defaults().create(&kind_name(kind), rect, text)
}
#[cfg(not(any(feature = "desktop", feature = "tablet", feature = "mobile")))]
{
let _ = (text, rect);
None
}
});
let Some(widget) = widget else {
log::warn!(
"create_widget_of_kind: no constructor for {kind:?} and no widget object was \
supplied; returning 0"
);
return 0;
};
match mount_widget_object(parent, widget, rect) {
Ok(id) => id,
Err(error) => {
log::warn!("create_widget_of_kind: cannot host {kind:?}: {error}");
0
}
}
}
#[cfg(all(not(alloc_frugal), full_widgets))]
fn kind_name(kind: widget::WidgetKind) -> alloc::string::String {
use alloc::string::ToString;
if let Some(capability) = widget::WidgetFactory::new_with_defaults().capability_by_kind(kind) {
return capability.canonical_name.to_string();
}
widget::capability::factory_name_for_kind(kind).to_string()
}
#[cfg(all(not(alloc_frugal), not(full_widgets)))]
#[allow(dead_code)]
fn kind_name(kind: widget::WidgetKind) -> alloc::string::String {
use alloc::string::ToString;
let debug = alloc::format!("{kind:?}");
let mut snake = alloc::string::String::with_capacity(debug.len() + 4);
for (index, ch) in debug.chars().enumerate() {
if ch.is_ascii_uppercase() {
let starts_word =
index > 0 && !debug.chars().nth(index - 1).is_some_and(|p| p.is_ascii_uppercase());
if starts_word {
snake.push('_');
}
snake.push(ch.to_ascii_lowercase());
} else {
snake.push(ch);
}
}
snake.to_string()
}
#[cfg(alloc_frugal)]
pub fn mount_surface(
_parent: crate::core::ObjectId,
_id: crate::core::ObjectId,
_rect: crate::core::Rect,
) -> bool {
false
}
#[cfg(alloc_frugal)]
pub fn resize_surface(_id: crate::core::ObjectId, _rect: crate::core::Rect) -> bool {
false
}
#[cfg(alloc_frugal)]
pub fn unmount_surface(_id: crate::core::ObjectId) -> bool {
false
}
#[cfg(alloc_frugal)]
pub fn invalidate_surface(_id: crate::core::ObjectId) -> bool {
false
}
#[cfg(alloc_frugal)]
pub fn supports_surfaces() -> bool {
false
}
#[cfg(not(alloc_frugal))]
pub fn show_widget(widget_id: crate::core::ObjectId) {
platform::get_platform().show_widget(widget_id);
}
#[cfg(not(alloc_frugal))]
pub fn hide_widget(widget_id: crate::core::ObjectId) {
platform::get_platform().hide_widget(widget_id);
}
#[cfg(not(alloc_frugal))]
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);
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_text(widget_id: crate::core::ObjectId, text: &str) {
platform::get_platform().set_widget_text(widget_id, text);
}
#[cfg(not(alloc_frugal))]
pub fn get_widget_text(widget_id: crate::core::ObjectId) -> String {
platform::get_platform().get_widget_text(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_enabled(widget_id: crate::core::ObjectId, enabled: bool) {
platform::get_platform().set_widget_enabled(widget_id, enabled);
}
#[cfg(not(alloc_frugal))]
pub fn is_widget_enabled(widget_id: crate::core::ObjectId) -> bool {
platform::get_platform().is_widget_enabled(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_visible(widget_id: crate::core::ObjectId, visible: bool) {
platform::get_platform().set_widget_visible(widget_id, visible);
}
#[cfg(not(alloc_frugal))]
pub fn is_widget_visible(widget_id: crate::core::ObjectId) -> bool {
platform::get_platform().is_widget_visible(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_value(widget_id: crate::core::ObjectId, value: f64) -> bool {
platform::get_platform().set_widget_value(widget_id, value)
}
#[cfg(not(alloc_frugal))]
pub fn widget_value(widget_id: crate::core::ObjectId) -> Option<f64> {
platform::get_platform().widget_value(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_range(widget_id: crate::core::ObjectId, min: f64, max: f64) -> bool {
platform::get_platform().set_widget_range(widget_id, min, max)
}
#[cfg(not(alloc_frugal))]
pub fn widget_range(widget_id: crate::core::ObjectId) -> Option<(f64, f64)> {
platform::get_platform().widget_range(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_selected_index(widget_id: crate::core::ObjectId, index: Option<usize>) -> bool {
platform::get_platform().set_widget_selected_index(widget_id, index)
}
#[cfg(not(alloc_frugal))]
pub fn widget_selected_index(widget_id: crate::core::ObjectId) -> Option<usize> {
platform::get_platform().widget_selected_index(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_checked(widget_id: crate::core::ObjectId, checked: bool) -> bool {
platform::get_platform().set_widget_checked(widget_id, checked)
}
#[cfg(not(alloc_frugal))]
pub fn is_widget_checked(widget_id: crate::core::ObjectId) -> Option<bool> {
platform::get_platform().is_widget_checked(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_step(widget_id: crate::core::ObjectId, step: f64) -> bool {
platform::get_platform().set_widget_step(widget_id, step)
}
#[cfg(not(alloc_frugal))]
pub fn widget_step(widget_id: crate::core::ObjectId) -> Option<f64> {
platform::get_platform().widget_step(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_indeterminate(widget_id: crate::core::ObjectId, indeterminate: bool) -> bool {
platform::get_platform().set_widget_indeterminate(widget_id, indeterminate)
}
#[cfg(not(alloc_frugal))]
pub fn is_widget_indeterminate(widget_id: crate::core::ObjectId) -> Option<bool> {
platform::get_platform().is_widget_indeterminate(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_read_only(widget_id: crate::core::ObjectId, read_only: bool) -> bool {
platform::get_platform().set_widget_read_only(widget_id, read_only)
}
#[cfg(not(alloc_frugal))]
pub fn is_widget_read_only(widget_id: crate::core::ObjectId) -> Option<bool> {
platform::get_platform().is_widget_read_only(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_max_length(widget_id: crate::core::ObjectId, max_length: u32) -> bool {
platform::get_platform().set_widget_max_length(widget_id, max_length)
}
#[cfg(not(alloc_frugal))]
pub fn widget_max_length(widget_id: crate::core::ObjectId) -> Option<u32> {
platform::get_platform().widget_max_length(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_window_state(
widget_id: crate::core::ObjectId,
flag: platform::WindowStateFlag,
on: bool,
) -> bool {
platform::get_platform().set_window_state(widget_id, flag, on)
}
#[cfg(not(alloc_frugal))]
pub fn is_window_in_state(
widget_id: crate::core::ObjectId,
flag: platform::WindowStateFlag,
) -> Option<bool> {
platform::get_platform().is_window_in_state(widget_id, flag)
}
#[cfg(not(alloc_frugal))]
pub fn set_window_min_size(widget_id: crate::core::ObjectId, width: u32, height: u32) -> bool {
platform::get_platform().set_window_min_size(widget_id, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn window_min_size(widget_id: crate::core::ObjectId) -> Option<(u32, u32)> {
platform::get_platform().window_min_size(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_window_icon(widget_id: crate::core::ObjectId, path: &str) -> bool {
platform::get_platform().set_window_icon(widget_id, path)
}
#[cfg(not(alloc_frugal))]
pub fn window_icon(widget_id: crate::core::ObjectId) -> Option<String> {
platform::get_platform().window_icon(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_selection(widget_id: crate::core::ObjectId, start: u32, end: u32) -> bool {
platform::get_platform().set_widget_selection(widget_id, start, end)
}
#[cfg(not(alloc_frugal))]
pub fn widget_selection(widget_id: crate::core::ObjectId) -> Option<(u32, u32)> {
platform::get_platform().widget_selection(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_placeholder(widget_id: crate::core::ObjectId, text: &str) -> bool {
platform::get_platform().set_widget_placeholder(widget_id, text)
}
#[cfg(not(alloc_frugal))]
pub fn widget_placeholder(widget_id: crate::core::ObjectId) -> Option<String> {
platform::get_platform().widget_placeholder(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_echo_mode(widget_id: crate::core::ObjectId, mode: platform::EchoMode) -> bool {
platform::get_platform().set_widget_echo_mode(widget_id, mode)
}
#[cfg(not(alloc_frugal))]
pub fn widget_echo_mode(widget_id: crate::core::ObjectId) -> Option<platform::EchoMode> {
platform::get_platform().widget_echo_mode(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_slider_orientation(
widget_id: crate::core::ObjectId,
orientation: crate::core::Orientation,
) -> bool {
platform::get_platform().set_slider_orientation(widget_id, orientation)
}
#[cfg(not(alloc_frugal))]
pub fn slider_orientation(widget_id: crate::core::ObjectId) -> Option<crate::core::Orientation> {
platform::get_platform().slider_orientation(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_tristate(widget_id: crate::core::ObjectId, enabled: bool) -> bool {
platform::get_platform().set_widget_tristate(widget_id, enabled)
}
#[cfg(not(alloc_frugal))]
pub fn is_widget_tristate(widget_id: crate::core::ObjectId) -> Option<bool> {
platform::get_platform().is_widget_tristate(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_group(widget_id: crate::core::ObjectId, group: &str) -> bool {
platform::get_platform().set_widget_group(widget_id, group)
}
#[cfg(not(alloc_frugal))]
pub fn widget_group(widget_id: crate::core::ObjectId) -> Option<String> {
platform::get_platform().widget_group(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_scroll_position(widget_id: crate::core::ObjectId, x: i32, y: i32) -> bool {
platform::get_platform().set_widget_scroll_position(widget_id, x, y)
}
#[cfg(not(alloc_frugal))]
pub fn widget_scroll_position(widget_id: crate::core::ObjectId) -> Option<(i32, i32)> {
platform::get_platform().widget_scroll_position(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn combo_box_add_item(combo_box: crate::core::ObjectId, text: &str) -> bool {
platform::get_platform().combo_box_add_item(combo_box, text)
}
#[cfg(not(alloc_frugal))]
pub fn combo_box_clear_items(combo_box: crate::core::ObjectId) -> bool {
platform::get_platform().combo_box_clear_items(combo_box)
}
#[cfg(not(alloc_frugal))]
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)
}
#[cfg(not(alloc_frugal))]
pub fn combo_box_current_index(combo_box: crate::core::ObjectId) -> Option<usize> {
platform::get_platform().combo_box_current_index(combo_box)
}
#[cfg(not(alloc_frugal))]
pub fn combo_box_item_count(combo_box: crate::core::ObjectId) -> usize {
platform::get_platform().combo_box_item_count(combo_box)
}
#[cfg(not(alloc_frugal))]
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)
}
#[cfg(not(alloc_frugal))]
pub fn list_box_add_item(list_box: crate::core::ObjectId, text: &str) -> bool {
platform::get_platform().list_box_add_item(list_box, text)
}
#[cfg(not(alloc_frugal))]
pub fn list_box_remove_item(list_box: crate::core::ObjectId, index: usize) -> bool {
platform::get_platform().list_box_remove_item(list_box, index)
}
#[cfg(not(alloc_frugal))]
pub fn list_box_clear_items(list_box: crate::core::ObjectId) -> bool {
platform::get_platform().list_box_clear_items(list_box)
}
#[cfg(not(alloc_frugal))]
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)
}
#[cfg(not(alloc_frugal))]
pub fn list_box_current_index(list_box: crate::core::ObjectId) -> Option<usize> {
platform::get_platform().list_box_current_index(list_box)
}
#[cfg(not(alloc_frugal))]
pub fn list_box_item_count(list_box: crate::core::ObjectId) -> usize {
platform::get_platform().list_box_item_count(list_box)
}
#[cfg(not(alloc_frugal))]
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)
}
#[cfg(not(alloc_frugal))]
pub fn poll_widget_triggered() -> Option<crate::core::ObjectId> {
platform::get_platform().poll_widget_triggered()
}
#[cfg(not(alloc_frugal))]
pub fn poll_widget_trigger_event() -> Option<WidgetTriggerEvent> {
platform::get_platform().poll_widget_trigger_event()
}
#[cfg(not(alloc_frugal))]
pub fn inject_widget_trigger_event(
widget_id: crate::core::ObjectId,
kind: WidgetTriggerKind,
) -> bool {
platform::get_platform().inject_widget_trigger_event(widget_id, kind)
}
#[cfg(not(alloc_frugal))]
pub fn set_clipboard_text(text: &str) -> bool {
platform::get_platform().set_clipboard_text(text)
}
#[cfg(not(alloc_frugal))]
pub fn get_clipboard_text() -> String {
platform::get_platform().get_clipboard_text()
}
#[cfg(not(alloc_frugal))]
pub fn platform_clipboard() -> Option<&'static dyn crate::platform::clipboard::RichClipboardBackend>
{
platform::get_platform().clipboard_backend()
}
#[cfg(not(alloc_frugal))]
pub fn create_menu_bar(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(KIND_MENU_BAR).create_menu_bar(parent, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_menu(
parent: crate::core::ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(KIND_MENU).create_menu(parent, text, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
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)
}
#[cfg(not(alloc_frugal))]
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)
}
#[cfg(not(alloc_frugal))]
pub fn format_shortcut(shortcut: &crate::shortcut::Shortcut) -> String {
platform::get_platform().format_shortcut(shortcut)
}
#[cfg(not(alloc_frugal))]
pub fn poll_menu_triggered() -> Option<crate::core::ObjectId> {
platform::get_platform().poll_menu_triggered()
}
#[cfg(not(alloc_frugal))]
pub fn menu_item_shortcut(menu_item: crate::core::ObjectId) -> Option<String> {
platform::get_platform().menu_item_shortcut(menu_item)
}
#[cfg(not(alloc_frugal))]
pub fn native_handle(widget: crate::core::ObjectId) -> Option<usize> {
platform::get_platform().get_native_handle(widget)
}
#[cfg(not(alloc_frugal))]
pub fn inject_menu_trigger(menu_item_id: crate::core::ObjectId) -> bool {
platform::get_platform().inject_menu_trigger(menu_item_id)
}
#[cfg(not(alloc_frugal))]
pub fn create_tool_bar(
parent: crate::core::ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(KIND_TOOL_BAR).create_tool_bar(parent, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
pub fn create_status_bar(
parent: crate::core::ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
backend_for_kind(KIND_STATUS_BAR).create_status_bar(parent, text, x, y, width, height)
}
#[cfg(not(alloc_frugal))]
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)
}
#[cfg(not(alloc_frugal))]
pub fn poll_drop_event() -> Option<DropEvent> {
platform::get_platform().poll_drop_event()
}
#[cfg(not(alloc_frugal))]
pub fn inject_drop_event(event: DropEvent) -> bool {
platform::get_platform().inject_drop_event(event)
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_ime_enabled(widget_id: crate::core::ObjectId, enabled: bool) -> bool {
platform::get_platform().set_widget_ime_enabled(widget_id, enabled)
}
#[cfg(not(alloc_frugal))]
pub fn is_widget_ime_enabled(widget_id: crate::core::ObjectId) -> bool {
platform::get_platform().is_widget_ime_enabled(widget_id)
}
#[cfg(not(alloc_frugal))]
pub fn platform_ime_bridge() -> Option<&'static dyn crate::platform::ime::ImeBridge> {
platform::get_platform().ime_bridge()
}
#[cfg(not(alloc_frugal))]
pub fn set_widget_accessibility_name(widget_id: crate::core::ObjectId, name: &str) -> bool {
platform::get_platform().set_widget_accessibility_name(widget_id, name)
}
#[cfg(not(alloc_frugal))]
pub fn get_widget_accessibility_name(widget_id: crate::core::ObjectId) -> String {
platform::get_platform().get_widget_accessibility_name(widget_id)
}
#[cfg(not(alloc_frugal))]
pub use platform::{
backend_name, 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,
};
pub use platform::{
CapabilityContract, DesktopBackend, DropEvent, EmbeddedCapabilityContract, MobileBackend,
NativeCapabilityContract, PlatformCapabilities, RuntimeGuiMode, WidgetTriggerEvent,
WidgetTriggerKind, WindowStateFlag,
};
#[allow(deprecated)]
pub mod deprecated {
#[deprecated(
note = "renamed to `mount_surface`; 'custom' named a mechanism that no longer exists"
)]
pub fn mount_custom_widget(
parent: crate::core::ObjectId,
id: crate::core::ObjectId,
rect: crate::core::Rect,
) -> bool {
crate::mount_surface(parent, id, rect)
}
#[deprecated(
note = "renamed to `resize_surface`; 'custom' named a mechanism that no longer exists"
)]
pub fn resize_custom_widget(id: crate::core::ObjectId, rect: crate::core::Rect) -> bool {
crate::resize_surface(id, rect)
}
#[deprecated(
note = "renamed to `unmount_surface`; 'custom' named a mechanism that no longer exists"
)]
pub fn unmount_custom_widget(id: crate::core::ObjectId) -> bool {
crate::unmount_surface(id)
}
#[deprecated(
note = "renamed to `invalidate_surface`; 'custom' named a mechanism that no longer exists"
)]
pub fn request_custom_repaint(id: crate::core::ObjectId) -> bool {
crate::invalidate_surface(id)
}
#[deprecated(
note = "renamed to `supports_surfaces`; 'custom' named a mechanism that no longer exists"
)]
pub fn supports_custom_widgets() -> bool {
crate::supports_surfaces()
}
}
#[allow(deprecated)]
pub use deprecated::{
mount_custom_widget, request_custom_repaint, resize_custom_widget, supports_custom_widgets,
unmount_custom_widget,
};
#[cfg(test)]
mod docs_paths_tests;
#[cfg(test)]
mod compat_path_tests {
#[test]
#[allow(deprecated)]
fn old_surface_names_still_resolve_at_the_crate_root() {
let _: fn(crate::core::ObjectId, crate::core::ObjectId, crate::core::Rect) -> bool =
crate::mount_custom_widget;
let _: fn(crate::core::ObjectId, crate::core::Rect) -> bool = crate::resize_custom_widget;
let _: fn(crate::core::ObjectId) -> bool = crate::unmount_custom_widget;
let _: fn(crate::core::ObjectId) -> bool = crate::request_custom_repaint;
let _: fn() -> bool = crate::supports_custom_widgets;
}
#[test]
#[allow(deprecated)]
fn deprecated_aliases_delegate_to_the_surface_api() {
assert_eq!(crate::supports_custom_widgets(), crate::supports_surfaces());
}
}