Skip to main content

native_gui_core/
lib.rs

1//! `native-gui-core` is the backend-independent core of `native-gui`, a
2//! cross-platform GUI library for Rust desktop applications that drives the
3//! operating system's own controls (Win32, GTK4, Cocoa) through pluggable
4//! backends. Applications normally depend on the `native-gui` facade crate.
5//!
6//! The crate exposes:
7//! - a shared widget model (`WidgetKind`, `WidgetSpec`, including `TextArea`, `FileChooserDialog`, `AlertDialog`, and `VulkanCanvas`)
8//! - a backend-agnostic UI manager (`Ui`)
9//! - event and callback dispatch (`UiEvent`, `dispatch_events`)
10//! - menu APIs (`create_menu`, `add_menu_item`, `attach_menu_to_window`)
11//! - container orientation control (`ContainerDirection`)
12//! - data list/grid and clipboard operations (`set_data_list_items`, `set_data_grid_rows`, `copy_to_clipboard`, `paste_from_clipboard`)
13//! - portable accessibility metadata (`AccessibilitySpec`, `AccessibleRole`, `AccessibilityState`)
14//! - focus and tab-order model (`Ui::focus`, `Ui::focus_next`, `Ui::set_focusable`)
15//! - theme tokens and light/dark modes (`Theme`, `Ui::set_theme`, `Ui::set_theme_override`)
16//!
17//! The application bootstrap (`app::run`, `app::App`) and the
18//! developer-experience prelude (`native_gui::prelude`) live in the `native-gui` facade
19//! crate, which re-exports this one.
20//!
21//! # Quick start (mock backend)
22//!
23//! ```rust
24//! use native_gui_mock::MockBackend;
25//! use native_gui_core::{ContainerDirection, Ui, WidgetKind};
26//!
27//! # fn main() -> native_gui_core::GuiResult<()> {
28//! let backend = MockBackend::default();
29//! let mut ui = Ui::new(backend);
30//!
31//! let window = ui.create(WidgetKind::Window, Some("Native GUI Demo"))?;
32//! let container = ui.create(WidgetKind::Container, None)?;
33//! let label = ui.create(WidgetKind::Label, Some("Hello from Native GUI!"))?;
34//!
35//! ui.set_container_direction(container, ContainerDirection::Vertical)?;
36//! ui.attach(window, container)?;
37//! ui.attach(container, label)?;
38//! ui.show(window)?;
39//! # Ok(())
40//! # }
41//! ```
42//!
43//! For full platform examples, see the `examples/` directory and `docs/guides/tutorial.md`.
44//!
45//! # Module features
46//!
47//! Defaults select `full`, enabling the core modules (`i18n`, `window-state`,
48//! `bindings`, `routes`, `async`, `displays`, `declarative`, and all widget
49//! families). Serialization support is opt-in through `serde`; window-state JSON helpers
50//! require both `window-state` and `serde`. A no-default consumer keeps the
51//! widget model, `Ui`, layout, accessibility, focus, and backend contract
52//! while selecting module features explicitly. Display capability reporting
53//! and pointer-scale projection remain part of that contract; `displays`
54//! enables enumeration types/methods and display-change events. The `mock`
55//! feature implies `displays` for the `native-gui-mock` crate.
56
57#![deny(rustdoc::broken_intra_doc_links)]
58pub mod access;
59pub mod advanced;
60pub mod artprov;
61#[cfg(feature = "async")]
62pub mod async_ui;
63pub mod autoclose;
64#[doc(hidden)]
65pub mod backend_support;
66#[cfg(feature = "bindings")]
67pub mod bindings;
68pub mod canvas;
69#[cfg(feature = "declarative")]
70pub mod declarative;
71pub mod demo_cube;
72pub mod displays;
73pub mod drag;
74pub mod error;
75pub mod events;
76pub mod file_dialog;
77
78pub mod focus;
79#[cfg(feature = "i18n")]
80pub mod i18n;
81pub mod image_resource;
82pub mod layout;
83pub mod menus;
84pub mod motion;
85pub mod pickers;
86pub mod properties;
87#[cfg(feature = "property-grid")]
88pub mod property_grid;
89#[cfg(feature = "routes")]
90pub mod routes;
91pub mod state;
92#[cfg(feature = "styled-text")]
93pub mod styled_text;
94/// Wall-clock test budgets that stay tight locally and widen in CI.
95#[doc(hidden)]
96pub mod test_budget;
97pub mod theme;
98pub mod timer;
99pub mod toolbar;
100pub mod tray;
101pub mod ui;
102#[cfg(feature = "webview")]
103pub mod webview;
104pub mod widgets;
105pub mod window_handle;
106#[cfg(feature = "window-state")]
107pub mod window_state;
108pub mod windowing;
109
110pub use access::{AccessibilitySpec, AccessibilityState, AccessibleAction, AccessibleRole};
111pub use advanced::{
112    AdvancedFamily, AdvancedHostCapabilities, DecisionCounters, DecisionOutcome, DecisionToken,
113    EngineInfo, OperationId,
114};
115#[cfg(feature = "property-grid")]
116pub use advanced::{BatchReport, BatchScope, PropertyGridBackend, PropertyGridCapabilities};
117pub use artprov::{ArtCapabilities, IconRole, IconSize, IconSource, StockIcon};
118#[cfg(feature = "async")]
119pub use async_ui::{
120    TaskClass, TaskCommand, TaskDrainReport, TaskEvent, TaskHandle, TaskId, TaskSendError,
121    TaskToken, UiProxy, DEFAULT_TASK_QUEUE_CAPACITY,
122};
123pub use autoclose::Autoclose;
124#[cfg(feature = "bindings")]
125pub use bindings::Bindings;
126pub use canvas::{
127    CanvasBufferCost, CanvasDamage, CanvasDamageAccumulator, CanvasStrokeCoalescingPolicy,
128};
129pub use demo_cube::{project_demo_cube, DemoCubeFace, DEMO_CUBE_BOTTOM, DEMO_CUBE_TOP};
130pub use displays::{logical_pointer_projection, DisplayCapabilities};
131#[cfg(feature = "displays")]
132pub use displays::{DisplayInfo, DisplayRect};
133pub use drag::{
134    DragCapabilities, DragPayload, DragPayloadKind, DragSessionId, DragSourceOptions,
135    DragTargetOptions, DropCancelReason, DropEffect, MAX_DRAG_PAYLOAD_BYTES,
136};
137pub use error::{GuiError, GuiResult};
138pub use events::{AccessibleNotification, UiEvent};
139pub use file_dialog::{FileDialog, FileFilter};
140pub use focus::{default_focusable, is_focusable};
141pub use image_resource::{
142    ImageData, ImageResourceCapabilities, ImageResourceId, MAX_IMAGE_RESOURCE_BYTES,
143    MAX_IMAGE_RESOURCE_BYTES_PER_UI,
144};
145pub use menus::{MenuId, MenuItemId};
146pub use motion::{MotionCapabilities, MotionId, MotionSpec, MOTION_TICK_CADENCE};
147pub use pickers::{
148    ColorDialogData, FontDescriptor, FontDialogData, FontEffects, FontWeight, PickerError,
149    PickerResult, Rgba, MAX_CUSTOM_COLORS,
150};
151pub use properties::{
152    ChangeToken, DenialReason, PendingChange, ProjectionMode, PropertyEditor, PropertyError,
153    PropertyEvent, PropertyId, PropertyModel, PropertyNode, PropertyNodeKind, PropertyResult,
154    PropertyRow, PropertyValue,
155};
156#[cfg(feature = "property-grid")]
157pub use property_grid::{
158    format_property_value, parse_property_text, PropertyEditorWidget, PropertyGridFeatures,
159    DEFAULT_PROPERTY_LABEL_WIDTH, PROPERTY_GRID_FEATURES,
160};
161#[cfg(feature = "routes")]
162pub use routes::Routes;
163#[cfg(feature = "styled-text")]
164pub use styled_text::{
165    builtin_lexer, FindOptions, IndicatorId, JsonLexer, MarkerId, PlainLexer, RustLexer, StyleId,
166    StyleTable, StyledDocument, StyledTextEdit, StyledTextError, StyledTextLexer, StyledTextResult,
167};
168pub use theme::{
169    HighContrastPreset, Theme, ThemeCapabilities, ThemeColors, ThemeMode, ThemeOverride,
170    ThemeSpacing, ThemeTypography,
171};
172pub use timer::{TimerCapabilities, TimerFire, TimerId, TimerSpec, TimerStopPolicy};
173pub use toolbar::{
174    ToolDisplay, ToolId, ToolInteraction, ToolSpec, ToolUpdate, ToolbarError, ToolbarItem,
175    ToolbarOrientation,
176};
177pub use tray::{TrayEvent, TrayIconId, TrayIconSpec};
178pub use ui::{
179    Backend, Capability, InputMode, LoopFlow, MetalCanvasHandle, Operation, RunStop, Ui,
180    VulkanCanvasHandle,
181};
182#[cfg(feature = "webview")]
183pub use webview::{
184    WebViewBackend, WebViewCommand, WebViewContent, WebViewError, WebViewOptions, WebViewState,
185};
186pub use widgets::{
187    abstractable_widget_types, apply_row_ops_to_cells, apply_row_ops_to_items,
188    apply_row_ops_to_rows, diff_row_ops, AlertLevel, CalendarDate, CalendarFirstDayOfWeek,
189    CalendarSelectionMode, CanvasPrimitive, CanvasRect, CanvasScene, CanvasSurface, Color,
190    ColumnSpec, ContainerDirection, ContainerWrap, FileChooserMode, GpuDegradationPolicy,
191    GpuSurfaceCapabilities, ImageFit, LabelAlignment, LabelWrap, LabelWrapMode, RichTextImage,
192    RowDelta, RowKey, RowOp, RowSet, TextRun, TextStyle, TreeItem, WidgetId, WidgetKind,
193    WidgetProperty, WidgetSpec,
194};
195#[cfg(feature = "window-state")]
196pub use window_state::{clamp_to_displays, RectGeometry, WindowGeometry, WindowShowState};
197#[cfg(all(feature = "window-state", feature = "serde"))]
198pub use window_state::{
199    get_window_state_path, load_window_geometry_from_path, save_window_geometry_to_path,
200};
201pub use windowing::{
202    AnchorEdge, PopupDismissReason, ShowEffect, Stacking, WindowCapabilities, WindowFocusPolicy,
203    WindowOptions, WindowPlacement, WindowRole, WindowShape,
204};
205
206// ---------------------------------------------------------------------------
207// Test-only Mock backend
208// ---------------------------------------------------------------------------
209//
210// Unit tests in `ui.rs`, `declarative.rs`, `bindings.rs`, and `advanced.rs` use
211// the shared Mock backend. A direct dependency on `native-gui-mock` does not work for
212// `#[cfg(test)]` because tests compile as a distinct crate. We therefore embed
213// `native-gui-mock/src/lib.rs` under this crate's identity (via `extern crate self as native_gui_core`
214// and the `test_support` module). The module is `#[cfg(test)]`-gated only.
215//
216// See `crates/native-gui-core/Cargo.toml` dev-dependency note and the CI step that
217// runs `cargo check -p native-gui-core --all-targets`.
218#[cfg(any(test, feature = "mock"))]
219extern crate self as native_gui_core;
220
221#[cfg(any(test, feature = "mock"))]
222#[doc(hidden)]
223// The included source is `native-gui-mock`'s, so its `#[cfg(feature = "e2e")]` gates
224// are never expected in this crate's feature set; they stay disabled here.
225#[allow(unexpected_cfgs)]
226#[path = "../../native-gui-mock/src/lib.rs"]
227pub mod test_support;