Skip to main content

Crate mobiler_core

Crate mobiler_core 

Source
Expand description

Mobiler runtime — the developer-facing API.

Implement MobilerApp with your typed events, model, and view (built from the builders). Mobiler wraps it in MobilerShell, a Crux app speaking the fixed UI ABI (mobiler_ui); you never touch the wire protocol. Device APIs are capabilities via Cx.

Re-exports§

pub use app_info::AppInfo;
pub use clipboard::CopyOptions;
pub use device::DeviceInfo;
pub use photo::Photo;
pub use photo::PhotoError;
pub use photo::PhotoFormat;
pub use photo::PhotoOptions;
pub use dialog::Confirm;
pub use dialog::Picker;
pub use dialog::Snackbar;
pub use dialog::SnackbarDuration;
pub use format::Currency;
pub use format::Locale;
pub use format::Weekday;
pub use http::HttpHeader;
pub use http::HttpOutcome;
pub use i18n::Catalog;
pub use i18n::negotiate;
pub use transfer::TransferEvent;

Modules§

app_info
The app’s own version/build, handed to the core by the shell at startup (Action::AppInfo) and read via Cx::app_info.
bunny
Bunny.net Stream URL helpers — pure string builders, no I/O.
clipboard
A copy with options (ADR-0052): cx.copy_with / cx.copy_sensitive. The request goes to the built-in clipboard_with capability, not clipboard, so a shell that predates it answers ok: false instead of copying a secret in plain text.
device
Structured device details (cx.device_info), for support and bug reports.
dialog
Labels for the built-in confirm dialog and date/time pickers, so an app can word the buttons in its own language and say what they do (“Cancel booking” / “Keep it”) instead of a generic OK / Cancel. Used with Cx::confirm_with, Cx::pick_date_with and Cx::pick_time_with.
format
Locale-aware number, currency, and date formatting — pure, synchronous, dependency-light.
http
The HTTP capability’s payload types.
i18n
Tiny, dependency-free localization: pick a UI language from the device, then translate keys.
photo
Per-call photo options for Cx::pick_photo_with and Cx::capture_photo_with: the format, size and metadata the shell re-encodes a picked or captured image to (ADR-0045), and the typed reply. The pipeline rules every shell follows live here as functions, so they are stated and tested once.
transfer
Streaming file transfers (cx.upload / cx.download).

Structs§

