Components / controls
TextInput view
One line of editable text.
A view survives a frame. Hold it in an Entity with cx.new(..) and reach it with .update(..).
use gpui_kit::controls::input::TextInput;
Reviewed in input touch-inputs.
Construct
new(ident: impl Into<Ident>, window: &mut Window, cx: &mut Context<Self>) -> Self
bind(input: &Entity<Self>, signal: &Signal<String>, cx: &mut App) -> Vec<Subscription>
Options
Chain onto the value.
placeholder(placeholder: impl Into<SharedString>) -> Self
input_options(options: gpui::TextInputOptions) -> Self
name(name: impl Into<SharedString>) -> Self
text(text: impl Into<SharedString>) -> Self
invalid(invalid: bool) -> Self
required(required: bool) -> Self
read_only(read_only: bool) -> Self
secret(secret: bool) -> Self
bare(bare: bool) -> Self
max_length(max_length: usize) -> Self
Commands
Need a Context, so they need a view.
set_input_options(options: gpui::TextInputOptions, cx: &mut Context<Self>)
set_name(name: impl Into<SharedString>, cx: &mut Context<Self>)
set_secret(secret: bool, cx: &mut Context<Self>)
set_max_length(max_length: Option<usize>, cx: &mut Context<Self>)
set_bare(bare: bool, cx: &mut Context<Self>)
set_value(value: impl Into<SharedString>, cx: &mut Context<Self>)
set_placeholder(placeholder: impl Into<SharedString>, cx: &mut Context<Self>)
set_text_quietly(value: impl Into<SharedString>, cx: &mut Context<Self>)
set_disabled(disabled: bool, cx: &mut Context<Self>)
set_read_only(read_only: bool, cx: &mut Context<Self>)
set_required(required: bool, cx: &mut Context<Self>)
set_control_size(size: ControlSize, cx: &mut Context<Self>)
set_invalid(invalid: bool, cx: &mut Context<Self>)
Queries
Only answer; they change nothing.
value() -> &SharedString
is_empty() -> bool
is_disabled() -> bool
is_secret() -> bool
selected_range() -> Range<usize>
cursor_offset() -> usize
Reports
The variants of the event it emits. It never applies the change itself.
- Change
- Submit
- Cancel
- BackspaceAtStart
- Focus
- Blur
Example · input
fn input(window: &mut Window, cx: &mut App) -> AnyElement {
ensure_inputs(window, cx);
let inputs = cx.global::<SceneInputs>();
let (token, disabled, invalid, provider) = (
inputs.token.clone(),
inputs.disabled.clone(),
inputs.invalid.clone(),
inputs.provider.clone(),
);
let theme = cx.theme().clone();
// A field with no label is a box. Each one is put where a product would
// put it: under the words that say what it is for, and above the sentence
// that says what is wrong with it.
div()
.flex()
.flex_col()
.gap(px(theme.space(Space::Md)))
.p(px(theme.space(Space::Lg)))
.w(px(360.0))
.child(
FormField::new("scene.input.token.field", "API token")
.control("scene.input.token")
.description("Kept on this machine, never published.")
.child(token),
)
.child(
FormField::new("scene.input.disabled.field", "Workspace id")
.control("scene.input.disabled")
.description("Set when the workspace was created.")
.child(disabled),
)
.child(
FormField::new("scene.input.invalid.field", "Email")
.control("scene.input.invalid")
.required(true)
.error("This is not an address anyone can be reached at.")
.child(invalid),
)
.child(
FormField::new("scene.input.provider.field", "Provider")
.control("scene.input.provider")
.description("Where a run is sent.")
.child(provider),
)
.child(caption(&theme, "Focused chrome fixture · not an editor"))
.child(
crate::controls::field::field_shell(
&theme,
ControlSize::Md,
crate::controls::field::FieldState::default().focused(true),
)
.child("Halo retains the inner highlight")
.semantic_in(cx, NodeSpec::new("scene.input.focused-chrome", Role::Group)),
)
.into_any_element()
}