Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
Three-state choices

Русская версия · CheckBox · RadioGroup

Use ui::threeState when unchecked, checked and mixed are all meaningful, for example an aggregate selection. For a Boolean choice use CheckBox; for mutually exclusive alternatives use RadioGroup.

A complete application

The example starts mixed. Space or Enter cycles the value; F10 exits and the standard runner reports errors and restores the terminal.

The three-state example starts with a mixed selection.
// Copyright (c) 2026 ttldtor.
// SPDX-License-Identifier: BSL-1.0
#include <portals/ui.hpp>
int main() {
using namespace portals;
return ui::scene(ui::vbox(ui::label("CheckBox | Space changes state | F10 quit"),
ui::threeState("Selection", CheckState::MIXED)))
| ui::onKey(key::F10, ui::quit)
| ui::runApp();
}
Public Portals API.
Definition action.hpp:8
@ MIXED
Partial selection, displayed independently of color.
Definition controls.hpp:269

Build portals_check_state_example with PORTALS_BUILD_EXAMPLES=ON and run it in a terminal. See build setup and package setup.

Value, input and resources

ui::threeState("Selection", CheckState::MIXED) creates scene-owned state. Omitting the initial state uses context defaults, otherwise unchecked; a ManagedState<CheckState> overload shares a scene model. The fixed cycle is UNCHECKED → CHECKED → MIXED → UNCHECKED. Unmodified Enter, Space and left mouse press activate. Release, movement, paste and modified gestures do not; hidden or disabled ancestry blocks activation. There is no separate read-only checkbox mode.

A ui::Ref<ThreeState> observes the mounted control. Typed change callbacks and ui::onChange observe successful user changes; external model writes do not invoke the business callback. A committed value is not undone by rejected observer notifications. The scene owns the widget and binding, while Ref is observing. ui::checkbox(...).threeState() is an alternative with natural type CheckBox, demonstrated in CheckBox. See three-state binding for receipts and aggregate helpers.

Resources register ThreeState; retrieve a named instance using scene.get<ThreeState>(...). See scene resources for syntax and typed lookup.

Styling reference

The natural type is ThreeState with base type CheckBox, so either selector matches. Its caption and fixed [ ] , [x] , [-] markers share normal/focused/disabled style; disabled takes priority. Checked and mixed are values, not :selected paint states. Header and caret are not painted; PSS cannot replace marker strings or color them independently.

Property Values and effect
foreground, background #RRGGBB; foreground and fill
bold, italic, underline true or false; explicit false overrides a lower layer
width, height Nonnegative cells, auto, fit-content, flex(positive weight) in runtime PSS
min-width, max-width, min-height, max-height Nonnegative cell bounds; only min-width also works in compile-time PSS

Size declarations cannot depend on a state or :read-only; conflicting bounds reject the update and retain the last valid style and geometry. See layout. Manual ControlStyle uses terminal-default colors, normal text, bold focus and italic disabled text. Theme and PSS rules override individual fields; unspecified fields retain lower-layer values. See the cascade.

ThreeState { min-width: 12; }
ThreeState:focused { foreground: #ffffff; background: #245070; }
ThreeState:disabled { italic: true; }

See portals::ThreeState, CheckState, ui::threeState and basic styling.