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    calculate_pan_weights, MacBox, MacButtonCell, MacCircularSlider, MacCollectionView,
84    MacCollectionViewFlowLayout, MacColorWell, MacComboBox, MacControlSize, MacDate, MacDatePicker,
85    MacDatePickerElementFlags, MacDatePickerStyle, MacDisclosureButton, MacDisclosureGroup,
86    MacInputCell, MacLevelIndicator, MacLevelIndicatorStyle, MacLevelOrientation, MacOutlineRow,
87    MacOutlineRowResponse, MacOutlineTree, MacOutlineView, MacPathComponent, MacPathControl,
88    MacPathControlResponse, MacPlayerControlsStyle, MacPlayerView, MacPopUpButton,
89    MacProgressControlSize, MacProgressIndicator, MacProgressStyle, MacRatingIndicator,
90    MacSearchField, MacSegmentedControl, MacSlider, MacSortDirection, MacStepper, MacTabItem,
91    MacTabStyle, MacTabView, MacTableColumn, MacTableView, MacTableViewOutput, MacTableViewResponse,
92    MacThumbnailCell, MacTimelineZone, MacToggle, MacTokenField, MacTrimScrubber,
93    MacTrimScrubberResponse, UNIT_STAR, MacInsets,
94};
95pub use feedback::{clamp_menu_rect, MacContextMenu, MacToast, MacToastManager, ToastLevel};
96pub use layout::{
97    is_window_active, subpixel_snap, subpixel_snap_pos, subpixel_snap_rect, MacFixedView, MacForm,
98    MacFormUi, MacFrame, MacRow, MacScrollView, MacScrollViewOutput, MacSplitOrientation,
99    MacSplitView, MacStackAlignment, MacStackOrientation, MacStackUi, MacStackView,
100    MacStackViewOutput,
101};
102pub use motion::CASpring;
103pub use navigation::{
104    CommandPaletteItem, MacCanvasFooter, MacCanvasFooterAction, MacCommandPalette,
105    MacKeyboardShortcut, MacMenuBar, MacMenuItemKind, MacToolbar, MacToolbarResponse, NSMenu,
106    NSMenuItem, CANVAS_FOOTER_HEIGHT, COMMAND_PALETTE_HEIGHT, COMMAND_PALETTE_WIDTH,
107};
108pub use state::{NSUndoManager, DEFAULT_UNDO_CAPACITY};
109pub use surfaces::{MacCard, MacFloatingInfoBox, MacPanel, MacPopover, MacPopoverArrowEdge};
110pub use tokens::{
111    sf_pro_tracking, ColorWellMetrics, LayoutMetrics, LevelIndicatorMetrics, MacColorTokens,
112    MacControlMetrics, MacDesignTokens, MacMotionTokens, MacTypographyTokens, OutlineViewMetrics,
113    PathControlMetrics, PopUpButtonMetrics, ProgressIndicatorMetrics, ProgressSizeMetrics,
114    ScrollViewMetrics, SearchFieldMetrics, SliderMetrics, SplitViewMetrics, StackViewMetrics,
115    StepperMetrics, TableViewMetrics, ThumbnailCellMetrics, ToggleMetrics, TokenFieldMetrics,
116    TrimScrubberMetrics,
117};