GPUI Box GitHub

Components / display

Tag builder

A label with an optional remove action.

A builder is RenderOnce. Construct and mount it in one expression.

use gpui_kit::display::tag::Tag;

Reviewed in tag.

Construct
new(ident: impl Into<Ident>, label: impl Into<SharedString>) -> Self
Options

Chain onto the value.

tone(tone: Tone) -> Self
tint(tint: Hsla) -> Self
variant(variant: Variant) -> Self
color(color: impl Into<ColorChoice>) -> Self
on_remove(handler: impl Fn(&mut Window, &mut App) + 'static) -> Self
Example · tag
fn tag(_window: &mut Window, cx: &mut App) -> AnyElement {
    let theme = cx.theme().clone();
    stack(&theme)
        .child(caption(&theme, "Tones, which report rather than decorate"))
        .child(
            row(&theme)
                .child(Tag::new("scene.tag.rust", "rust").on_remove(|_, _| {}))
                .child(
                    Tag::new("scene.tag.failing", "failing")
                        .tone(Tone::Danger)
                        .on_remove(|_, _| {}),
                )
                .child(
                    Tag::new("scene.tag.passing", "passing")
                        .tone(Tone::Success)
                        .on_remove(|_, _| {}),
                )
                .child(
                    Tag::new("scene.tag.review", "needs review")
                        .tone(Tone::Warning)
                        .on_remove(|_, _| {}),
                ),
        )
        .child(caption(
            &theme,
            "An identity tint, which is a fact about who and not about severity",
        ))
        .child(
            row(&theme)
                .child(
                    Tag::new("scene.tag.ada", "Ada")
                        .tint(identity_tint(&theme, "agent.external"))
                        .on_remove(|_, _| {}),
                )
                .child(
                    Tag::new("scene.tag.grace", "Grace")
                        .tint(identity_tint(&theme, "agent.shell"))
                        .on_remove(|_, _| {}),
                ),
        )
        .child(caption(
            &theme,
            "Read-only: nothing offers to remove it, because no handler was given",
        ))
        .child(row(&theme).child(Tag::new("scene.tag.plain", "read-only")))
        .child(caption(
            &theme,
            "Disabled: the host refuses to act on it at all, and it dims to say so",
        ))
        .child(
            row(&theme).child(
                Tag::new("scene.tag.pinned", "pinned")
                    .disabled(true)
                    .on_remove(|_, _| {}),
            ),
        )
        .child(caption(
            &theme,
            "Singled out by the keyboard, which is what the next keystroke acts on",
        ))
        .child(
            row(&theme).child(
                Tag::new("scene.tag.selected", "selected")
                    .selected(true)
                    .on_remove(|_, _| {}),
            ),
        )
        .child(caption(
            &theme,
            "The shared tiers, resolved against a palette colour",
        ))
        .child(
            row(&theme).children(
                [Variant::Filled, Variant::Light, Variant::Subtle].map(|tier| {
                    Tag::new(format!("scene.tag.lime.{}", tier.name()), tier.name())
                        .variant(tier)
                        .color("lime")
                        .on_remove(|_, _| {})
                }),
            ),
        )
        .into_any_element()
}

Source: crates/gpui-kit/src/display/tag.rs