Components / controls
SearchField view
A query field, a hit count, and next and previous.
A view survives a frame. Hold it in an Entity with cx.new(..) and reach it with .update(..).
use gpui_kit::controls::search::SearchField;
Reviewed in search-field.
Construct
new(ident: impl Into<Ident>, window: &mut Window, cx: &mut Context<Self>) -> Self
Options
Chain onto the value.
placeholder(placeholder: impl Into<SharedString>) -> Self
match_case(on: bool) -> Self
whole_word(on: bool) -> Self
Commands
Need a Context, so they need a view.
set_match_case(on: Option<bool>, cx: &mut Context<Self>)
set_whole_word(on: Option<bool>, cx: &mut Context<Self>)
set_count(count: HitCount, cx: &mut Context<Self>)
set_placeholder(placeholder: Option<SharedString>, cx: &mut Context<Self>)
set_control_size(size: ControlSize, cx: &mut Context<Self>)
set_query(text: impl Into<SharedString>, cx: &mut Context<Self>)
set_disabled(disabled: bool, cx: &mut Context<Self>)
Queries
Only answer; they change nothing.
count() -> &HitCount
query_text(cx: &App) -> SharedString
query_input() -> &Entity<TextInput>
is_disabled() -> bool
focus(window: &mut Window, cx: &mut Context<Self>)
Reports
The variants of the event it emits. It never applies the change itself.
- QueryChanged
- Next
- Previous
- Cancelled
- MatchCaseToggled
- WholeWordToggled
Example · search-field
fn search_field(window: &mut Window, cx: &mut App) -> AnyElement {
ensure_search(window, cx);
let field = cx.global::<SceneSearch>().field.clone();
let theme = cx.theme().clone();
let counting = cx.global::<SceneSearch>().counting.clone();
let none = cx.global::<SceneSearch>().none.clone();
let too_many = cx.global::<SceneSearch>().too_many.clone();
// The three counts a field must keep apart. No pointer position produces
// them at once, so each is stated.
stack(&theme)
.w(px(620.0))
.child(field)
.child(caption(
&theme,
"counting is not none, and too many is not a total",
))
.child(counting)
.child(none)
.child(too_many)
.child(caption(&theme, "the current hit is not the other hits"))
.child(
div().child(
HighlightedText::new(
"The transport reports what it did; the transport never decides.",
)
.id("scene.search.line")
.hits([4..13, 39..48])
.current(1),
),
)
.into_any_element()
}