dioxus-compose guide

Mixing the two

HTML and widgets on one screen planned

Both vocabularies are in the crate today, and an rsx! block uses one of them. Putting both on one screen is decided and not built. This page describes the design so you can see where it is going; none of it works yet.

Today

An app picks one prelude. dioxus_compose::html::prelude::* names the HTML elements and dioxus_compose::prelude::* names the widgets, each as dioxus_elements, so a block of rsx! sees one set or the other. The widget path draws today; the HTML path is laid out and planned but not drawn (#43), and mixing builds on that bridge.

One node, one world

Every node will belong to exactly one world, decided by its element name: a widget name this crate defines is a widget, and anything else is HTML. The two meet only at placeholder nodes, so neither world has to understand the other's rules.

HTML inside a widget

An HtmlView widget will hold an HTML island. Its size comes from the Compose layout around it, and the Host lays the HTML out at that width. When the window resizes, only that island is laid out again.

illustrative: HtmlView is planned and does not compile today
rsx! {
    Column {
        fill_max_width: true,
        TopAppBar { title: "Release notes" }
        HtmlView {
            weight: 1.0,
            article { class: "notes",
                h1 { "Version 0.2" }
                p { "Screens written with HTML and CSS are drawn." }
            }
        }
    }
}

Widgets inside HTML

A widget inside HTML will be a box whose contents CSS does not know, like an image. Its natural size will be asked of the renderer during layout, with the same synchronous call that measures text, so a TextField or a DatePicker sits on a line at the size Compose gives it and the text around it flows past.

The rules across the seam

Status

planned The design is settled and is scheduled after the HTML path draws on screen. #59 tracks it; it builds on #43.