GPUI Box GitHub

Components / controls

Cascader view

A menu of progressively revealed caller-owned option columns.

A view survives a frame. Hold it in an Entity with cx.new(..) and reach it with .update(..).

use gpui_kit::controls::cascader::Cascader;

Reviewed in cascader.

Construct
new(ident: impl Into<Ident>, _window: &mut Window, cx: &mut Context<Self>) -> Self
Options

Chain onto the value.

options(options: impl IntoIterator<Item = CascaderOption>) -> Self
selected(id: impl Into<SharedString>) -> Self
name(name: impl Into<SharedString>) -> Self
placeholder(placeholder: impl Into<SharedString>) -> Self
Commands

Need a Context, so they need a view.

set_options(options: Vec<CascaderOption>, cx: &mut Context<Self>)
set_selected(selected: Option<SharedString>, cx: &mut Context<Self>)
set_name(name: impl Into<SharedString>, cx: &mut Context<Self>)
set_placeholder(placeholder: Option<SharedString>, cx: &mut Context<Self>)
set_disabled(disabled: bool, cx: &mut Context<Self>)
set_control_size(size: ControlSize, cx: &mut Context<Self>)
open(window: &mut Window, cx: &mut Context<Self>)
close(cx: &mut Context<Self>)
Queries

Only answer; they change nothing.

selected_id() -> Option<&SharedString>
is_disabled() -> bool
is_open() -> bool
open_path() -> &[SharedString]
Reports

The variants of the event it emits. It never applies the change itself.

  • Selected
  • Expanded
  • Retry
  • Opened
  • Closed
Example · cascader
fn cascader(window: &mut Window, cx: &mut App) -> AnyElement {
    if !cx.has_global::<SceneCascader>() {
        let cascader = cx.new(|cx| {
            Cascader::new("scene.cascader", window, cx)
                .name("Fixture destination")
                .selected("release-notes")
                .options([
                    CascaderOption::new("guides", "Guides").children([
                        CascaderOption::new("getting-started", "Getting started"),
                        CascaderOption::new("configuration", "Configuration"),
                    ]),
                    CascaderOption::new("reference", "Reference").loading_children(),
                    CascaderOption::new("archive", "Archive").unavailable_children(
                        "The fixture host does not provide archived sections.",
                    ),
                    CascaderOption::new("release-notes", "Release notes"),
                    CascaderOption::new("managed", "Managed section").disabled(true),
                ])
        });
        cascader.update(cx, |cascader, cx| cascader.open(window, cx));
        cx.set_global(SceneCascader { cascader });
    }
    let theme = cx.theme().clone();
    let cascader = cx.global::<SceneCascader>().cascader.clone();
    stack(&theme)
        .w(px(680.0))
        .child(caption(
            &theme,
            "caller-owned hierarchy and value; the open path belongs only to the view",
        ))
        // The trigger is given the width its own popup has, so the scene does
        // not show a control that disagrees with the surface it opens.
        .child(div().w(px(380.0)).child(cascader))
        .into_any_element()
}

Source: crates/gpui-kit/src/controls/cascader.rs