Skip to main content

frus_widgets/
lib.rs

1//! `frus-widgets` — frus's declarative widget tree.
2//!
3//! An interface is described with composable widgets ([`Container`], [`Flex`],
4//! [`Text`], [`TextField`], [`SingleChildScrollView`]) generic over a message type `Msg`, in the
5//! Elm/iced message model. [`build_ui`] translates them into a layout, through
6//! `frus-layout`, and then into a [`Ui`]: the [`Scene`] to draw, plus the hit-test maps
7//! for clicking, focus and scrolling.
8//!
9//! The state retained between frames — hover and focus, scroll offsets, caret and
10//! selection — lives in a [`Runtime`], keyed by widget identity.
11
12#![deny(missing_docs)]
13
14// The README's example is compiled and run by `cargo test --doc`, so it cannot rot.
15#[cfg(doctest)]
16#[doc = include_str!("../README.md")]
17pub struct ReadmeDoctests;
18
19mod actionbutton;
20mod alert;
21mod animated;
22mod appbar;
23mod aspectratio;
24mod autocomplete;
25mod autofill;
26mod avatar;
27mod badge;
28mod banner;
29mod barrier;
30mod baseline;
31mod bottomappbar;
32mod bottomsheet;
33mod breadcrumb;
34mod button;
35mod callback;
36mod card;
37mod carousel;
38mod chart;
39mod checkbox;
40mod chip;
41mod clip;
42mod collapsible;
43mod collapsingheader;
44mod colorpicker;
45mod component;
46mod constraints;
47mod container;
48mod controltile;
49mod custompaint;
50mod datatable;
51mod datepicker;
52mod datetimepicker;
53mod datetimerange;
54mod dialog;
55/// The **disabled state** every control shares: two colours and a four-part contract.
56pub mod disabled;
57/// Swipe-to-dismiss: the [`dismiss::Dismissible`] widget and its retained state.
58pub mod dismiss;
59mod divider;
60mod dragdrop;
61mod drawer;
62mod drawerheader;
63mod dropdown;
64mod dropdownmenu;
65mod dsl;
66mod editing;
67mod expanded;
68mod expansionpanel;
69mod fab;
70mod filters;
71mod fittedbox;
72mod flex;
73mod focus;
74/// Form validation, pure and application-side: [`form::Rule`] and [`form::Form`].
75pub mod form;
76mod switcher;
77mod system_ui;
78pub use form::ErrorSummary;
79mod fractional;
80mod grid;
81mod gridtile;
82mod hero;
83// Documented inside (`host.rs`): an outer doc comment here would make its links resolve from
84// this scope rather than from the module's.
85pub mod host;
86mod icon;
87mod iconbutton;
88mod icons;
89mod image;
90/// The software keyboard's vocabulary: which keys, and what the action key does.
91pub mod ime;
92mod ink;
93mod inspector;
94mod interaction;
95mod interactive;
96mod kanban;
97mod kbd;
98mod keyed;
99mod layoutbuilder;
100pub mod licenses;
101mod list;
102mod listtile;
103/// Which language the interface is in: [`locale::Locale`], [`locale::resolve`] and
104/// [`locale::of`].
105pub mod locale;
106/// The words the framework itself says: [`localizations::Localizations`] and [`localizations::of`].
107pub mod localizations;
108mod media;
109mod mediascope;
110mod menu;
111mod navbar;
112mod navdrawer;
113mod navigator;
114mod navrail;
115mod navscaffold;
116mod notifier;
117mod overflowbar;
118mod overscroll;
119mod pageselector;
120mod pageview;
121mod pagination;
122mod paintcache;
123mod physics;
124mod placeholder;
125mod popover;
126mod portal;
127mod positioned;
128mod progressbar;
129mod radio;
130mod rating;
131/// Pull-to-refresh: the [`refresh::RefreshIndicator`] widget and its retained pull.
132pub mod refresh;
133mod relayout;
134mod reorder;
135mod reorderable;
136mod responsive;
137mod richtext;
138mod rotatedbox;
139mod router;
140mod rowcolumn;
141mod runtime;
142mod safearea;
143mod scaffold;
144mod scaffoldinfo;
145mod scroll;
146pub mod scrolloverlay;
147pub mod scrollposition;
148mod searchbar;
149mod searchview;
150mod segmented;
151/// Stating what a widget **is** from outside it: the [`semantics::Semantics`] wrapper.
152pub mod semantics;
153mod sheet;
154mod shortcuts;
155mod skeleton;
156mod slider;
157mod spacer;
158mod spinner;
159mod stack;
160mod stepper;
161mod steps;
162mod switch;
163mod table;
164mod tabs;
165mod text;
166mod textinput;
167mod theme;
168mod themebuilder;
169mod themed;
170mod timeline;
171mod timepicker;
172mod toast;
173mod toasthost;
174mod togglebuttons;
175mod tooltip;
176mod transform;
177mod transitions;
178pub(crate) mod transparent;
179mod tree;
180mod twopane;
181mod ui;
182mod undo;
183mod wheel;
184mod widget;
185mod widgetstate;
186mod widgettheme;
187
188pub use actionbutton::{BackButton, CloseButton, DrawerButton, EndDrawerButton};
189pub use alert::{Alert, AlertKind};
190pub use animated::{
191    AnimatedAlign, AnimatedContainer, AnimatedDefaultTextStyle, AnimatedFractionallySizedBox,
192    AnimatedOpacity, AnimatedPadding, AnimatedPositioned, AnimatedRotation, AnimatedScale,
193    AnimatedSlide, Opacity,
194};
195pub use appbar::{platform_centers_title, AppBar, APP_BAR_HEIGHT, APP_BAR_MAX_TITLE_SCALE};
196pub use aspectratio::AspectRatio;
197pub use autocomplete::Autocomplete;
198pub use autofill::{AutofillGroup, AutofillHint};
199pub use avatar::CircleAvatar;
200pub use badge::Badge;
201pub use banner::{MaterialBanner, BANNER_ELEVATION, BANNER_MIN_ACTION_BAR_HEIGHT};
202pub use barrier::{
203    AbsorbPointer, ExcludeSemantics, IgnorePointer, ModalBarrier, Offstage, Visibility,
204};
205pub use baseline::{Baseline, IgnoreBaseline};
206pub use bottomappbar::{bar_spacer, notched_outline, BottomAppBar};
207pub use bottomsheet::BottomSheet;
208pub use breadcrumb::Breadcrumb;
209pub use button::{
210    Button, Variant, BUTTON_BORDER_WIDTH, BUTTON_ELEVATION, BUTTON_HEIGHT, BUTTON_MIN_WIDTH,
211    BUTTON_PADDING, BUTTON_TEXT_PADDING,
212};
213pub use callback::{Callback, IntoMsg};
214pub use card::{Card, CardVariant, CARD_ELEVATION, CARD_MARGIN};
215pub use carousel::CarouselView;
216pub use chart::{BarChart, LineChart};
217pub use checkbox::Checkbox;
218pub use chip::{
219    Chip, CHIP_BORDER_WIDTH, CHIP_HEIGHT, CHIP_ICON_SIZE, CHIP_LABEL_PADDING, CHIP_PADDING,
220    CHIP_RADIUS,
221};
222pub use clip::{ClipOval, ClipPath, ClipRRect};
223pub use collapsible::{ControlAffinity, ExpansionTile};
224pub use collapsingheader::{header_rect, CollapsingHeader, HeaderState, COLLAPSED_HEIGHT};
225pub use colorpicker::ColorPicker;
226pub use component::{
227    back_blocked, component, intervals, rebuild_requested, request_rebuild, take_rebuild_request,
228    BuildContext, Component, Interval, IntoCleanup, State, StateContext, StateHandle, StateStore,
229    StatefulWidget, StatelessWidget, UseRef, UseState,
230};
231pub use constraints::{
232    AxisConstraint, ConstrainedBox, ConstraintsTransform, ConstraintsTransformBox, Intrinsic,
233    IntrinsicAxis, IntrinsicHeight, IntrinsicWidth, Overflow, OverflowBox, SizedBox,
234    SizedOverflowBox, UnconstrainedBox,
235};
236pub use container::Container;
237pub use controltile::{CheckboxListTile, RadioListTile, SwitchListTile};
238pub use custompaint::CustomPaint;
239pub use datatable::{
240    compare_cells, page_count, page_range_label, page_rows, row_matches, sort_rows, DataTable,
241};
242pub use datepicker::DatePicker;
243pub use datetimepicker::DateTimePicker;
244pub use datetimerange::DateTimeRange;
245pub use dialog::{
246    ActionsAlignment, AlertDialog, Dialog, SimpleDialog, SimpleDialogOption, DIALOG_ELEVATION,
247    DIALOG_INSET_PADDING, DIALOG_MIN_WIDTH, DIALOG_RADIUS,
248};
249pub use disabled::{
250    disabled_container, disabled_content, disabled_mark, over_surface, DISABLED_CONTAINER_OPACITY,
251    DISABLED_CONTENT_OPACITY,
252};
253pub use dismiss::{
254    DismissAxis, DismissDirection, DismissPhase, DismissSpec, DismissState, Dismissable,
255    Dismissible,
256};
257pub use divider::{Divider, VerticalDivider, DIVIDER_SPACE, DIVIDER_THICKNESS};
258pub use dragdrop::{DragSource, DragTarget, Draggable, DropZone};
259pub use drawer::{Drawer, DRAWER_RADIUS, DRAWER_WIDTH};
260pub use drawerheader::{DrawerHeader, UserAccountsDrawerHeader, DRAWER_HEADER_HEIGHT};
261pub use dropdown::{DropdownButton, DropdownOption};
262pub use dropdownmenu::DropdownMenu;
263pub use dsl::{button, expanded, flexible, keyed, spacer, text};
264pub use editing::TextEditingController;
265pub use expanded::{Expanded, FlexFit, Flexible};
266pub use expansionpanel::{ExpansionPanel, ExpansionPanelList};
267pub use fab::{FabSize, FloatingActionButton};
268pub use filters::{BackdropFilter, BackdropGroup, ColorFiltered, ImageFiltered, ShaderMask};
269pub use fittedbox::FittedBox;
270pub use flex::{Flex, ListBody, Wrap};
271pub use focus::{
272    ExcludeFocus, ExcludeFocusTraversal, Focus, FocusTraversalGroup, FocusTraversalOrder,
273};
274pub use fractional::FractionallySizedBox;
275pub use grid::GridView;
276pub use gridtile::{GridTile, GridTileBar, GRID_TILE_BAR_HEIGHT, GRID_TILE_BAR_TWO_LINE_HEIGHT};
277pub use hero::{lerp_rect, Hero, HeroSpot};
278pub use icon::Icon;
279pub use iconbutton::{
280    IconButton, IconButtonVariant, ICON_BUTTON_BORDER_WIDTH, ICON_BUTTON_ICON_SIZE,
281    ICON_BUTTON_SIZE,
282};
283pub use icons::{AnimatedIconData, AnimatedIcons, IconData, IconStyle, Icons};
284pub use image::{Image, ImageIcon, ImagePlaceholder, State as ImageState, IMAGE_FADE};
285pub use ime::{Capitalization, Ime, KeyboardType, TextInputAction};
286pub use ink::{InkStyle, InkWell, Ripples};
287pub use inspector::{dump_tree, node_at, paint_overlay as paint_inspector_overlay, InspectorNode};
288pub use interaction::{Cursor, InputState, Interaction, Key, KeyResponse, Status, WidgetId};
289pub use interactive::{InteractiveView, InteractiveViewer};
290pub use kanban::{kanban_slot, Kanban};
291pub use kbd::Kbd;
292pub use keyed::Keyed;
293pub use layoutbuilder::LayoutBuilder;
294pub use licenses::{AboutDialog, AboutListTile, LicenseNotice, LicensePage, Package};
295pub use list::{ListView, VirtualList};
296pub use listtile::{
297    ListTile, LIST_TILE_DENSE_HEIGHTS, LIST_TILE_HEIGHTS, LIST_TILE_MIN_LEADING_WIDTH,
298    LIST_TILE_MIN_VERTICAL_PADDING, LIST_TILE_PADDING_END, LIST_TILE_PADDING_START,
299    LIST_TILE_TITLE_GAP,
300};
301pub use locale::Locale;
302pub use localizations::{English, French, Localizations};
303pub use media::{
304    Accessibility, AccessibilityOverrides, Brightness, Edges, MediaQuery, SurfaceGuard,
305};
306pub use mediascope::MediaScope;
307pub use menu::{MenuItem, PopupMenuButton};
308pub use navbar::NavigationBar;
309pub use navdrawer::NavigationDrawer;
310pub use navigator::Navigator;
311pub use navrail::{BottomBar, DestinationIcon, NavigationDestination, NavigationRail, RailLabels};
312pub use navscaffold::NavScaffold;
313pub use notifier::{ChangeNotifier, Listenable, Subscription, ValueNotifier};
314pub use overflowbar::OverflowBar;
315pub use overscroll::{
316    cross_axis as glow_cross_axis, edge_for, GlowEdge, OverscrollGlow, ScrollGlows,
317};
318pub use pageselector::{TabPageSelector, PAGE_DOT_GAP, PAGE_DOT_SIZE};
319pub use pageview::{PageSnap, PageView, PagedView};
320pub use pagination::Pagination;
321pub use paintcache::PaintCache;
322pub use physics::{
323    page_of, page_target, snap_target, Ballistic, ScrollDecelerationRate, ScrollMetrics,
324    ScrollPhysics, Scrollbars, CONSTANT_DECELERATION_FAST, MAX_FLING_VELOCITY, MIN_FLING_VELOCITY,
325};
326pub use placeholder::{Placeholder, PLACEHOLDER_COLOR, PLACEHOLDER_FALLBACK, PLACEHOLDER_STROKE};
327pub use popover::MenuAnchor;
328pub use portal::{OverlayPortal, Placement};
329pub use positioned::{Positioned, Positioning};
330pub use progressbar::LinearProgressIndicator;
331pub use radio::{Radio, RadioGroup};
332pub use rating::Rating;
333pub use refresh::{RefreshIndicator, RefreshPhase, RefreshPull, RefreshSpec, Refreshable};
334pub use relayout::LayoutCache;
335pub use reorder::{
336    nearest_reorder_slot, reflow_reorder_cards, reflow_reorder_columns, reorder_drop_after,
337};
338pub use reorderable::{settled_index, ReorderGrab, ReorderableList};
339pub use responsive::{responsive, Responsive};
340pub use richtext::RichText;
341pub use rotatedbox::RotatedBox;
342pub use router::{GoRoute, GoRouter, GoRouterState};
343pub use rowcolumn::{Column, MainAxisSize, Row, VerticalDirection};
344pub use runtime::{
345    spring_ease, spring_step, Anim, Edit, Runtime, ScrollBallistic, ScrollState, ScrollbarFade,
346    SelectionHandle, TransformValues, ValueAnim,
347};
348pub use safearea::SafeArea;
349pub use scaffold::{fab_button, FabLocation, NavPlacement, Scaffold};
350pub use scaffoldinfo::{ScaffoldGuard, ScaffoldInfo, ScaffoldScope};
351pub use scroll::{Axis, SingleChildScrollView};
352pub use scrolloverlay::{OverlayBuilder, ScrollOverlay};
353pub use scrollposition::{ScrollPosition, ScrollTarget, ScrollTo};
354pub use searchbar::{SearchBar, SEARCH_BAR_HEIGHT, SEARCH_BAR_MAX_WIDTH, SEARCH_BAR_MIN_WIDTH};
355pub use searchview::{
356    SearchAnchor, SEARCH_VIEW_FULL_SCREEN_HEADER, SEARCH_VIEW_MIN_HEIGHT, SEARCH_VIEW_MIN_WIDTH,
357    SEARCH_VIEW_RADIUS,
358};
359pub use segmented::{
360    SegmentedButton, SEGMENTED_BORDER_WIDTH, SEGMENTED_HEIGHT, SEGMENTED_ICON_GAP,
361    SEGMENTED_ICON_SIZE, SEGMENTED_PADDING,
362};
363pub use semantics::{Description, Semantics};
364pub use sheet::{
365    sheet_takes_release, split_sheet_drag, DraggableScrollableSheet, SheetArea, SheetSpec,
366    SheetState, SheetTo, SnapSimulation, SHEET_SNAP_MIN_SPEED,
367};
368pub use shortcuts::{
369    ActionListener, Actions, CallbackShortcuts, FocusableActionDetector, Intent, KeyStroke,
370    KeyboardListener, ShortcutKey, Shortcuts,
371};
372pub use skeleton::Skeleton;
373pub use slider::{RangeSlider, Slider};
374pub use spacer::Spacer;
375pub use spinner::CircularProgressIndicator;
376pub use stack::{IndexedStack, Stack, StackFit};
377pub use stepper::Stepper;
378pub use steps::Steps;
379pub use switch::Switch;
380pub use switcher::AnimatedSwitcher;
381pub use system_ui::{AnnotatedRegion, SystemBars, SystemUiOverlayStyle};
382pub use table::Table;
383pub use tabs::{
384    TabAlignment, TabBar, TabBarVariant, TabItem, TAB_DIVIDER_HEIGHT, TAB_HEIGHT, TAB_ICON_GAP,
385    TAB_ICON_HEIGHT, TAB_ICON_SIZE, TAB_INDICATOR_PRIMARY, TAB_INDICATOR_SECONDARY,
386    TAB_LABEL_PADDING, TAB_START_OFFSET,
387};
388pub use text::Text;
389pub use textinput::{
390    TextField, TextFieldStyle, TextFieldVariant, FIELD_BORDER_WIDTH,
391    FIELD_DENSE_OUTLINED_PADDING_BOTTOM, FIELD_DENSE_OUTLINED_PADDING_TOP, FIELD_DENSE_PADDING_Y,
392    FIELD_DISABLED_OPACITY, FIELD_FOCUSED_BORDER_WIDTH, FIELD_GAP, FIELD_ICON_SIZE,
393    FIELD_LABEL_SCALE, FIELD_NOTCH_GAP, FIELD_OUTLINED_PADDING_BOTTOM, FIELD_OUTLINED_PADDING_TOP,
394    FIELD_PADDING_X, FIELD_PADDING_Y, FIELD_RADIUS, FIELD_SUB_SIZE, FIELD_TEXT_SIZE,
395};
396pub use theme::{
397    ColorScheme, TapTarget, TextTheme, Theme, ThemeMode, MIN_TAP_TARGET, SHRUNK_TAP_TARGET,
398};
399pub use themebuilder::ThemeBuilder;
400pub use themed::Themed;
401pub use timeline::Timeline;
402pub use timepicker::{Endpoint, TimeField, TimePicker, TimeRange};
403pub use toast::{SnackBar, SnackBarBehavior, SnackBarKind, SnackBarQueue};
404pub use toasthost::{ScaffoldMessenger, SnackBarPosition};
405pub use togglebuttons::{
406    ToggleAxis, ToggleButtons, TOGGLE_BUTTONS_BORDER_WIDTH, TOGGLE_BUTTON_MIN_SIZE,
407};
408pub use tooltip::Tooltip;
409pub use transform::{FractionalTranslation, Transform};
410pub use transitions::{
411    eased, DecoratedBoxTransition, DecorationPosition, DefaultTextStyleTransition, FadeTransition,
412    ScaleTransition, SlideFrom, SlideTransition,
413};
414pub use tree::Tree;
415pub use twopane::TwoPane;
416pub use ui::{
417    build_deferred, build_ui, build_ui_inspected, collect_ids, find_by_key, find_path,
418    find_sheet_by_key, find_widget, reorder_siblings, reorderable_owners, subtree_ids,
419    FocusDirection, Focusable, KeepVisible, Scrollable, Scrollbar, Ui,
420};
421pub use undo::{EditKind, EditSnapshot, UndoHistory, RUN_PAUSE};
422pub use wheel::{ListWheel, RowOnWheel, WheelGeometry};
423pub use widget::{CellFn, FillAxes, FilterContext, ReorderAxis, Widget};
424pub use widgetstate::{StateFilter, WidgetState, WidgetStateProperty, WidgetStates};
425// **Every** one of them, and not only the ones a doc link happened to need. A theme
426// struct that is `pub` inside a private module is public and unreachable: callers can
427// still set `theme.widgets.button.background`, because the field's type is inferred, but
428// they cannot name the type — so `AppBar::icon_theme` took an `IconTheme` no caller
429// could build from milestone 396 until now. A property that ships unusable is a property
430// that did not ship.
431pub use widgettheme::resolve_shape;
432pub use widgettheme::{
433    AppBarTheme, BadgeTheme, ButtonTheme, CardTheme, CheckboxTheme, ChipTheme, DefaultTextStyle,
434    DividerTheme, DrawerTheme, DropdownTheme, ExpansionPanelListTheme, GridTileBarTheme,
435    IconButtonTheme, IconTheme, InkTheme, MenuTheme, PageSelectorTheme, RadioTheme, SegmentedTheme,
436    SliderTheme, SwitchTheme, TabBarTheme, TextFieldTheme, ToggleButtonsTheme, WidgetThemes,
437};
438
439// Convenience re-exports for callers.
440/// Installing the reader's font size for a whole frame — see
441/// [`frus_core::install_text_scale`]. Re-exported for the shell, which has to hold it
442/// across the build, the layout **and** the paint.
443pub use frus_core::{install_text_scale, TextScaleGuard};
444pub use frus_core::{
445    Affine, Alignment, AlignmentDirectional, AlignmentGeometry, Backdrop, BlendMode, Border,
446    BorderRadius, BoxDecoration, BoxFit, BoxShadow, ClipShape, Color, ColorFilter, Colors,
447    FontWeight, FractionalMask, ImageData, ImageFilter, ImageHandle, Insets, InsetsDirectional,
448    LinearGradient, MaterialColor, Orientation, Path, PathVerb, Point, Primitive, Rect, Role,
449    Scene, SemanticsProperties, Size, SizeClass, TextAlign, TextDecoration, TextDirection,
450    TextOverflow, TextSpan, TextStyle, Toggled, WindowInsets,
451};
452/// The shared animation layer — physics, curves, driver — see
453/// [`frus_core::animation`]. Re-exported here so applications can reach it through
454/// `frus_widgets` without depending on `frus-core` directly.
455pub use frus_core::{
456    AnimationController, ClampedSimulation, Curve, FrictionSimulation, Lerp, Simulation,
457    SpringDescription, SpringSimulation, Tolerance, Tween, Velocity, VelocityEstimate,
458    VelocityStrategy, VelocityTracker,
459};
460// `frus_core::Status`, an animation's progress, is renamed so it does not shadow the
461// interaction `Status`, which is paint state: hover, press, focus and so on.
462pub use frus_core::Status as AnimationStatus;
463
464/// The image stores and the two things a host has to name: a decoder is chosen by the
465/// `images` feature, and the **fetcher** is registered by whoever has a network. See
466/// [`Image::network`].
467pub use frus_core::{images_in_flight, set_image_fetcher, ImageFetcher};
468pub use frus_layout::{Align, AlignContent, FlexDirection, Justify, Overflowing, Side};