ButtonOpts
Extra options for button_with; ButtonOpts::default() is a plain button.
Caption
One subtitle/caption track for a Widget::Video. url points at a WebVTT (.vtt) file, language is a BCP-47 tag (e.g. "en"), label is the human-readable menu entry, and default_on selects it by default. Sidecar tracks work on web (<track>) and Android (Media3 subtitle configuration); on iOS only captions already embedded in an HLS manifest are selectable (AVPlayer can’t attach a sidecar VTT to an MP4 — a documented v1 gap).
ChartBracket
A right-side bracket annotation spanning [y0, y1] with a label note (e.g. a ceiling band).
ChartLegendItem
One legend entry (swatch + name) for a Widget::RegionChart.
ChartRefLine
A horizontal reference line across a Widget::RegionChart at value, with a right-edge label chip. dashed draws it dashed (e.g. a “max insured” ceiling) vs solid (a target).
ChartRegion
One rectangle in a Widget::RegionChart, spanning [x0, x1] horizontally and [y0, y1] vertically in the chart’s domain. label is centered inside (empty = none); vertical rotates it 90° for narrow columns. color overrides the auto-assigned palette slot.
ChartSeries
One named data series in a Widget::Chart. Cartesian styles plot values across the chart’s x-axis labels; circular styles (pie/donut/rings/gauge) collapse the series to a single magnitude (values summed). color overrides the auto-assigned palette slot; goal is the denominator for Rings/Gauge progress (ignored by the other styles).
ChartTick
An x-axis tick on a Widget::RegionChart at domain position at, labelled label. Ticks are irregular (the app places them), so shells position them by fraction, not even spacing.
ColorRoles
Colour roles; every one optional (None = the shell’s current colour for that role).
Cx
Effects an app requests during update, generic over the app event type so continuations stay fully typed.
Fab
A floating action button anchored over the scaffold body (the raised primary action).
MapMarker
A pin on a Widget::Map. id is echoed back when the marker is tapped (Action::Input { id: "{map_id}.marker", value: Text(marker.id) }).
MobilerShell
Crux adapter: turns a MobilerApp into an app speaking the fixed ABI.
Nav
A navigation stack the app holds in its Model. The core owns the stack (single source of truth); the framework reads its route/depth to drive the shell’s push/pop transitions and back button.
Palette
A light and a dark set of colour roles — the design’s tokens. See ColorRoles.
PluginCall
PluginNotify
PluginResponse
A plugin’s reply. output is raw bytes: the HTTP capability puts a bincode HttpOutcome here, while most plugins put UTF-8 text (use PluginResponse::text to build one and as_text to read it).
PluginStreamCall
A streaming plugin subscription (powers Effect::PluginStream). Like PluginCall but carries a caller-chosen key so the subscription can be torn down (Cx::unsubscribe) — the shell registers the native source under key.
Rgb
A 24-bit RGB color. Used for a theme’s brand/seed color — the one place an app supplies an arbitrary color (everything else is intent tokens).
Rgba
A colour with alpha (a: 0 = transparent, 255 = opaque).
Segment
One option in a Widget::Segmented control (mirrors Tab). selected marks the active segment; tapping sends on_select.
Shapes
A corner radius per component. sheet_top rounds only the bottom sheet’s top corners (Pill there is capped at 32 — a dome would clip the sheet’s content). button also shapes the confirm dialog’s buttons where the shell draws them (web, Android); iOS uses the system alert.
Sheet
A modal bottom sheet anchored over the scaffold body (a scrim behind, a panel rising from the bottom). Present (Some) ⇒ open; tapping the scrim/handle sends on_dismiss.
ShellLabels
Text the shells draw themselves (back buttons, web list controls, dialog/picker defaults), in the app’s language. Set once on the scaffold with with_labels; every field is optional and falls back to the shell’s built-in English. A label passed to a specific call (confirm_with, Picker) still wins over these.
SwipeButton
One revealed action in a SwipeAction row (swipe to reveal, tap to fire).
Tab
A bottom-navigation tab. selected marks the active one; tapping sends on_select. icon (optional) renders above the label for an icon tab bar.
TabBadge
A tab’s badge (ADR-0050). Both strings are finished by the core: the shells draw text as-is and add no words.
Theme
App branding as data — the visual twin of dark_mode. Set on a Widget::Scaffold (theme: None = the framework defaults, i.e. no visual change). The shell maps these to its native theming: seed → the brand/primary color (Android M3 scheme / iOS tint / web --primary), plus a global corner, spacing, and font choice.
TonePair
A tone’s soft background and its foreground.
TypeScale
The app’s type scale: one optional TypeSpec per text style. title also sets the scaffold’s top-bar title and headline the sheet titles. Sizes are sp/pt/px and still follow the platform’s text-size accessibility setting.
TypeSpec
One style’s size (sp/pt/px), weight (100..=900, rounded to the nearest 100) and font role.

Enums§

