Skip to content

Views

View::render builds the UI after you invalidate or the operating system asks for a redraw. Use id so rows keep their identity across renders.

#How views work

Return impl IntoElement from render. The window sleeps until invalidate or a platform event.

#Conditional content

if self.expanded {
    text("Expanded content")
} else {
    text("Collapsed")
}

Omitting a branch drops those nodes.

#Lists

div().children(self.items.iter().map(|item| {
    text(item.name.as_str()).id(item.id)
}))

Give stateful rows stable ids. For long collections, use VirtualList or Table.

#Window lifecycle

Each open_window owns an independent view. Closing one window does not drop the others. Handle the Dock icon by opening a new window when has_visible_windows is false.

#Current window

fn render(&mut self, cx: &mut ViewContext<'_, Self>) -> impl IntoElement {
    let close = cx.listener("close", |_this, cx: &mut EventContext| {
        let _ = cx.close_window();
    });
    button().on_click(close).child("Close")
}

#Testing

quickgui check
quickgui test

examples/base_ui_components.rs is the UI gallery. Enable the inspector crate feature for the in-app inspector.