|
Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
|
Русская версия · Models · LineEdit · Live suggestions
Use ComboBox for an editable draft with a choice from a source. Use DropDown for a read-only main display. Both accept immutable models and load visible popup rows on workers through the existing virtual-list provider.
The complete Shipping desk application also demonstrates list navigation, filtered selection and dark/light palette changes:
These images show a captured native application rendered by VHS. Appearance can vary with terminal fonts and capabilities.
Type a city, press Down to open the popup and Enter to accept a highlighted row. Escape dismisses the popup. F10 exits through the ordinary runner. The factory copies the small literal source; references and callbacks require no manual binding-token storage.
Build guide_choices in the standalone guide project, or build portals_choices_example with examples enabled for the larger form. The build guide describes the native presets.
To build the standalone guide from the repository root:
ComboBox is appropriate when a user may type a draft as well as accept a catalog row. Its Ref<ComboBox>::text() reads the draft, while selection() and onSelect describe the accepted row. Editing text does not itself select a row. The complete program above demonstrates this control.
DropDown is appropriate when the main display must remain read-only. Its popup has a separate search editor by default (ComboBoxConfig::searchable); searchable=false removes that editor. Use Ref<DropDown> and onSelect to observe accepted choices. The complete Shipping desk program, included below, demonstrates delivery and palette DropDowns as well as the ComboBox. Both examples accept a popup row by keyboard or pointer; Escape dismisses it.
Both use ComboBoxConfig: PREFIX search, 32 browse rows per request, eight visible popup rows, maximum popup width 60 cells, and no initial ordinal by default. See configuration and factories and choice API. Source and search budgets, selection lifetime and loaded-scene restrictions are detailed below.
ComboBox and DropDown use SearchStrategy::PREFIX by default: matching is case-insensitive and accent-insensitive over the normalized label or a whitespace token. With the catalog below, Pra shows only Prague; Bratislava, Paris and São Paulo are excluded. Pr2 has no exact prefix match.
Use .fuzzy() when an application should tolerate one insertion, deletion or substitution from three normalized query graphemes. This complete example also shows Bratislava for Pra:
Use .prefix() to restore strict matching after a fuzzy setting:
The pipe forms are recipe | ui::fuzzy() and recipe | ui::prefix(); .fuzzy(false) also selects PREFIX. These modifiers override only the strategy, retaining every configured worker budget. ComboBoxConfig::search.strategy remains available for explicit configuration. Sparse .settings() patches and fluent modifiers follow the existing last-value rule for the same leaf.
An explicit ComboBoxConfig::search aggregate uses SearchOptions defaults. When supplying only a budget there, append .prefix() to keep strict matching. General SearchOptions and live suggestions retain their FUZZY_PREFIX default.
The main editor and accepted selection represent different state:
combo.text() exposes the standard editable text property. combo.editor() provides advanced access to its LineEdit. A DropDown's main display is read-only; its optional popup search field has its own transient query. Closing a ComboBox popup preserves its main draft and editor history.
A source can be a managed model, an owning immutable snapshot, or a RowCollection<T> including its checked construction result. For example, given an existing model of City rows, the projection selects the displayed field:
The projection runs on a worker and must read immutable data safely. Keep UI references and thread-affine services out of that projection. Source changes invalidate incompatible accepted rows and pending completions while retaining visible draft text. Original source ordinals remain distinct from ranked-search positions.
For startup selection, set ComboBoxConfig::initial. A programmatic select() over a managed model requires the first ordinary preparation cycle to have pinned that model. runApp drives the normal preparation cycles; low-level hosts call ManagedScene::prepare themselves. Scene::prepareChecked() mounts the scene but does not perform this runtime model preparation.
A projection can also return an owning std::string, for example from std::format. The worker pins that result while preparing display text. View-returning projections borrow the immutable source snapshot. Row-byte and scratch budgets bound library-owned storage; allocations made inside an application projection before it returns remain the application's responsibility.
The ordinary browse list can navigate the complete source using bounded visible requests. A nonempty search query uses the bounded indexed-search path described in live suggestions; its top-K limit is a search-result limit.
open(), select(index) and select(selection) return checked admission results. Popup creation, layout and source-row resolution complete through existing UI/worker phases. An admitted request has not necessarily opened a popup or accepted a row yet. opened() observes the committed state; onSelect reports the eventual accepted selection. Newest intent and exact source identities fence stale work.
select(index) uses a zero-based source ordinal captured for that request. select(selection) schedules a still-current owning selection through the same deferred command path, including calls from button callbacks. dismiss() also cancels a pending open. Closing or removing the owner retires its transient popup and popup-owned result models. An explicit programmatic selection can resolve its one requested row while the popup is closed.
Provider and transport failures enter the existing typed diagnostics and runner error policy. The optional failure callback can provide immediate application feedback. Recoverable action diagnostics follow the runner contract.
Use natural ComboBox and DropDown selectors and the existing theme/style layers. The Shipping desk form retains its application rules while changing the base theme. Popup placement flips or clamps to the terminal viewport.
The scene paints the theme background across the viewport, including layout gaps and unused space. Changing the palette updates this background together with the controls. No additional background widget is required. An application rule such as Scene { background: #182028; } overrides the theme background and remains in effect when the theme changes.
ComboBoxConfig separates the visible popup height, width, visible-range budget and search limits. Defaults include eight visible rows, a 60-cell maximum popup width, a 32-row browse-request bound and the existing indexed-search budgets with PREFIX matching. Tune these only when the application needs different limits; invalid settings report checked errors.
The scene supplies the existing overlay host automatically when required and reuses a compatible explicit host. A popup occupies its normal layer/model resources while open and releases them when dismissed. Closed controls perform no autonomous browse or search. The main retained controls and their draft state remain in the tree.
The main controls use the natural PSS types ComboBox and DropDown. Their children have .choice-editor and .choice-trigger classes. The popup uses Dialog.choice-popup, with .choice-search, .choice-list and .choice-completion children. Existing LineEdit, Button, VirtualList and Dialog default styles supply the skin; no per-control registration is needed.
The resource registry recognizes ComboBox and DropDown and their ordinary control settings, including text, placeholder and searchStrategy=PREFIX or searchStrategy=FUZZY_PREFIX. Source models and callbacks remain C++ declarations. To supply a catalog from a resource, register a typed factory with SceneResourceOptions::control<ComboBox> or control<DropDown> and return the corresponding recipe with .settings(arguments.settings). The scene-loading guide shows the registration and lazy runner error path.
Typed factories and aliases advertise their popup-host requirement without running application callbacks twice. An opaque Widget factory that conditionally returns a choice must use an explicit compatible ui::overlayHost.
Protected PASSWORD and NO_ECHO editor modes are rejected with INVALID_ARGUMENT before choice references publish: catalog search must not send protected editor contents to a worker projection.
ComboBox and DropDown are composition roots. Their painted children have these selectors: LineEdit.choice-editor, Button.choice-trigger, LineEdit.choice-search, VirtualList.choice-list, VirtualList.choice-completion and Dialog.choice-popup. The search editor is shown for a searchable DropDown; lists are used in the popup. Style each child separately. The editor paints normal/focused/disabled, selected and caret; the trigger paints normal/focused/disabled; list rows also use selected. See LineEdit and virtual lists for their details. The trigger caption v is fixed; PSS does not replace it. Editor manual defaults use ComboBoxConfig::editor, while the trigger starts from ControlStyle{}.
The common paint properties apply to each painted target:
| Property | Value |
|---|---|
| foreground | #RRGGBB text/ink color |
| background | #RRGGBB fill color |
| bold | true or false |
| italic | true or false |
| underline | true or false |
Manual ControlStyle defaults use terminal colors, normal text, bold focus and italic disabled text. Theme and PSS declarations override individual manual fields; unspecified fields retain lower-layer values, including explicit false. A selector without a state supplies all variants. See cascade and selectors and styles.
Layout properties width and height accept nonnegative cell counts, auto, fit-content, or flex(positive weight); min-width, max-width, min-height, and max-height accept nonnegative cell counts. They require selectors without state or :read-only; Except for min-width, these size declarations are runtime PSS only. Conflicting widget bounds reject the update and retain the previous style and geometry; constraints and recipe precedence are explained in layout. These affect allocation, not the glyphs themselves.