A11yRole
Accessibility role for Widget::A11y — the control type announced to a screen reader. Maps best-effort per platform: iOS accessibility traits, Android semantics role / heading(), web ARIA role.
Action
What the shell sends back to the core. Fixed across all apps.
Appearance
How the scaffold picks light or dark. Light/Dark force it; System follows the OS live (the shell switches palette sets itself, no core round-trip). Set with with_appearance.
BoxAlign
ButtonStyle
Button emphasis. Tonal is the quieter filled secondary (M3 filled-tonal).
CardStyle
Dashed: no fill and a dashed outline (“empty, you can fill this”). BREAKING (Moj Termin design release): appended, so exhaustive matches need the case.
ChartStyle
How a Chart draws its series.
Corner
Global corner-radius scale. Medium ≈ the current (un-themed) look.
Density
Global density. Comfortable ≈ the current (un-themed) look; Compact tightens spacing. Large is for hurried / wet / gloved hands: bigger controls (56 buttons & segmented, 48 chips & calendar days, 56 icon-button targets), 16 control labels, ≥ 12 between adjacent tappables. Body text stays on the platform’s font-scale setting.
Effect
Built-in capabilities the generic shell fulfils.
EffectFfi
FamilyRole
Which synced font a TypeSpec uses under FontFamily::Custom (otherwise the theme’s system font).
FieldKind
What a Widget::TextField accepts — selects the on-screen keyboard, secure (masked) entry, and single- vs multi-line layout in one axis.
FontFamily
A cross-platform font family. System/Rounded/Serif/Monospace map to each platform’s nearest system font design. Custom = the app’s mobiler.toml [fonts], synced into the shells by the CLI (mobiler fonts sync, also run by build/dev): the display family for titles and subtitles, the body family for the rest; a role without files falls back to the system font. System ≈ the current look.
Icon
A finite icon set (maps to Material icons / SF Symbols / web glyphs per shell). Grouped: editing, navigation/chrome, content, and domain icons.
ImageRatio
ImageShape
InputValue
A value produced by an input widget at runtime.
ProjectColor
Project-identity colors (distinct from semantic Tone). Concrete RGB decided in the render layer.
Radius
A corner radius: Dp(n) (dp/pt/px), or Pill — fully round (half the component’s height), at any density.
Spacing
TextStyle
Tone
Semantic status color (distinct from brand/identity color).
Widget
The app-agnostic widget tree the shell renders. Fixed across all apps.

Traits§

MobilerApp
What a Mobiler app implements. Write typed domain events; Mobiler serializes them into opaque tokens behind the scenes.

Functions§

