native-gui-core 1.0.0

Core abstraction, widget model, and layout engine for Native GUI
Documentation
//! `native-gui-core` is the backend-independent core of `native-gui`, a
//! cross-platform GUI library for Rust desktop applications that drives the
//! operating system's own controls (Win32, GTK4, Cocoa) through pluggable
//! backends. Applications normally depend on the `native-gui` facade crate.
//!
//! The crate exposes:
//! - a shared widget model (`WidgetKind`, `WidgetSpec`, including `TextArea`, `FileChooserDialog`, `AlertDialog`, and `VulkanCanvas`)
//! - a backend-agnostic UI manager (`Ui`)
//! - event and callback dispatch (`UiEvent`, `dispatch_events`)
//! - menu APIs (`create_menu`, `add_menu_item`, `attach_menu_to_window`)
//! - container orientation control (`ContainerDirection`)
//! - data list/grid and clipboard operations (`set_data_list_items`, `set_data_grid_rows`, `copy_to_clipboard`, `paste_from_clipboard`)
//! - portable accessibility metadata (`AccessibilitySpec`, `AccessibleRole`, `AccessibilityState`)
//! - focus and tab-order model (`Ui::focus`, `Ui::focus_next`, `Ui::set_focusable`)
//! - theme tokens and light/dark modes (`Theme`, `Ui::set_theme`, `Ui::set_theme_override`)
//!
//! The application bootstrap (`app::run`, `app::App`) and the
//! developer-experience prelude (`native_gui::prelude`) live in the `native-gui` facade
//! crate, which re-exports this one.
//!
//! # Quick start (mock backend)
//!
//! ```rust
//! use native_gui_mock::MockBackend;
//! use native_gui_core::{ContainerDirection, Ui, WidgetKind};
//!
//! # fn main() -> native_gui_core::GuiResult<()> {
//! let backend = MockBackend::default();
//! let mut ui = Ui::new(backend);
//!
//! let window = ui.create(WidgetKind::Window, Some("Native GUI Demo"))?;
//! let container = ui.create(WidgetKind::Container, None)?;
//! let label = ui.create(WidgetKind::Label, Some("Hello from Native GUI!"))?;
//!
//! ui.set_container_direction(container, ContainerDirection::Vertical)?;
//! ui.attach(window, container)?;
//! ui.attach(container, label)?;
//! ui.show(window)?;
//! # Ok(())
//! # }
//! ```
//!
//! For full platform examples, see the `examples/` directory and `docs/guides/tutorial.md`.
//!
//! # Module features
//!
//! Defaults select `full`, enabling the core modules (`i18n`, `window-state`,
//! `bindings`, `routes`, `async`, `displays`, `declarative`, and all widget
//! families). Serialization support is opt-in through `serde`; window-state JSON helpers
//! require both `window-state` and `serde`. A no-default consumer keeps the
//! widget model, `Ui`, layout, accessibility, focus, and backend contract
//! while selecting module features explicitly. Display capability reporting
//! and pointer-scale projection remain part of that contract; `displays`
//! enables enumeration types/methods and display-change events. The `mock`
//! feature implies `displays` for the `native-gui-mock` crate.

#![deny(rustdoc::broken_intra_doc_links)]
pub mod access;
pub mod advanced;
pub mod artprov;
#[cfg(feature = "async")]
pub mod async_ui;
pub mod autoclose;
#[doc(hidden)]
pub mod backend_support;
#[cfg(feature = "bindings")]
pub mod bindings;
pub mod canvas;
#[cfg(feature = "declarative")]
pub mod declarative;
pub mod demo_cube;
pub mod displays;
pub mod drag;
pub mod error;
pub mod events;
pub mod file_dialog;

pub mod focus;
#[cfg(feature = "i18n")]
pub mod i18n;
pub mod image_resource;
pub mod layout;
pub mod menus;
pub mod motion;
pub mod pickers;
pub mod properties;
#[cfg(feature = "property-grid")]
pub mod property_grid;
#[cfg(feature = "routes")]
pub mod routes;
pub mod state;
#[cfg(feature = "styled-text")]
pub mod styled_text;
/// Wall-clock test budgets that stay tight locally and widen in CI.
#[doc(hidden)]
pub mod test_budget;
pub mod theme;
pub mod timer;
pub mod toolbar;
pub mod tray;
pub mod ui;
#[cfg(feature = "webview")]
pub mod webview;
pub mod widgets;
pub mod window_handle;
#[cfg(feature = "window-state")]
pub mod window_state;
pub mod windowing;

