Skip to main content

Crate native_gui_core

Crate native_gui_core 

Source
Expand description

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)

use native_gui_mock::MockBackend;
use native_gui_core::{ContainerDirection, Ui, WidgetKind};

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)?;

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.

Re-exports§

pub use access::AccessibilitySpec;
pub use access::AccessibilityState;
pub use access::AccessibleAction;
pub use access::AccessibleRole;
pub use advanced::AdvancedFamily;
pub use advanced::AdvancedHostCapabilities;
pub use advanced::DecisionCounters;
pub use advanced::DecisionOutcome;
pub use advanced::DecisionToken;
pub use advanced::EngineInfo;
pub use advanced::OperationId;
pub use artprov::ArtCapabilities;
pub use artprov::IconRole;
pub use artprov::IconSize;
pub use artprov::IconSource;
pub use artprov::StockIcon;
pub use async_ui::TaskClass;
pub use async_ui::TaskCommand;
pub use async_ui::TaskDrainReport;
pub use async_ui::TaskEvent;
pub use async_ui::TaskHandle;
pub use async_ui::TaskId;
pub use async_ui::TaskSendError;
pub use async_ui::TaskToken;
pub use async_ui::UiProxy;
pub use async_ui::DEFAULT_TASK_QUEUE_CAPACITY;
pub use autoclose::Autoclose;
pub use bindings::Bindings;
pub use canvas::CanvasBufferCost;
pub use canvas::CanvasDamage;
pub use canvas::CanvasDamageAccumulator;
pub use canvas::CanvasStrokeCoalescingPolicy;
pub use demo_cube::project_demo_cube;
pub use demo_cube::DemoCubeFace;
pub use demo_cube::DEMO_CUBE_BOTTOM;
pub use demo_cube::DEMO_CUBE_TOP;
pub use displays::logical_pointer_projection;
pub use displays::DisplayCapabilities;
pub use displays::DisplayInfo;
pub use displays::DisplayRect;
pub use drag::DragCapabilities;
pub use drag::DragPayload;
pub use drag::DragPayloadKind;
pub use drag::DragSessionId;
pub use drag::DragSourceOptions;
pub use drag::DragTargetOptions;
pub use drag::DropCancelReason;
pub use drag::DropEffect;
pub use drag::MAX_DRAG_PAYLOAD_BYTES;
pub use error::GuiError;
pub use error::GuiResult;
pub use events::AccessibleNotification;
pub use events::UiEvent;
pub use file_dialog::FileDialog;
pub use file_dialog::FileFilter;
pub use focus::default_focusable;
pub use focus::is_focusable;
pub use image_resource::ImageData;
pub use image_resource::ImageResourceCapabilities;
pub use image_resource::ImageResourceId;
pub use image_resource::MAX_IMAGE_RESOURCE_BYTES;
pub use image_resource::MAX_IMAGE_RESOURCE_BYTES_PER_UI;
pub use menus::MenuId;
pub use menus::MenuItemId;
pub use motion::MotionCapabilities;
pub use motion::MotionId;
pub use motion::MotionSpec;
pub use motion::MOTION_TICK_CADENCE;
pub use pickers::ColorDialogData;
pub use pickers::FontDescriptor;
pub use pickers::FontDialogData;
pub use pickers::FontEffects;
pub use pickers::FontWeight;
pub use pickers::PickerError;
pub use pickers::PickerResult;
pub use pickers::Rgba;
pub use pickers::MAX_CUSTOM_COLORS;
pub use properties::ChangeToken;
pub use properties::DenialReason;
pub use properties::PendingChange;
pub use properties::ProjectionMode;
pub use properties::PropertyEditor;
pub use properties::PropertyError;
pub use properties::PropertyEvent;
pub use properties::PropertyId;
pub use properties::PropertyModel;
pub use properties::PropertyNode;
pub use properties::PropertyNodeKind;
pub use properties::PropertyResult;
pub use properties::PropertyRow;
pub use properties::PropertyValue;
pub use routes::Routes;
pub use theme::HighContrastPreset;
pub use theme::Theme;
pub use theme::ThemeCapabilities;
pub use theme::ThemeColors;
pub use theme::ThemeMode;
pub use theme::ThemeOverride;
pub use theme::ThemeSpacing;
pub use theme::ThemeTypography;
pub use timer::TimerCapabilities;
pub use timer::TimerFire;
pub use timer::TimerId;
pub use timer::TimerSpec;
pub use timer::TimerStopPolicy;
pub use toolbar::ToolDisplay;
pub use toolbar::ToolId;
pub use toolbar::ToolInteraction;
pub use toolbar::ToolSpec;
pub use toolbar::ToolUpdate;
pub use toolbar::ToolbarError;
pub use toolbar::ToolbarItem;
pub use toolbar::ToolbarOrientation;
pub use tray::TrayEvent;
pub use tray::TrayIconId;
pub use tray::TrayIconSpec;
pub use ui::Backend;
pub use ui::Capability;
pub use ui::InputMode;
pub use ui::LoopFlow;
pub use ui::MetalCanvasHandle;
pub use ui::Operation;
pub use ui::RunStop;
pub use ui::Ui;
pub use ui::VulkanCanvasHandle;
pub use widgets::abstractable_widget_types;
pub use widgets::apply_row_ops_to_cells;
pub use widgets::apply_row_ops_to_items;
pub use widgets::apply_row_ops_to_rows;
pub use widgets::diff_row_ops;
pub use widgets::AlertLevel;
pub use widgets::CalendarDate;
pub use widgets::CalendarFirstDayOfWeek;
pub use widgets::CalendarSelectionMode;
pub use widgets::CanvasPrimitive;
pub use widgets::CanvasRect;
pub use widgets::CanvasScene;
pub use widgets::CanvasSurface;
pub use widgets::Color;
pub use widgets::ColumnSpec;
pub use widgets::ContainerDirection;
pub use widgets::ContainerWrap;
pub use widgets::FileChooserMode;
pub use widgets::GpuDegradationPolicy;
pub use widgets::GpuSurfaceCapabilities;
pub use widgets::ImageFit;
pub use widgets::LabelAlignment;
pub use widgets::LabelWrap;
pub use widgets::LabelWrapMode;
pub use widgets::RichTextImage;
pub use widgets::RowDelta;
pub use widgets::RowKey;
pub use widgets::RowOp;
pub use widgets::RowSet;
pub use widgets::TextRun;
pub use widgets::TextStyle;
pub use widgets::TreeItem;
pub use widgets::WidgetId;
pub use widgets::WidgetKind;
pub use widgets::WidgetProperty;
pub use widgets::WidgetSpec;
pub use window_state::clamp_to_displays;
pub use window_state::RectGeometry;
pub use window_state::WindowGeometry;
pub use window_state::WindowShowState;
pub use windowing::AnchorEdge;
pub use windowing::PopupDismissReason;
pub use windowing::ShowEffect;
pub use windowing::Stacking;
pub use windowing::WindowCapabilities;
pub use windowing::WindowFocusPolicy;
pub use windowing::WindowOptions;
pub use windowing::WindowPlacement;
pub use windowing::WindowRole;
pub use windowing::WindowShape;

