Expand description
The widget vocabulary as composables: the same widgets, the same properties and the
same Modifier slots the rsx! layer writes, with Compose’s names and Compose’s shape.
use compose_rust::runtime::*;
use compose_rust::ui::*;
#[composable]
fn Greeting(name: String) {
Column().modifier(Modifier.padding(16.0).fill_max_width()).content(|| {
Text(format!("Hello, {name}")).type_role(TypeRole::Title);
Button("Wave").on_click(|| show_message("Hello back"));
});
}A widget is written as a statement. Text("Hello") creates a description and the
statement’s end hands it to the composition; the methods in between set what Compose
would take as named arguments. A container’s children are the closure given to
content, which runs at once. Binding a widget to a variable delays it to the end of
the variable’s scope, so a widget is not bound.
Nothing here defines a widget. Each composable writes exactly the attributes its
rsx! counterpart writes, through the same translation into wire records, so a screen
written either way is the same tree of the same nodes for the Renderer. A Modifier the
rsx! counterpart does not accept is still written when it is set, because the wire
carries every Modifier slot on every node.
Re-exports§
pub use crate::boundary::LaunchBuilder;pub use crate::brush::Brush;pub use crate::brush::Stop;pub use crate::brush::brush;pub use crate::drawing::DrawCommand;pub use crate::drawing::DrawList;pub use crate::drawing::DrawListBuilder;pub use crate::message::Message;pub use crate::message::show_message;pub use crate::runtime::application;pub use crate::runtime::launch;pub use crate::schema::Alignment;pub use crate::schema::Arrangement;pub use crate::schema::ButtonKind;pub use crate::schema::ButtonVariant;pub use crate::schema::Color;pub use crate::schema::ColorRole;pub use crate::schema::ColorScheme;pub use crate::schema::DesignSystem;pub use crate::schema::IconRole;pub use crate::schema::Key;pub use crate::schema::MaterialRole;pub use crate::schema::MessageDuration;pub use crate::schema::MotionRole;pub use crate::schema::Paint;pub use crate::schema::ShapeRole;pub use crate::schema::SpaceRole;pub use crate::schema::TextAlign;pub use crate::schema::TextOverflow;pub use crate::schema::Theme;pub use crate::schema::TypeRole;pub use crate::schema::WindowHeightClass;pub use crate::schema::WindowSizeClass;pub use crate::spans::TextSpans;pub use crate::theme::ThemeHandle;pub use crate::theme::current_theme;pub use crate::window::NodeSize;pub use crate::window::WindowSize;pub use crate::Cursor;pub use crate::FileDrop;pub use crate::KeyEvent;pub use crate::PointerEvent;pub use crate::PointerKind;pub use crate::PointerKinds;pub use crate::RangeRequest;pub use crate::UserSelect;pub use crate::asset;pub use crate::asset;
Structs§
- Asset
Scope - An
Imageor anIconand its builder. - Badge
Scope - A
Badgeand its builder. - Button
Scope - A
Buttonand its builder. - Canvas
Scope - A
Canvasand its builder. - Card
Scope - A
Cardand its builder. - Checkbox
Scope - A
Checkboxand its builder. - Chip
Scope - A
Chipand its builder. - Column
Scope - A
Columnand its builder. - Compose
Box - A
Boxand its builder. Named apart fromstd::boxed::Box, which a glob import of this module would otherwise hide. - Date
Picker Scope - A
DatePickerand its builder. - Divider
Scope - A
Dividerand its builder. - Dropdown
Scope - A
Dropdownand its builder. - File
Drop Target Scope - A
FileDropTargetand its builder. - Floating
Action Scope - A
FloatingActionand its builder. - Lazy
List - A lazy list and its builder.
- Lazy
List Scope - What a lazy list’s builder is handed. Compose’s
LazyListScope. - Linear
Progress Indicator Scope - The worked extension widget: Material 3’s determinate linear progress indicator.
- Menu
Scope - A
Menuand its builder. - Modal
Scope - A
Dialogor aSheetand its builder:openseeds the Renderer’s own open state, andon_dismisssays once that the user asked to close it. - Modifier
- What sits around a widget: its size, its surface, its outline, how far its content
is inset, and what the Renderer reports about it. Compose’s
Modifier. - Navigation
Item Scope - A
NavigationItemand its builder. - Navigation
Scope - A
Navigationand its builder. - Progress
Indicator Scope - A
ProgressIndicatorand its builder. - Radio
Button Scope - A
RadioButtonand its builder. - RowScope
- A
Rowand its builder. - Scaffold
Scope - A
Scaffoldand its builder. - Scroll
Column Scope - A
ScrollColumnand its builder. - Scroll
RowScope - A
ScrollRowand its builder. - Selection
Container Scope - A
SelectionContainerand its builder. - Slider
Scope - A
Sliderand its builder. - Spacer
Scope - A
Spacerand its builder. - Split
Pane Scope - A
SplitPaneand its builder. - Surface
Scope - A
Surfaceand its builder. - Switch
Scope - A
Switchand its builder. - Tabs
Scope - A
Tabsand its builder. - Text
Field Scope - A
TextFieldand its builder. - Text
Scope - A
Textand its builder. - Time
Picker Scope - A
TimePickerand its builder. - Tooltip
Scope - A
Tooltipand its builder. - TopApp
BarScope - A
TopAppBarand its builder.
Constants§
- Modifier
- The empty Modifier, to start a chain from:
Modifier.padding(8.0).
Functions§
- Badge
- A count, a word or a dot, on its child or on its own. Compose’s
BadgedBoxandBadge. - Box
- Stacks its children on top of each other. Compose’s
Box. - Button
- A button with a label. Compose’s
Button; the variant is the design system’s seam, soButtonVariant::Textis Compose’sTextButtonandOutlineditsOutlinedButton. - Canvas
- Pixels the widget vocabulary cannot produce. Compose’s
Canvas, with the drawing as a value rather than a callback: drawing code cannot cross into the Renderer, and an equal list costs no record. - Card
- A grouped container. What it looks like is the design system’s.
- Checkbox
- A box that is ticked or not. Compose’s
Checkbox(checked, onCheckedChange). - Chip
- A small token that is chosen or filters. Compose’s
FilterChip. - Column
- Lays its children out one after another. Compose’s
Column. - Date
Picker - A date, as whole days since 1970-01-01. How it is picked is the design system’s.
- Dialog
- A modal. Compose’s
Dialog, kept in the tree and opened byopen, so its enter and exit belong to the Renderer. - Divider
- A line between two things. Compose’s
HorizontalDivider;verticalmakes it the other. - Dropdown
- One choice out of a list; each child is one option.
- File
Drop Target - A place files may be dropped. Desktop only in effect.
- Floating
Action - The one action a screen is about. Compose’s
ExtendedFloatingActionButton; where it goes is the design system’s answer. - Icon
- A registered icon, tinted. Compose’s
Icon. - Image
- A registered asset drawn as a picture. Compose’s
Image. - Indeterminate
Progress Indicator - Work in progress of no known length.
- Lazy
Column - A vertical list that composes only the items on screen. Compose’s
LazyColumn. - Lazy
Grid - A grid that composes only the rows on screen. Compose’s
LazyVerticalGrid; say how wide a column is withcolumnsormin_column_width. - LazyRow
- A horizontal list that composes only the items on screen. Compose’s
LazyRow. - Linear
Progress Indicator - The extension widget the schema carries as its example.
- Menu
- A popup hanging off its anchor. Compose’s
DropdownMenu, with the anchor said rather than positioned: the Renderer places the popup. - Navigation
- A set of destinations and the screen they lead to. The children that are
NavigationItems are the destinations; whether they are a bar, a rail or a drawer is the Renderer’s choice. Compose’sNavigationSuiteScaffold. - Navigation
Item - One destination inside a
Navigation. Compose’sNavigationSuiteItem. - Progress
Indicator - How far along something is, as a fraction. Compose’s
LinearProgressIndicator(progress). - Radio
Button - One choice out of several. Compose’s
RadioButton(selected, onClick). - Row
- Lays its children out one after another. Compose’s
Row. - Scaffold
- The screen’s frame: which slots it has filled, and the page. Compose’s
Scaffold. What each slot becomes on this platform at this width is the Renderer’s decision. - Scroll
Column - All of its content, with a vertical scroll the Renderer owns.
- Scroll
Row - All of its content, with a horizontal scroll the Renderer owns.
- Selection
Container - Every
Textinside can be selected and copied as one selection. - Separator
- A hairline between two rows of a grouped list, in the design system’s quiet edge or
the given colour. The same node as
Divider().modifier(Modifier.background(color)). - Sheet
- A surface that slides in from the edge the Renderer chooses. Compose’s
ModalBottomSheet, without a promise about which edge. - Slider
- A value picked from a range. Compose’s
Slider. The drag is the Renderer’s;valueseeds it and moves it when the change came from elsewhere. - Spacer
- Empty space, sized by its Modifier.
- Split
Pane - A side pane and a body with a divider the user drags. Exactly two children, side pane first. The drag is reported once, when it ends.
- Surface
- A plain background and elevation, without a card’s meaning.
- Switch
- An on and off control. Compose’s
Switch(checked, onCheckedChange). - Tabs
- A row of tabs; each child is one tab, and a tap is that child’s own click. Compose’s
TabRow. - Text
- Text. Compose’s
Text. - Text
Field - An uncontrolled text field. Compose’s
TextField, with the value kept where the platform’s text input keeps it: the Renderer reports each change and the Host never writes the value back while the user types. - Time
Picker - A time of day, as minutes since midnight.
- Tooltip
- An explanation attached to its child, which assistive technology reads too. Compose’s
TooltipBox. - TopApp
Bar - The bar across the top of a screen; its children are its content. Compose’s
TopAppBar, with the title a property so the Renderer can find it. - theme
- The application’s theme, to read and to change while it runs. A change is one
SetThemerecord in the batch the call that made it produces.