SearchField
Layer: molecule · Path:
src/molecules/search_field.rs· Exports:search_field::SearchField
A search input preset: a thin wrapper over InputGroup configured with a leading magnifier icon. Inspired by Unity’s Search Field.
Design
- Purpose / when to use — Any filter/search box. Use it instead of hand-wiring an
InputGroupwith a search glyph. - Anatomy — An
InputGroupbound to your buffer, withleading_icon(light::MAGNIFYING_GLASS)and an optional placeholder. - Tokens / layout consumed — inherited from
InputGroup. See tokens.
API
| Method | Effect |
|---|---|
SearchField::new(buf: &'a mut String) -> Self | Bind the search buffer. |
.placeholder(text: impl Into<String>) -> Self | Hint text shown when empty. |
.show(self, ui: &mut Ui) -> Response | Render; returns the field Response (.changed() on edit). |
Usage
#![allow(unused)]
fn main() {
use ouroboros_ui::molecules::SearchField;
// minimal
SearchField::new(&mut query).show(ui);
}
#![allow(unused)]
fn main() {
use ouroboros_ui::molecules::SearchField;
// with placeholder; react to edits
if SearchField::new(&mut query)
.placeholder("Search assets…")
.show(ui)
.changed()
{
refilter(&query);
}
}
Composition
Composes InputGroup only (which in turn composes Surface + Icon + the text editor). It never paints — see the guards.
Notes
- A deliberately minimal molecule — no id_source setter; the underlying
InputGroupfalls back to egui’s auto id. If you need a stable id or trailing clear button, useInputGroupdirectly. - The returned
Responseis the field’s;.changed()fires on edit.