Skip to main content

agg_gui/
lib.rs

1//! # agg-gui
2//!
3//! A Rust GUI framework built on [AGG](https://github.com/larsbrubaker/agg-rust)
4//! (Anti-Grain Geometry).
5//!
6//! ## Architecture
7//!
8//! ```text
9//! Application / Widgets
10//!   │
11//! GfxCtx (Cairo-style stateful 2D drawing API)
12//!   │
13//! AGG (rasterization) + Clipper2 (boolean geometry)
14//!   │
15//! Framebuffer (RGBA8, bottom-up Y-up row order)
16//!   │
17//! Platform (WGL native / WebGL WASM)
18//! ```
19//!
20//! ## Coordinate system
21//!
22//! The entire framework uses **first-quadrant (Y-up)** coordinates throughout.
23//! Origin is the bottom-left corner of the window. Positive Y goes upward.
24//! This is a non-negotiable architectural invariant — see the dev plan for
25//! the rationale.
26//!
27//! ## Module guide
28//!
29//! - [`widget`] / [`widgets`] — the [`App`] event/layout/paint driver and the
30//!   widget set (buttons, text editing, windows, flex layout, menus, …).
31//! - [`draw_ctx`] — the [`DrawCtx`] drawing trait every widget paints
32//!   through; [`gfx_ctx`] is the software AGG implementation.
33//! - [`theme`] — dark / light / system visuals read via `ctx.visuals()`.
34//! - [`overlay_insets`] + [`widgets::ReserveInset`] + [`card`] — safe-area
35//!   overlay placement: reserved screen edges (the on-screen keyboard
36//!   reserves itself), and anchored info cards that measure, word-wrap,
37//!   flip, and clamp so floating content never hides under sibling chrome.
38//! - [`input_profile`] / [`ux_scale`] — touch-device detection and the
39//!   mobile UX zoom; [`widgets::on_screen_keyboard`] is the in-canvas
40//!   keyboard with keyboard-avoidance handled by [`App::layout`].
41//! - `winit_adapter` (feature `winit-adapter`) and, on WASM,
42//!   `web_adapter` (`install_keyboard_listeners` = typing + clipboard
43//!   for any browser shell) — platform glue. The repo's `demo-wgpu` crate
44//!   adds turn-key `native_shell` / `web_shell` runners on top.
45
46pub mod animation;
47pub mod app_state;
48pub mod card;
49pub mod clipboard;
50pub mod color;
51pub mod confetti;
52pub mod cursor;
53pub mod device_scale;
54pub mod draw_cell;
55pub mod draw_ctx;
56pub mod event;
57pub mod focus;
58pub mod font_settings;
59pub mod framebuffer;
60pub mod geometry;
61pub mod gfx_ctx;
62pub mod gl_renderer;
63pub mod input_profile;
64pub mod layout_props;
65pub mod lcd_coverage;
66pub mod lcd_gfx_ctx;
67pub mod overlay_insets;
68pub mod paints;
69pub mod persistence;
70pub mod pixel_bounds;
71pub mod platform;
72pub mod screenshot;
73pub mod snap;
74pub mod svg;
75pub mod text;
76pub mod theme;
77pub mod timestep;
78pub mod touch_emulation;
79pub mod touch_state;
80pub mod undo;
81pub mod ux_scale;
82#[cfg(target_arch = "wasm32")]
83pub mod wasm_clipboard;
84pub mod widget;
85pub mod widgets;
86
87/// Adapter helpers bridging `winit` types (keyboard, mouse, modifiers,
88/// cursor) to this crate's input/cursor types.  Enabled with the
89/// `winit-adapter` feature so consumers that don't use winit don't pull
90/// the dep.
91#[cfg(feature = "winit-adapter")]
92pub mod winit_adapter;
93
94/// Adapter helpers for web/JS targets — DOM KeyboardEvent key-string →
95/// [`Key`] parser and CSS cursor-name for [`CursorIcon`].  Compiled only
96/// for `wasm32` targets.
97#[cfg(target_arch = "wasm32")]
98pub mod web_adapter;
99
100// Re-export the most commonly used types at the crate root.
101pub use app_state::{OsWindowHandle, OsWindowState};
102pub use color::Color;
103pub use cursor::{current_cursor_icon, reset_cursor_icon, set_cursor_icon, CursorIcon};
104pub use device_scale::{device_scale, set_device_scale};
105pub use draw_cell::{DrawCell, DrawRefCell, DrawRefMut};
106pub use draw_ctx::{DrawCtx, FillRule, GlPaint};
107pub use event::{Event, EventResult, Key, Modifiers, MouseButton};
108pub use font_settings::current_typography_epoch;
109pub use framebuffer::Framebuffer;
110pub use geometry::{Point, Rect, Size};
111pub use gfx_ctx::GfxCtx;
112pub use layout_props::{resolve_fit_or_stretch, HAnchor, Insets, VAnchor, WidgetBase};
113pub use platform::{current_platform, platform_from_name, set_platform, Platform};
114pub use screenshot::ScreenshotHandle;
115pub use snap::{
116    compute_snap, next_snap_id, ResizeEdge as SnapResizeEdge, SnapGuide, SnapId, SnapMode,
117    SnapOverlay, SnapResult, Snappable, DEFAULT_THRESHOLD as SNAP_DEFAULT_THRESHOLD,
118};
119pub use svg::{
120    compare_svg_rgba, parse_svg, render_svg, render_svg_at_size, render_svg_at_size_with_options,
121    render_svg_at_size_with_resources, render_svg_to_framebuffer,
122    render_svg_to_framebuffer_at_size, render_svg_to_framebuffer_at_size_with_options,
123    render_svg_to_framebuffer_at_size_with_resources, render_svg_to_framebuffer_with_options,
124    render_svg_to_lcd_buffer, render_svg_to_lcd_buffer_at_size,
125    render_svg_to_lcd_buffer_at_size_with_options, render_svg_to_lcd_buffer_at_size_with_resources,
126    render_svg_to_lcd_buffer_with_options, render_svg_tree, render_svg_tree_at_size,
127    render_svg_tree_region_at_size, render_svg_tree_region_to_framebuffer_at_size,
128    render_svg_tree_to_framebuffer, render_svg_tree_to_framebuffer_at_size,
129    render_svg_tree_to_lcd_buffer, render_svg_tree_to_lcd_buffer_at_size, render_svg_with_options,
130    set_default_svg_parse_options, svg_fontdb_from_font_data, SvgCompareResult,
131    SvgCompareThresholds, SvgParseOptions, SvgRenderError, SvgTree, DEFAULT_ALPHA_TOLERANCE,
132    DEFAULT_MISMATCH_RATIO, DEFAULT_OPAQUE_RGB_TOLERANCE, DEFAULT_TRANSLUCENT_RGB_TOLERANCE,
133    DEFAULT_VISUAL_RGB_TOLERANCE,
134};
135pub use text::{measure_text_metrics, Font, TextMetrics};
136pub use theme::{
137    current_visuals, current_visuals_epoch, set_visuals, AccentColor, ThemePreference, Visuals,
138};
139pub use timestep::{FixedTimestep, StepBatch, FIXED_DT, MAX_STEPS_PER_DRAW, SIMULATION_HZ};
140pub use touch_emulation::{EmuCmd, TouchMouseEmu, TOUCH_SCROLL_THRESHOLD};
141pub use touch_state::{current_multi_touch, MultiTouchInfo, TouchDeviceId, TouchId, TouchPhase};
142pub use undo::{DoUndoActions, Settings as UndoerSettings, UndoBuffer, Undoer, UndoRedoCommand};
143#[cfg(feature = "reflect")]
144pub use widget::{apply_inspector_edit, reflect_fields, InspectorEdit};
145pub use widget::{
146    apply_widget_base_edit, collect_inspector_nodes, current_mouse_world, current_viewport,
147    debug_draw_report, find_widget_by_id, find_widget_by_id_mut, find_widget_by_type, App,
148    BackbufferKind,
149    BackbufferSpec, BackbufferState, InspectorNode, InspectorOverlay, Widget, WidgetBaseEdit,
150    WidgetBaseField,
151};
152pub use widgets::{
153    color_wheel_picker_dialog, color_wheel_picker_dialog_with_on_close, current_scroll_style,
154    current_scroll_visibility, paint_sparkline,
155    set_scroll_style, set_scroll_visibility, shared_frame_history, shared_run_mode, Button,
156    CellInfo, Checkbox, ClickAwayAction, CloseReason, CollapsingHeader, ColorPicker,
157    ColorWheelPicker, ComboBox, Conditional,
158    Align, Align2, Container, DragValue, FlexColumn, FlexRow, FrameHistory, HandleShape,
159    DEFAULT_COLUMN_GAP, DEFAULT_ROW_GAP,
160    HeaderInfo, Hyperlink, ImageView, InspectorPanel, InspectorSavedState, Label, LabelAlign,
161    MarkdownView, MenuBar, MenuBarStrip, MenuEntry, MenuItem, MenuResponse, MenuSelection,
162    MenuShortcut, ModalSheet, NodeIcon, Padding, PerformanceView, Popup, PopupClickOutcome,
163    PopupCloseBehavior, PopupMenu, ProgressBar, QrView, RadioGroup, Rebuilder, RectAlign,
164    Resize, RichCommand, RichDoc, RichEditHandle, RichTextEdit, RichTextToolbar, RichTextView,
165    RunMode, RunModeDesc,
166    RunModeRow, Scene, SharedResolver, single_font_resolver,
167    SceneTransform, ScrollBarColor, ScrollBarKind,
168    ScrollBarStyle, ScrollBarVisibility, ScrollView, Separator, SharedFrameHistory, ShortcutKey,
169    SizedBox, Slider, SliderClamping, SliderOrientation, Spacer, Splitter, Stack, TabView, Table,
170    TableBuilder, TableColumn, TableRows, TextArea, TextEditState, TextField, TextHAlign,
171    TextVAlign, ToggleSwitch, Tooltip, TooltipTimings, TopMenu, TreeView, Window,
172    set_tooltip_timings, tooltip_timings,
173};
174
175// Re-export AGG types so callers don't need to import agg-rust directly.
176pub use agg_rust::comp_op::CompOp;
177pub use agg_rust::math_stroke::{LineCap, LineJoin};
178pub use agg_rust::trans_affine::TransAffine;
179
180#[cfg(test)]
181mod tests;