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

Русская версия · Key help · Layout

Use ui::statusBar to arrange ordinary status sections in a horizontal bar. It fills its allocation and composes labels, spacers and interactive children; it is not a timed notification. Use a toast when a message should be temporary.

A complete application

This larger example combines a status label and key hints with a real help view. F2 changes Ready to Saved, F1 opens help, Escape closes it and F10 exits. The standard runner reports errors and restores the terminal.

Status desk with Saved, UTF-8 and key hints in the bottom bar.
// Copyright (c) 2026 ttldtor.
// SPDX-License-Identifier: BSL-1.0
#include <portals/ui.hpp>
#include <portals/ui_style.hpp>
int main() {
using namespace portals;
// clang-format off
auto scene = ui::scene(ui::vbox(
ui::label("Status desk | F2 updates | F1 help | F10 quit"),
ui::button("Mark saved").onClick([status] { status.text() = "Saved"; }),
ui::helpView(help),
ui::spacer(),
ui::statusBar({.gap = 1},
ui::label(status, "Ready"), ui::spacer(), ui::label("UTF-8"),
ui::keyHints(help).maxWidth(36))));
scene.onKey(ui::press("F2"), ui::keyInfo("Mark saved"), [status] { status.text() = "Saved"; });
scene.onKey(ui::press("F1"), ui::keyInfo("Open help"), [help] { return help.open(); });
scene.onKey(ui::press("Escape"), ui::keyInfo("Close help").scope(help), [help] { return help.close(); });
scene.onKey(ui::press("F10"), ui::keyInfo("Quit"), [] { ui::quit(); });
return scene
| ui::theme(nordTheme())
| ui::runApp();
// clang-format on
}
Typed Widget observation; explicit composite specializations reuse their existing weak facades.
Definition ui_ref.hpp:761
std::expected< void, ManagedError > close(std::source_location origin=std::source_location::current()) const
Definition ui_ref.hpp:1020
TextProperty text(TextResolver resolver={}, std::source_location origin=std::source_location::current()) const
Definition ui_ref.hpp:1968
std::expected< void, ManagedError > open(std::source_location origin=std::source_location::current()) const
Definition ui_ref.hpp:1013
Scene & onKey(KeySelection selection, Info info, Callback callback, std::source_location origin=std::source_location::current()) &
Definition ui_scene.hpp:531
Public Portals API.
Definition action.hpp:8
StyleSheet nordTheme()

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

Layout, references and resources

ui::statusBar({.gap = 1}, children...) uses LinearOptions: gap inserts one cell between adjacent child sections, so their text and controls do not touch. The default gap and padding are zero; main alignment is START, cross alignment is STRETCH and overflow is CLIP. The default SizePolicy fills available width and requests one fixed row. A spacer pushes later sections away; under shortage later shrinkable children yield first down to their minima and remaining overflow is clipped. The parent determines placement; the bar does not dock itself.

A ui::Ref<StatusBar> observes the container for geometry, visibility and removal; it has no text property or timer. Give a child ui::Ref<Label> to update text, as in the example. The scene owns the bar and children. The bar is not a focus stop and has no own keyboard or mouse action; interactive children keep theirs. ui::keyHints(help) reflects the bound HelpView; see key help.

Both resource formats support a bar with children, basic size/flex and gap, for example StatusBar#footer { gap=1 Label#status { text="Ready" } Spacer{} }. Get the children with scene.get<Label>("status") and the bar with scene.get<StatusBar>("footer"). Use the configuration format for min/max, padding and linear alignment. Legacy resources with ControlContext defaults or definitions can reject min/max literals with DUPLICATE_PROPERTY; use the configuration format. See resource details.

Styling reference

The natural selector is StatusBar. It paints its whole allocation with normal or disabled style, disabled when ineligible. It does not paint focused, selected, header or caret states. Child labels and buttons resolve their own styles; a bar foreground does not automatically style their text. The manual ControlStyle supplies normal and disabled defaults; there are no bar-specific 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.

StatusBar { background: #182028; height: 1; }
StatusBar:disabled { background: #303030; }
Label.status { foreground: #dce1e8; }

Here height: 1 requests a one-row outer allocation for this footer; it is not the horizontal gap. The default bar policy also requests one fixed row, and the parent layout determines placement. Assign .classes("status") to the intended label for the last rule. See portals::StatusBar, LinearOptions, ui::statusBar, and basic styling.