Components / controls
SearchInput view
An in-content query with a magnifier and a clear action when nonempty.
A view survives a frame. Hold it in an Entity with cx.new(..) and reach it with .update(..).
use gpui_kit::controls::search::SearchInput;
Reviewed in search-input.
Construct
new(ident: impl Into<Ident>, window: &mut Window, cx: &mut Context<Self>) -> Self
Options
Chain onto the value.
name(name: impl Into<SharedString>) -> Self
placeholder(placeholder: impl Into<SharedString>) -> Self
Commands
Need a Context, so they need a view.
set_name(name: impl Into<SharedString>, cx: &mut Context<Self>)
set_placeholder(placeholder: impl Into<SharedString>, cx: &mut Context<Self>)
set_value(value: impl Into<SharedString>, cx: &mut Context<Self>)
set_presentation(name: Option<SharedString>, placeholder: Option<SharedString>, size: ControlSize, cx: &mut Context<Self>)
set_disabled(disabled: bool, cx: &mut Context<Self>)
Queries
Only answer; they change nothing.
value(cx: &App) -> SharedString
input() -> &Entity<TextInput>
is_disabled() -> bool
Reports
The variants of the event it emits. It never applies the change itself.
- Change
- Submit
- Cancel
- BackspaceAtStart
- Focus
- Blur
Example · search-input
fn search_input(window: &mut Window, cx: &mut App) -> AnyElement {
ensure_search(window, cx);
let theme = cx.theme().clone();
stack(&theme)
.w(px(480.0))
.child(caption(
&theme,
"Queries: Xs empty, Sm and Md populated, disabled",
))
.children(cx.global::<SceneSearch>().queries.clone())
.child(caption(
&theme,
"Last query: name ‘Search projects’, hint ‘Search…’",
))
.into_any_element()
}