Skip to main content

egui_macview/
lib.rs

1#![doc = include_str!("../README.md")]
2//!
3//! Grounded in Apple AppKit, macOS Human Interface Guidelines (HIG), and W3C DTCG Design Tokens.
4//!
5//! # Architecture & Highlights
6//!
7//! - **Authentic Control Primitives**: Complete macOS AppKit controls including [`MacToggle`], [`MacSlider`],
8//!   [`MacSegmentedControl`], [`MacPopUpButton`], [`MacSearchField`], [`MacStepper`], [`MacColorWell`],
9//!   [`MacOutlineView`], [`MacButtonCell`], [`MacInputCell`], and [`MacThumbnailCell`].
10//! - **Deterministic Layout Engines**: Subpixel-snapped linear [`MacStackView`] (`NSStackView`), draggable hairline [`MacSplitView`] (`NSSplitView`),
11//!   zero-gutter floating overlay [`MacScrollView`] (`NSScrollView`), absolute [`MacFixedView`], and autolayout [`MacRow`].
12//! - **CoreAnimation Physics**: Analytical spring physics runtime [`CASpring`] matching Apple's `CASpringAnimation`
13//!   and SwiftUI `.spring(response:dampingRatio:)` with analytical displacement and velocity calculations.
14//! - **W3C DTCG Token Catalog & Theming**: Dynamic theming via [`MacTheme`] and [`MacAppearance`] supporting Aqua and DarkAqua
15//!   appearances, configurable window control decorations via [`WindowControlsStyle`], and dynamic system accent colors.
16//! - **Subpixel Snapping**: Physical pixel boundary rounding via [`subpixel_snap`], [`subpixel_snap_pos`], and [`subpixel_snap_rect`].
17//!
18//! # Quick Start Example
19//!
20//! ```rust
21//! use egui_macview::{
22//!     CASpring, MacAppearance, MacSlider, MacStackView, MacTheme, MacToggle,
23//! };
24//!
25//! # let ctx = egui::Context::default();
26//! # let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
27//! // 1. Initialize macOS dynamic theme (Aqua or DarkAqua)
28//! let theme = MacTheme::new(MacAppearance::DarkAqua);
29//!
30//! // 2. Assemble controls inside an NSStackView linear layout
31//! let mut enabled = true;
32//! let mut volume = 75.0f32;
33//!
34//! MacStackView::vertical()
35//!     .theme(&theme)
36//!     .show_separators(true)
37//!     .show(ui, |stack| {
38//!         stack.add(|ui| {
39//!             ui.add(MacToggle::new(&mut enabled).theme(&theme));
40//!         });
41//!         stack.add(|ui| {
42//!             MacSlider::new(&mut volume, 0.0..=100.0)
43//!                 .theme(&theme)
44//!                 .ticks(5, true)
45//!                 .show(ui);
46//!         });
47//!     });
48//!
49//! // 3. Analytical spring physics evaluation
50//! let spring = CASpring::new(0.35, 0.85);
51//! let displacement = spring.evaluate(0.15); // t = 150ms
52//! # assert!(displacement > 0.0);
53//! # });
54//! # output.textures_delta.clear();
55//! ```
56
57#![deny(missing_docs)]
58
59/// Crate release version string extracted from `Cargo.toml`.
60pub const VERSION: &str = env!("CARGO_PKG_VERSION");
61
62pub mod controls;
63pub mod feedback;
64pub mod layout;
65pub mod motion;
66pub mod navigation;
67pub mod state;
68pub mod surfaces;
69pub mod symbols;
70pub mod theme;
71pub mod tokens;
72
73pub use symbols::{
74    setup_symbols_font, MacSymbol, CUPERTINO_ICONS_FONT_BYTES, CUPERTINO_ICONS_FONT_NAME,
75};
76
77pub use theme::{
78    contrast_ratio, relative_luminance, MacAppearance, MacBackgroundStyle, MacTheme,
79    WindowControlsStyle,
80};
81
82pub use controls::{
83    MacButtonCell, MacColorWell, MacControlSize, MacInputCell, MacLevelIndicator,
84    MacLevelIndicatorStyle, MacLevelOrientation, MacOutlineRow, MacOutlineRowResponse,
85    MacOutlineTree, MacOutlineView, MacPathComponent, MacPathControl, MacPathControlResponse,
86    MacPopUpButton, MacProgressControlSize, MacProgressIndicator, MacProgressStyle, MacSearchField,
87    MacSegmentedControl, MacSlider, MacSortDirection, MacStepper, MacTableColumn, MacTableView,
88    MacTableViewResponse, MacThumbnailCell, MacTimelineZone, MacToggle, MacTokenField,
89    MacTrimScrubber, MacTrimScrubberResponse,
90};
91pub use feedback::{clamp_menu_rect, MacContextMenu, MacToast, MacToastManager, ToastLevel};
92pub use layout::{
93    subpixel_snap, subpixel_snap_pos, subpixel_snap_rect, MacFixedView, MacForm, MacFormUi,
94    MacFrame, MacRow, MacScrollView, MacScrollViewOutput, MacSplitOrientation, MacSplitView,
95    MacStackAlignment, MacStackOrientation, MacStackUi, MacStackView, MacStackViewOutput,
96};
97pub use motion::CASpring;
98pub use navigation::{
99    CommandPaletteItem, MacCanvasFooter, MacCanvasFooterAction, MacCommandPalette,
100    MacKeyboardShortcut, MacMenuBar, MacMenuItemKind, MacToolbar, MacToolbarResponse, NSMenu,
101    NSMenuItem, CANVAS_FOOTER_HEIGHT, COMMAND_PALETTE_HEIGHT, COMMAND_PALETTE_WIDTH,
102};
103pub use state::{NSUndoManager, DEFAULT_UNDO_CAPACITY};
104pub use surfaces::{MacCard, MacFloatingInfoBox, MacPanel, MacPopover, MacPopoverArrowEdge};
105pub use tokens::{
106    sf_pro_tracking, ColorWellMetrics, LayoutMetrics, LevelIndicatorMetrics, MacColorTokens,
107    MacControlMetrics, MacDesignTokens, MacMotionTokens, MacTypographyTokens, OutlineViewMetrics,
108    PathControlMetrics, PopUpButtonMetrics, ProgressIndicatorMetrics, ProgressSizeMetrics,
109    ScrollViewMetrics, SearchFieldMetrics, SliderMetrics, SplitViewMetrics, StackViewMetrics,
110    StepperMetrics, TableViewMetrics, ThumbnailCellMetrics, ToggleMetrics, TokenFieldMetrics,
111    TrimScrubberMetrics,
112};