GPUI Box GitHub

Components / controls

CopyButton view

A button that copies caller-supplied text and confirms what happened.

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

use gpui_kit::controls::copy_button::CopyButton;

Reviewed in copy-button.

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

Chain onto the value.

text(text: impl Into<SharedString>) -> Self
label(label: impl Into<SharedString>) -> Self
glyph_only(name: impl Into<SharedString>) -> Self
variant(variant: ButtonVariant) -> Self
copier(copier: impl Fn(&str, &mut App) -> Result<(), SharedString> + 'static) -> Self
confirmation(confirmation: Duration) -> Self
Commands

Need a Context, so they need a view.

set_text(text: impl Into<SharedString>, cx: &mut Context<Self>)
set_label(label: Option<SharedString>, cx: &mut Context<Self>)
set_glyph_only(name: Option<SharedString>, cx: &mut Context<Self>)
set_variant(variant: ButtonVariant, cx: &mut Context<Self>)
set_control_size(size: ControlSize, cx: &mut Context<Self>)
set_confirmation(confirmation: Duration, cx: &mut Context<Self>)
set_copier(copier: impl Fn(&str, &mut App) -> Result<(), SharedString> + 'static, cx: &mut Context<Self>)
clear_copier(cx: &mut Context<Self>)
set_disabled(disabled: bool, cx: &mut Context<Self>)
copy(cx: &mut Context<Self>)
Queries

Only answer; they change nothing.

state() -> &CopyState
is_disabled() -> bool
Example · copy-button
fn copy_button(window: &mut Window, cx: &mut App) -> AnyElement {
    ensure_ordinary(window, cx);
    let scene = cx.global::<SceneOrdinary>();
    let idle = scene.copy_idle.clone();
    let copied = scene.copy.clone();
    let refused = scene.copy_refused.clone();
    let theme = cx.theme().clone();
    stack(&theme)
        .child(caption(&theme, "Nobody has pressed it yet"))
        .child(idle)
        .child(caption(&theme, "The clipboard took it"))
        .child(copied)
        .child(caption(&theme, "It did not go through, and says so"))
        .child(refused)
        .into_any_element()
}

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