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

Русская версия · Basic controls · Text and state

Use ui::label for a one-line caption or changing status. It displays text and does not accept activation; use a button for an action and a line editor for input.

A complete application

This larger checkbox example updates the Label named status after each user change. Space or Enter changes the checkbox; F10 or Ctrl+C exits. The standard runner reports errors and restores the terminal.

Checkbox example: an unchecked selection and its status label.
// Copyright (c) 2026 ttldtor.
// SPDX-License-Identifier: BSL-1.0
#include <portals/ui.hpp>
int main() {
using namespace portals;
ui::Ref<CheckBox> selection;
// clang-format off
auto scene = ui::scene(ui::vbox(
ui::checkbox(selection, "Selection").threeState(),
ui::label(status, "Unchecked")));
return scene
| ui::onChange(selection, [status](CheckState value) {
switch (value) {
status.text() = "Unchecked";
break;
status.text() = "Checked";
break;
status.text() = "Mixed";
break;
}
})
| ui::onKey("F10 | Ctrl+C", ui::quit)
| ui::runApp();
// clang-format on
}
Typed Widget observation; explicit composite specializations reuse their existing weak facades.
Definition ui_ref.hpp:761
TextProperty text(TextResolver resolver={}, std::source_location origin=std::source_location::current()) const
Definition ui_ref.hpp:1968
Public Portals API.
Definition action.hpp:8
CheckState
Explicit checkbox value; MIXED describes an aggregate or an opt-in user choice.
Definition controls.hpp:266
@ MIXED
Partial selection, displayed independently of color.
Definition controls.hpp:269
@ CHECKED
Complete selection.
Definition controls.hpp:268
@ UNCHECKED
No selection.
Definition controls.hpp:267

Build portals_docs_check_change with PORTALS_BUILD_TESTS=ON and run the resulting executable in a terminal. See build setup and installed package setup.

Text, references and resources

ui::label("Ready") copies the caption; ui::label(status, "Ready") publishes an observing ui::Ref<Label> after successful mount. Set status.text() = "Saved" between frames to change it through the scene's diagnostic boundary. A label may also observe managed string state or a text source; text references describe supported operations. The scene owns the widget; a Ref does not extend its lifetime. Labels are not focus stops by default and have no activation, keyboard or mouse action of their own.

Scene resources support Label#status { "Ready" }; scene.get<Label>("status") observes the loaded label. See scene resources for both formats and text resolution.

Styling reference

The natural selector is Label. It paints normal, focused and disabled styles, with disabled first; ordinary labels do not receive focus by default. It does not paint selected, header or caret. Caption and allocated background use the same resolved style; there are no label-specific PSS glyph properties.

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.

Label#status { foreground: #dce1e8; min-width: 12; }
Label#status:disabled { italic: true; }

See portals::Label, portals::ControlStyle, portals::ui::label and portals::ui::Ref for signatures and basic controls for shared behavior.