pub use access::{AccessibilitySpec, AccessibilityState, AccessibleAction, AccessibleRole};
pub use advanced::{
    AdvancedFamily, AdvancedHostCapabilities, DecisionCounters, DecisionOutcome, DecisionToken,
    EngineInfo, OperationId,
};
#[cfg(feature = "property-grid")]
pub use advanced::{BatchReport, BatchScope, PropertyGridBackend, PropertyGridCapabilities};
pub use artprov::{ArtCapabilities, IconRole, IconSize, IconSource, StockIcon};
#[cfg(feature = "async")]
pub use async_ui::{
    TaskClass, TaskCommand, TaskDrainReport, TaskEvent, TaskHandle, TaskId, TaskSendError,
    TaskToken, UiProxy, DEFAULT_TASK_QUEUE_CAPACITY,
};
pub use autoclose::Autoclose;
#[cfg(feature = "bindings")]
pub use bindings::Bindings;
pub use canvas::{
    CanvasBufferCost, CanvasDamage, CanvasDamageAccumulator, CanvasStrokeCoalescingPolicy,
};
pub use demo_cube::{project_demo_cube, DemoCubeFace, DEMO_CUBE_BOTTOM, DEMO_CUBE_TOP};
pub use displays::{logical_pointer_projection, DisplayCapabilities};
#[cfg(feature = "displays")]
pub use displays::{DisplayInfo, DisplayRect};
pub use drag::{
    DragCapabilities, DragPayload, DragPayloadKind, DragSessionId, DragSourceOptions,
    DragTargetOptions, DropCancelReason, DropEffect, MAX_DRAG_PAYLOAD_BYTES,
};
pub use error::{GuiError, GuiResult};
pub use events::{AccessibleNotification, UiEvent};
pub use file_dialog::{FileDialog, FileFilter};
pub use focus::{default_focusable, is_focusable};
pub use image_resource::{
    ImageData, ImageResourceCapabilities, ImageResourceId, MAX_IMAGE_RESOURCE_BYTES,
    MAX_IMAGE_RESOURCE_BYTES_PER_UI,
};
pub use menus::{MenuId, MenuItemId};
pub use motion::{MotionCapabilities, MotionId, MotionSpec, MOTION_TICK_CADENCE};
pub use pickers::{
    ColorDialogData, FontDescriptor, FontDialogData, FontEffects, FontWeight, PickerError,
    PickerResult, Rgba, MAX_CUSTOM_COLORS,
};
pub use properties::{
    ChangeToken, DenialReason, PendingChange, ProjectionMode, PropertyEditor, PropertyError,
    PropertyEvent, PropertyId, PropertyModel, PropertyNode, PropertyNodeKind, PropertyResult,
    PropertyRow, PropertyValue,
};
#[cfg(feature = "property-grid")]
pub use property_grid::{
    format_property_value, parse_property_text, PropertyEditorWidget, PropertyGridFeatures,
    DEFAULT_PROPERTY_LABEL_WIDTH, PROPERTY_GRID_FEATURES,
};
#[cfg(feature = "routes")]
pub use routes::Routes;
#[cfg(feature = "styled-text")]
pub use styled_text::{
    builtin_lexer, FindOptions, IndicatorId, JsonLexer, MarkerId, PlainLexer, RustLexer, StyleId,
    StyleTable, StyledDocument, StyledTextEdit, StyledTextError, StyledTextLexer, StyledTextResult,
};
pub use theme::{
    HighContrastPreset, Theme, ThemeCapabilities, ThemeColors, ThemeMode, ThemeOverride,
    ThemeSpacing, ThemeTypography,
};
pub use timer::{TimerCapabilities, TimerFire, TimerId, TimerSpec, TimerStopPolicy};
pub use toolbar::{
    ToolDisplay, ToolId, ToolInteraction, ToolSpec, ToolUpdate, ToolbarError, ToolbarItem,
    ToolbarOrientation,
};
pub use tray::{TrayEvent, TrayIconId, TrayIconSpec};
pub use ui::{
    Backend, Capability, InputMode, LoopFlow, MetalCanvasHandle, Operation, RunStop, Ui,
    VulkanCanvasHandle,
};
#[cfg(feature = "webview")]
pub use webview::{
    WebViewBackend, WebViewCommand, WebViewContent, WebViewError, WebViewOptions, WebViewState,
};
pub use widgets::{
    abstractable_widget_types, apply_row_ops_to_cells, apply_row_ops_to_items,
    apply_row_ops_to_rows, diff_row_ops, AlertLevel, CalendarDate, CalendarFirstDayOfWeek,
    CalendarSelectionMode, CanvasPrimitive, CanvasRect, CanvasScene, CanvasSurface, Color,
    ColumnSpec, ContainerDirection, ContainerWrap, FileChooserMode, GpuDegradationPolicy,
    GpuSurfaceCapabilities, ImageFit, LabelAlignment, LabelWrap, LabelWrapMode, RichTextImage,
    RowDelta, RowKey, RowOp, RowSet, TextRun, TextStyle, TreeItem, WidgetId, WidgetKind,
    WidgetProperty, WidgetSpec,
};
#[cfg(feature = "window-state")]
pub use window_state::{clamp_to_displays, RectGeometry, WindowGeometry, WindowShowState};
#[cfg(all(feature = "window-state", feature = "serde"))]
pub use window_state::{
    get_window_state_path, load_window_geometry_from_path, save_window_geometry_to_path,
};
pub use windowing::{
    AnchorEdge, PopupDismissReason, ShowEffect, Stacking, WindowCapabilities, WindowFocusPolicy,
    WindowOptions, WindowPlacement, WindowRole, WindowShape,
};

// ---------------------------------------------------------------------------
// Test-only Mock backend
// ---------------------------------------------------------------------------
//
// Unit tests in `ui.rs`, `declarative.rs`, `bindings.rs`, and `advanced.rs` use
// the shared Mock backend. A direct dependency on `native-gui-mock` does not work for
// `#[cfg(test)]` because tests compile as a distinct crate. We therefore embed
// `native-gui-mock/src/lib.rs` under this crate's identity (via `extern crate self as native_gui_core`
// and the `test_support` module). The module is `#[cfg(test)]`-gated only.
//
// See `crates/native-gui-core/Cargo.toml` dev-dependency note and the CI step that
// runs `cargo check -p native-gui-core --all-targets`.
#[cfg(any(test, feature = "mock"))]
extern crate self as native_gui_core;

#[cfg(any(test, feature = "mock"))]
#[doc(hidden)]
// The included source is `native-gui-mock`'s, so its `#[cfg(feature = "e2e")]` gates
// are never expected in this crate's feature set; they stay disabled here.
#[allow(unexpected_cfgs)]
#[path = "../../native-gui-mock/src/lib.rs"]
pub mod test_support;