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
27pub mod animation;
28pub mod app_state;
29pub mod card;
30pub mod clipboard;
31pub mod color;
32pub mod cursor;
33pub mod device_scale;
34pub mod draw_ctx;
35pub mod event;
36pub mod focus;
37pub mod font_settings;
38pub mod framebuffer;
39pub mod geometry;
40pub mod gfx_ctx;
41pub mod gl_renderer;
42pub mod input_profile;
43pub mod layout_props;
44pub mod lcd_coverage;
45pub mod lcd_gfx_ctx;
46pub mod overlay_insets;
47pub mod paints;
48pub mod persistence;
49pub mod pixel_bounds;
50pub mod platform;
51pub mod screenshot;
52pub mod snap;
53pub mod svg;
54pub mod text;
55pub mod theme;
56pub mod timestep;
57pub mod touch_state;
58pub mod undo;
59pub mod ux_scale;
60#[cfg(target_arch = "wasm32")]
61pub mod wasm_clipboard;
62pub mod widget;
63pub mod widgets;
64
65/// Adapter helpers bridging `winit` types (keyboard, mouse, modifiers,
66/// cursor) to this crate's input/cursor types.  Enabled with the
67/// `winit-adapter` feature so consumers that don't use winit don't pull
68/// the dep.
69#[cfg(feature = "winit-adapter")]
70pub mod winit_adapter;
71
72/// Adapter helpers for web/JS targets — DOM KeyboardEvent key-string →
73/// [`Key`] parser and CSS cursor-name for [`CursorIcon`].  Compiled only
74/// for `wasm32` targets.
75#[cfg(target_arch = "wasm32")]
76pub mod web_adapter;
77
78// Re-export the most commonly used types at the crate root.
79pub use app_state::{OsWindowHandle, OsWindowState};
80pub use color::Color;
81pub use cursor::{current_cursor_icon, reset_cursor_icon, set_cursor_icon, CursorIcon};
82pub use device_scale::{device_scale, set_device_scale};
83pub use draw_ctx::{DrawCtx, FillRule, GlPaint};
84pub use event::{Event, EventResult, Key, Modifiers, MouseButton};
85pub use font_settings::current_typography_epoch;
86pub use framebuffer::Framebuffer;
87pub use geometry::{Point, Rect, Size};
88pub use gfx_ctx::GfxCtx;
89pub use layout_props::{resolve_fit_or_stretch, HAnchor, Insets, VAnchor, WidgetBase};
90pub use platform::{current_platform, platform_from_name, set_platform, Platform};
91pub use screenshot::ScreenshotHandle;
92pub use snap::{
93    compute_snap, next_snap_id, ResizeEdge as SnapResizeEdge, SnapGuide, SnapId, SnapMode,
94    SnapOverlay, SnapResult, Snappable, DEFAULT_THRESHOLD as SNAP_DEFAULT_THRESHOLD,
95};
96pub use svg::{
97    compare_svg_rgba, parse_svg, render_svg, render_svg_at_size, render_svg_at_size_with_options,
98    render_svg_at_size_with_resources, render_svg_to_framebuffer,
99    render_svg_to_framebuffer_at_size, render_svg_to_framebuffer_at_size_with_options,
100    render_svg_to_framebuffer_at_size_with_resources, render_svg_to_framebuffer_with_options,
101    render_svg_to_lcd_buffer, render_svg_to_lcd_buffer_at_size,
102    render_svg_to_lcd_buffer_at_size_with_options, render_svg_to_lcd_buffer_at_size_with_resources,
103    render_svg_to_lcd_buffer_with_options, render_svg_tree, render_svg_tree_at_size,
104    render_svg_tree_region_at_size, render_svg_tree_region_to_framebuffer_at_size,
105    render_svg_tree_to_framebuffer, render_svg_tree_to_framebuffer_at_size,
106    render_svg_tree_to_lcd_buffer, render_svg_tree_to_lcd_buffer_at_size, render_svg_with_options,
107    set_default_svg_parse_options, svg_fontdb_from_font_data, SvgCompareResult,
108    SvgCompareThresholds, SvgParseOptions, SvgRenderError, SvgTree, DEFAULT_ALPHA_TOLERANCE,
109    DEFAULT_MISMATCH_RATIO, DEFAULT_OPAQUE_RGB_TOLERANCE, DEFAULT_TRANSLUCENT_RGB_TOLERANCE,
110    DEFAULT_VISUAL_RGB_TOLERANCE,
111};
112pub use text::{measure_text_metrics, Font, TextMetrics};
113pub use theme::{
114    current_visuals, current_visuals_epoch, set_visuals, AccentColor, ThemePreference, Visuals,
115};
116pub use timestep::{FixedTimestep, StepBatch, FIXED_DT, MAX_STEPS_PER_DRAW, SIMULATION_HZ};
117pub use touch_state::{current_multi_touch, MultiTouchInfo, TouchDeviceId, TouchId, TouchPhase};
118pub use undo::{DoUndoActions, UndoBuffer, UndoRedoCommand};
119#[cfg(feature = "reflect")]
120pub use widget::{apply_inspector_edit, reflect_fields, InspectorEdit};
121pub use widget::{
122    apply_widget_base_edit, collect_inspector_nodes, current_mouse_world, current_viewport,
123    find_widget_by_id, find_widget_by_id_mut, find_widget_by_type, App, BackbufferKind,
124    BackbufferSpec, BackbufferState, InspectorNode, InspectorOverlay, Widget, WidgetBaseEdit,
125    WidgetBaseField,
126};
127pub use widgets::{
128    color_wheel_picker_dialog, current_scroll_style, current_scroll_visibility, paint_sparkline,
129    set_scroll_style, set_scroll_visibility, shared_frame_history, shared_run_mode, Button,
130    CellInfo, Checkbox, CollapsingHeader, ColorPicker, ColorWheelPicker, ComboBox, Conditional,
131    Container, DragValue, FlexColumn, FlexRow, FrameHistory, HeaderInfo, Hyperlink, ImageView,
132    InspectorPanel, InspectorSavedState, Label, LabelAlign, MarkdownView, MenuBar, MenuBarStrip,
133    MenuEntry, MenuItem, MenuResponse, MenuSelection, MenuShortcut, NodeIcon, Padding,
134    PerformanceView, PopupMenu, ProgressBar, QrView, RadioGroup, Resize, RunMode, RunModeDesc,
135    RunModeRow,
136    ScrollBarColor, ScrollBarKind, ScrollBarStyle, ScrollBarVisibility, ScrollView, Separator,
137    SharedFrameHistory, ShortcutKey, SizedBox, Slider, Spacer, Splitter, Stack, TabView, Table,
138    TableBuilder, TableColumn, TableRows, TextArea, TextField, ToggleSwitch, Tooltip, TopMenu,
139    TreeView, Window,
140};
141
142// Re-export AGG types so callers don't need to import agg-rust directly.
143pub use agg_rust::comp_op::CompOp;
144pub use agg_rust::math_stroke::{LineCap, LineJoin};
145pub use agg_rust::trans_affine::TransAffine;
146
147#[cfg(test)]
148mod tests;