# Platform

Crate: `libero`
Import: `use libero::{hooks::use_element, platform::{clock, color_scheme, document, keyboard, scroll, timer}};`
Index: [index.md](index.md) lists every other page
Description: Every platform API (elements, timers, keys, scroll, the document, the colour scheme, the clock), what each enables, and what to do where a renderer lacks one.

Everything that reaches past dioxus to the machine goes through
`libero::platform`. Components use it, and so can you. One call works on the web
and natively, and each renderer answers with what it has.

## The APIs

| API | What it gives | What you can build |
|---|---|---|
| `use_element()` | Focus, scroll, measure and query one element you mount. | Focus a field when a dialog opens, scroll a row into view, size a popup to its trigger. |
| `timer()` | A callback after a delay or on an interval. | Autoplay, a toast that closes itself, a debounced search. |
| `keyboard()` | Key presses anywhere in the document. | App-wide shortcuts, such as Ctrl+K for a command palette. |
| `scroll()` | Scrolling anywhere, not only the page. | Close a popup when its trigger scrolls away, a header that hides on scroll. |
| `document()` | The focused element, the viewport size, and attributes on the root element. | Put focus back where it was, lay out by window size, set a theme attribute on the root. |
| `color_scheme()` | The system's light or dark, its changes, and a stored choice. | Follow the system theme and remember what the reader picked. |
| `clock()` | Today's date in the user's time zone. | Mark today in a calendar, start a date field on today. |

The web and Blitz answer all of them. A WebView, on desktop or Android, answers
them through the page's scripts, but some element calls there are unsupported.

The renderer is a build-time choice, one dioxus feature each: `web`, `native`
(Blitz), `desktop` (a WebView window) or `mobile` (the Android and iOS
WebViews). These docs build with each of them.

## Using them

Each accessor returns an `Option`. `None` means the running renderer can't do
it, so branch once and let the feature be absent there instead of unwrapping.

A callback API hands back a subscription, and dropping it stops the callback.
Keep it in a signal for as long as the component lives, and write what the
callback learns into a signal.

Element reads such as `dimensions()` are futures. Start one in an event handler
and await it in a `spawn`. A renderer that can't serve one answers
`PlatformError::Unsupported`.

## Clipping in a native window

Natively, a box with a `z-index` paints past the clip of an `overflow` box
around it, unless that box is a stacking context. Libero's own scrollers are
one. Give yours `position: relative; z-index: 0`, or use `ScrollArea`. This
covers a sticky `Header`, and a `Tooltip` or `HoverCard` trigger, which natively
carries a `z-index` so the pointer reaches it.

A button in the inline flow of a block with padding takes no click natively,
only keys. Make the parent a flex box, or wrap the button in a plain `div`. This
covers an `ActionIcon` or a `Burger` placed straight in a padded `div`.

## Links in a WebView

On desktop and Android, `http`, `https` and `mailto` links open in the system
browser and the app stays on its page. Any other scheme, such as `tel:`, `sms:`,
`intent:` or `file:`, navigates the WebView itself and takes the app away. Your
app builds the WebView, not Libero, so decide there: set
`Config::with_navigation_handler` to open those links outside the app or deny
them.