Modules§

access
Desktop accessibility semantics.
advanced
Advanced-control substrate.
artprov
Stock art/icon provider.
async_ui
Sendable UI-thread command proxy for background work.
autoclose
Bounded-run budgets for unattended capture and smoke harnesses.
bindings
Retained, change-only widget property writers.
canvas
Canvas damage, repaint scheduling, and surface update efficiency helpers.
declarative
demo_cube
Software fallback cube shared by the Win32, GTK, and Web draw_demo_cube painters.
displays
Portable display and monitor metrics.
drag
error
events
file_dialog
Function-style native file dialogs (found while dogfooding).
focus
Focus and tab-order model.
i18n
Shared localization model (unblocks the internat example).
image_resource
layout
Native GUI owned layout types, geometry, and style specification.
menus
motion
pickers
Native productivity picker-dialog foundation.
properties
PropertyGrid typed property model — capability groups P1, P2, P4, and P5.
routes
Typed event routing for application message handling.
state
theme
Theme tokens and light/dark modes.
timer
toolbar
Portable toolbar model.
tray
Portable system tray service model.
ui
widgets
window_handle
Native top-level window handles and optional raw-window-handle interop.
window_state
Window state and geometry persistence.
windowing

Macros§

menu
Builds, populates, and attaches a window menu bar from a terse block.
ui
Builds and attaches widgets imperatively from a terse declarative block.