a11y
Wrap child so a screen reader (VoiceOver / TalkBack) announces the subtree as ONE element named label — gives an unlabeled icon_button/image a name, or groups a card’s children into one announced element. Add with_a11y_hint / with_a11y_role for the activation hint + control type.
avatar
A circular avatar image.
avatar_status
A circular avatar image with a colored status dot.
badge
bar_chart
A bar chart of values (normalized to the max), with optional per-value labels. Single-series, no axis or legend — for richer charts use chart.
button
button_with
A button with a ButtonOpts tone, leading icon, and/or full width.
calendar
An inline month calendar for year/month (1–12), US English (Sunday-first). on_day(d) builds the tap event for each day d; selected highlights a day. See calendar_in for a localized calendar with per-day markers.
calendar_in
A localized inline month calendar: the title, weekday header and week start follow locale (e.g. Locale::SrLatn → “Septembar 2026”, Monday-first P U S Č P S N). markers is one busy-level per day (markers[d-1], 0..=3, drawn as that many dots; 0 = none) — pass &[] for no markers. Shorter slices pad with 0; levels above 3 clamp to 3.
caption
card
card_button
A tappable card carrying a typed press event.
chart
A multi-series chart in the given style, with optional x-axis labels, y-axis gridlines/ ticks (cartesian styles), and a series legend. The general builder behind the convenience constructors below.
checkbox
chip
color_dot
A small colored identity dot.
column
decimal_field
A decimal keypad field (FieldKind::Decimal).
display
The largest text — e.g. an appointment time. Defaults to 36 bold (the display font under FontFamily::Custom); Theme.type_scale.display overrides it.
divider
donut_chart
A donut chart (pie with a center hole). Legend on.
email_field
An email-keyboard field (FieldKind::Email).
emphasis
field
A text field with full control over FieldKind and an optional inline validation error. The kind-specific helpers below (secure_field, email_field, …) wrap this for the common cases.
gauge_chart
A single radial gauge — the first series’ value / goal with the number in the center.
grid
headline
A section/sheet heading. Defaults to 24 semibold; Theme.type_scale.headline overrides it.
icon_button
image
lazy_list
A scrollable list for long/paged feeds that fires on_load_more when the user scrolls near the end. The app owns the state: append to children on each load-more event, set loading true while the page loads (the shell shows a spinner and won’t re-fire), and has_more=false when the feed is exhausted. Add pull-to-refresh at the top with with_refresh. Give it room — a LazyList nested in a scrollable body needs a bounded height to scroll on its own.
lazy_list_static
A scrollable list with no load-more and no refresh — a plain virtualized list of children.
line_chart
A line chart of values (normalized to the max), with optional per-value labels. Single-series, no axis or legend — for richer charts use chart.
map
An interactive map centered at (center_lat, center_lng) with the given zoom (≈ MapLibre/Google zoom levels: ~2 world, ~14 city, ~17 street). iOS MapKit / Android MapLibre / web MapLibre-GL — no API key. Add pins with with_markers, a vector style with with_map_style. Taps arrive in MobilerApp::input as Input { id: "{id}.tap", Text("lat,lng") } / { "{id}.marker", Text(id) }. Give it a height (a sized container or card).
marker
A map pin at (lat, lng); id is echoed on tap. Add a title with marker_titled.
marker_titled
A titled map pin (the title shows in the marker’s callout/popup).
multiline_field
A growable multi-line text area (FieldKind::Multiline).
nav_scaffold
Scaffold driven by a Nav stack: fills route (from the current route’s serialization) and depth (stack depth) so the shell animates transitions, and shows a back affordance (top-bar arrow + system back button) firing on_back whenever the stack can pop.
number_field
A whole-number keypad field (FieldKind::Number).
pct_stacked_bar_chart
Bars where each x-slot fills to 100% — series as proportions. Legend on, no value axis.
pdf_view
An in-app PDF viewer for the document at url (remote https URL or local file URI) — rendered natively per platform (PDFKit / PdfRenderer / <iframe>). The app just supplies the URL, e.g. a backend-generated report. Give it room (place in a sized container or a scroller).
phone_field
A phone-keypad field (FieldKind::Phone).
pie_chart
A pie chart — each series is one wedge sized by its magnitude. Legend on.
progress
A progress bar (Some(0.0..=1.0)) or an indeterminate spinner (None).
rating
A read-only star rating. value is in tenths (e.g. 48 = 4.8 of max stars).
rating_input
A tappable star rating — on_rate carries one event per star (star i fires on_rate[i]).
region_chart
A variable-width stacked-region (“coverage-gap” / Marimekko) chart. regions are rectangles in the [0, x_max] × [0, y_max] plane (build with ChartRegion::new); ticks label the irregular x-axis; ref_lines are horizontal target/max lines (ChartRefLine::target/::max); legend names the colors. Add a right-side bracket annotation with with_bracket.
rings_chart
Concentric progress rings — one per series, swept by sum(values) / goal. Legend on. Give each series a goal via ChartSeries::with_goal.
row
scaffold
App shell: top bar + bottom-nav tabs + scrollable body. dark_mode is theme-as-data (the shell themes the whole app from it).
scaffold_back
Like scaffold, but the top bar (and the system back button) navigate back via back — e.g. a detail screen pushed over a tab (treated as depth 2). For multi-level stacks, drive navigation with Nav + nav_scaffold.
scroller
Horizontally scrolling row of children (a carousel / chip rail).
scroller_hinted
A scroller whose trailing edge fades out — a hint that it scrolls.
search_field
A search input (leading magnifier, pill); emits Input { id, Text } like text_field.
secure_field
A masked password field (FieldKind::Secure).
segment
One option in a segmented control, carrying a typed selection event.
segmented
A single-choice segmented control (exclusive options in a pill).
skeleton
A shimmer placeholder shown while content loads.
slider
spacer
split
A two-pane master-detail layout (Widget::Split). Side-by-side on a wide screen (tablet / landscape); one pane on a phone — primary until show_detail (the app sets it on selection), then detail with a back chevron firing on_back. On wide, detail should show a placeholder until a row is selected.
stack
Z-stack/overlay (the Box widget). With scrim, the first child is a darkened background and the rest render on top.
stacked_bar_chart
Bars stacked to a total per x-slot. Axis + legend on by default.
step_text
The step indicator’s spoken text: template’s {current} / {total} filled in; a missing or empty template is "Step {current} of {total}". (Shells use this, or its native twin.)
stepper
steps
A step indicator: total equal segments with the first current filled (current is clamped to total), spoken as “Step 2 of 3” in the root scaffold’s ShellLabels::step_of language: steps(3, 2). It speaks the step itself: to also show the text, use with_step_caption rather than a separate text, which screen readers would read a second time.
styled
subtitle
swipe_action
A list row that reveals trailing actions (label, tone, event) on horizontal swipe; each is tappable. On web the actions render inline (no gesture).
tab
A bottom-nav tab carrying a typed selection event (label-only).
tab_icon
A bottom-nav tab with a leading icon (icon tab bar).
text
text_field
title
toggle
url_field
A URL-keyboard field (FieldKind::Url).
video_player
A controllable native video player for url (remote MP4/HLS or a local file URI), rendered with the native player per platform (AVPlayer / Media3 ExoPlayer / <video>). id routes the ~once-per-second position into input(id, InputValue::Int(position_ms)); build it fresh each render with the current playing (play/pause) + seek_to_ms (the shell jumps when this CHANGES; -1 = no seek). on_ended fires when the clip finishes. Defaults: controls shown, not looping/muted, no poster, no resume offset, no captions, rate 1.0, full volume, single clip (no playlist), PiP off — tune with with_loop/with_muted/without_controls/with_poster/with_start_at/with_captions/ with_rate/with_volume/with_pip (or video_playlist for a queue). Give it room.
video_playlist
A controllable native video player over a playlist of urls (auto-advances gaplessly; the shell reports the current track via input("{id}.index", InputValue::Int(i))). start_index is the first clip; build it fresh each render with the current playing. Force-jump to a track by pairing this with with_seek_index. on_ended fires when the LAST clip finishes. Same cosmetic modifiers as video_player. Empty urls renders nothing useful — use video_player for one clip.
web_view
A native web view showing the page / embedded player at url (WKWebView / Android WebView / <iframe>). General-purpose: docs, dashboards, or a hosted player embed (e.g. a Bunny.net / YouTube embed URL). NOT the default video player — use video_player for that. Give it room (a sized container or a card).
with_a11y_hint
Set the accessibility activation hint (e.g. “Opens your bookings”); wraps widget if it isn’t an a11y wrapper yet.
with_a11y_role
Set the accessibility role / control type; wraps widget if it isn’t an a11y wrapper yet.
with_appearance
Choose Light / Dark / System for the scaffold. System follows the OS live on every shell and switches the theme palette’s light/dark set by itself; dark_mode is then ignored.
with_avatar_size
Set an Avatar’s diameter in dp/pt/px (default 48); the status dot keeps its size. No-op on any other widget.
with_bottom_bar
Pin a screen’s main actions (one or two buttons, equal widths) in a bar above the tabs and the system navigation; the body ends above it, the FAB and snackbar float above it, and a sheet covers it. With the keyboard up it stays above the keyboard: on Android (11+; older Android pans the window) it rides on the keyboard while bottom tabs stay behind it; on iOS the bar and the tabs both rise. On the web it follows the browser’s viewport. Empty = no bar. No-op on any other widget — drive it from view like with_sheet: with_bottom_bar(root, vec![button_with("Završi", .., ButtonOpts::default().wide()), ..]) — wide buttons fill their equal cells on every shell.
with_bracket
Attach a right-side bracket annotation to a region_chart (no-op on any other widget).
with_captions
Attach subtitle/caption tracks to a video_player (see Caption). No-op on non-Video widgets.
with_columns
Give a Grid exactly columns equal columns (clamped to 1–4) at every width, instead of the adaptive 2-on-a-phone rule: with_columns(grid(slots), 3). No-op on any other widget.
with_end_label
Text shown at the end of an exhausted paged list (a lazy_list whose has_more is false) — e.g. “You’re all caught up”, in the app’s language. Without it nothing is shown there. Combines with with_refresh in either order. No-op on other widgets.
with_error
Attach an inline validation message to a Widget::TextField, marking it invalid. No-op on any other widget.
with_extended_fab
An extended FAB: the icon plus a label (“Novi termin”), which is also its accessible name. Same anchor, colours and shape as with_fab; no-op on any other widget: with_extended_fab(scaffold(...), Icon::Add, "New booking", Msg::New).
with_fab
Anchor a floating action button over a scaffold’s body (the raised primary action). No-op on any other widget: with_fab(scaffold(...), Icon::Add, Msg::New).
with_fill
Let a paged list fill the rest of the screen: when it is the scaffold body (or a direct child of the body’s column — the first such list), the body stops scrolling as a page and the list takes the remaining height, scrolling itself. Anywhere else it keeps its normal bounded height. Combines with with_refresh and with_end_label in any order. No-op on other widgets.
with_icon
Put an icon before a Badge’s label, so the status reads without its colour (with_icon(badge("Confirmed", Tone::Success), Icon::Check)). Decorative: only the label is read. No-op on any other widget.
with_initials
Give an Avatar initials, drawn when its source is empty or fails to load: with_initials(avatar(""), "MŽ"). Pass the initials, not the name — only the first two characters are drawn. No-op on any other widget.
with_labels
Set the app-wide shell text (see ShellLabels) on a scaffold — e.g. with_labels(root, ShellLabels::new().back("Nazad").ok("U redu").cancel("Otkaži")) also puts those words on a plain cx.confirm. Combines with the other scaffold helpers in any order. No-op on other widgets.
with_long_press
Attach a long-press (press-and-hold) event to a Card. No-op on any other widget. Combines with card / card_button — a card can carry both a tap and a long-press.
with_loop
Loop a video_player (restart on end). No-op on non-Video widgets.
with_map_style
Set the MapLibre vector-style URL (Android + web; iOS MapKit ignores it). None → a free default.
with_markers
Add/replace the pins on a map (no-op on any other widget).
with_muted
Start a video_player muted (needed for reliable autoplay). No-op on non-Video widgets.
with_pip
Enable Picture-in-Picture on a video_player (the shell adds a PiP affordance). No-op otherwise.
with_poster
Show poster (an image URL) before the first play / while idle. No-op on non-Video widgets.
with_rate
Set playback speed (1.0 = normal) on a video_player. No-op on non-Video widgets.
with_refresh
Enable pull-to-refresh on a scaffold’s body: the body becomes pull-refreshable and fires on_refresh on pull. refreshing is app-owned — set it true when the pull fires and clear it when the async reload completes (the shell shows a spinner while true). No-op on other widgets.
with_seek_index
Force a playlist video_playlist to jump to track index when this CHANGES. No-op otherwise.
with_sheet
Open a modal bottom sheet over a scaffold’s body. No-op on any other widget — drive it from the model: with_sheet(scaffold(...), title, sheet_body, Msg::CloseSheet).
with_start_at
Resume a video_player at start_at_ms (applied once on load). No-op on non-Video widgets.
with_step_caption
Show the step text (“Korak 2 od 3”, from ShellLabels::step_of) above a steps bar, as part of the same single accessibility element: with_step_caption(steps(3, 2)). No-op elsewhere.
with_tab_count
Marks a tab with a count (ADR-0050). 0 removes the badge, so an unread count passes straight through; above 99 it reads “99+”. label is the spoken text (e.g. “3 nove poruke”); empty = the screen reader reads the number.
with_tab_dot
Marks a tab with a small dot (ADR-0050). label is what a screen reader says after the tab’s label (e.g. “Nove poruke”); it is the app’s text, so it is in the app’s language.
with_theme
Apply a Theme to a scaffold (brand color, corner, density, font). No-op on any other widget. Lets an app brand its UI without new scaffold builder overloads: with_theme(nav_scaffold(...), Theme { seed, ..Default::default() }).
with_volume
Set the volume (0.0–1.0) on a video_player. No-op on non-Video widgets.
without_controls
Hide the native transport controls on a video_player (the app drives it). No-op otherwise.