5#include <portals/controls.hpp>
6#include <portals/text_value.hpp>
9#include <initializer_list>
14using SpinnerLabelResolver = std::function<std::expected<std::string, TextResourceError>(std::string_view)>;
32inline constexpr std::array<std::string_view, 12>
SPINNER_PRESET_NAMES{
"DOTS",
"LINE",
"BRAILLE",
"BAR_BOUNCE",
33 "ARC",
"CIRCLE",
"SQUARE",
"TRIANGLE",
34 "ARROW",
"BLOCKS",
"ELLIPSIS",
"PULSE"};
42 if (candidate.size() != name.size())
45 for (std::size_t j = 0; j < name.size(); ++j) {
47 if (c >=
'a' && c <=
'z')
48 c =
static_cast<char>(c -
'a' +
'A');
51 if (c != candidate[j]) {
64inline std::string spinnerFrames(std::initializer_list<std::string_view> values) {
67 for (
const auto value : values) {
71 if (value.empty() || value.find_first_of(
"\r\n") != std::string_view::npos)
89 std::string
frames = std::string(0,
'\0');
157 friend class ManagedScene;
161 std::shared_ptr<detail::SpinnerState> state_;
An owning, invariant-preserving half-open cell rectangle.
Definition geometry.hpp:81
Copyable typed observer; never owns or exposes an unchecked widget pointer.
Definition widget.hpp:92
Borrowed synchronous command sink supplied by the frame owner. submit must consume commands immediate...
Definition widget_types.hpp:66
Retained indeterminate indicator using the receiving scene's existing scheduler. Construct through ui...
Definition spinner.hpp:115
friend std::expected< void, TreeError > setSpinner(WidgetTree &, Node< Spinner >, const SpinnerOptions &, SpinnerLabelResolver)
SpinnerOptions options() const
ComputedStyle styleDefaults() const override
std::expected< void, TreeError > paint(PaintContext &context) override
static std::expected< void, TreeError > validate(WidthPolicy width, SpinnerOptions options)
std::size_t frameIndex() const noexcept
std::expected< void, TreeError > preparation() const noexcept
std::expected< void, TreeError > arrange(CellRect local) override
friend std::expected< void, TreeError > setSpinnerActive(WidgetTree &, Node< Spinner >, bool)
~Spinner() override
Cancel this widget's timer on UI, without retaining the scene.
Spinner(WidthPolicy width={}, SpinnerOptions options={}, ControlStyle style={}, SizePolicy policy=DEFAULT_CONTENT_POLICY, SpinnerLabelResolver resolver={})
std::expected< CellSize, TreeError > measure(CellSize available) override
Owning literal bytes or a resource key, measured only at resolution.
Definition text_value.hpp:42
Public Portals API.
Definition action.hpp:8
@ FORWARD
Prefer the following item; an end boundary falls back to the preceding item.
Definition model_position.hpp:43
@ LINE
Join consecutive finite closes, leaving gaps disconnected.
Definition chart.hpp:50
@ BLOCKS
Shaded track and solid filled prefix.
Definition slider.hpp:15
std::function< std::expected< std::string, TextResourceError >(std::string_view)> SpinnerLabelResolver
Owning synchronous label lookup, invoked only while staging a configuration.
Definition spinner.hpp:14
std::expected< void, TreeError > setSpinnerActive(WidgetTree &tree, Node< Spinner > node, bool active)
constexpr std::array< std::string_view, 12 > SPINNER_PRESET_NAMES
Canonical names in SpinnerPreset ordinal order.
Definition spinner.hpp:32
@ SQUARE
Square brackets and inner spaces.
Definition frame.hpp:42
constexpr SizePolicy DEFAULT_CONTENT_POLICY
Intrinsic content on both axes; explicit policies remain authoritative.
Definition layout.hpp:44
SpinnerDirection
Traversal of the finite owning frame sequence.
Definition spinner.hpp:81
@ REVERSE
Decreasing frame indices with wraparound.
Definition spinner.hpp:83
@ FORWARD
Increasing frame indices with wraparound.
Definition spinner.hpp:82
LayoutAlign
Alignment; center assigns floor(free/2) before the child/group.
Definition layout.hpp:172
@ START
Place at the leading edge of the available space.
Definition layout.hpp:173
std::expected< void, TreeError > setSpinner(WidgetTree &tree, Node< Spinner > node, const SpinnerOptions &options, SpinnerLabelResolver resolver={})
SpinnerPreset
Original single-row indeterminate animation sequences.
Definition spinner.hpp:16
@ CIRCLE
Circle phases.
Definition spinner.hpp:22
@ ELLIPSIS
Growing dots.
Definition spinner.hpp:27
@ PULSE
Pulsing indicator.
Definition spinner.hpp:28
@ DOTS
Three positions, moving left to right.
Definition spinner.hpp:17
@ ARROW
Arrow directions.
Definition spinner.hpp:25
@ ARC
Rotating arc.
Definition spinner.hpp:21
@ BAR_BOUNCE
Five positions traversed in both directions.
Definition spinner.hpp:20
@ BRAILLE
Eight one-cell braille positions; ASCII fallback for incompatible widths.
Definition spinner.hpp:19
std::uint64_t SchedulerTime
Monotonic milliseconds; the clock must not move backwards.
Definition scheduler.hpp:18
SpinnerPreset spinnerPreset(std::string_view name) noexcept
Definition spinner.hpp:39
@ TRIANGLE
Triangle glyphs with the control width/glyph fallback.
Definition scrollbar_skin.hpp:34
TreeError
Checked tree failures; rejected operations never start the requested callback.
Definition widget_types.hpp:26
An owning available extent in terminal columns/rows.
Definition geometry.hpp:44
Owning resolved presentation; no actions or model state are encoded.
Definition style_types.hpp:169
Owning paint values; no theme engine or behavior is encoded here.
Definition controls.hpp:24
Owning single-row indicator configuration; no thread or timer is created by this value.
Definition spinner.hpp:87
std::size_t maxFrameBytes
Positive complete sequence source-byte budget.
Definition spinner.hpp:97
TextValue label
Owning label resolved before widget publication.
Definition spinner.hpp:95
bool reducedMotion
True selects static frame zero without a timer.
Definition spinner.hpp:94
std::size_t maxPaintCells
Positive allocated-area paint budget.
Definition spinner.hpp:99
LayoutAlign alignment
START/CENTER/END alignment of indicator and label.
Definition spinner.hpp:92
bool active
False pauses animation without polling.
Definition spinner.hpp:93
SpinnerPreset preset
Sequence used when frames is empty.
Definition spinner.hpp:88
SpinnerDirection direction
Finite sequence traversal order.
Definition spinner.hpp:91
std::size_t maxFrames
Positive maximum complete frame count.
Definition spinner.hpp:96
~SpinnerOptions()=default
Preserve fallible owning copies, including MSVC Debug iterator proxy allocations.
SchedulerTime interval
Positive monotonic milliseconds between frames.
Definition spinner.hpp:90
std::size_t maxFrameCells
Positive maximum cells per frame.
Definition spinner.hpp:98
std::string frames
Custom UTF-8 frames separated by LF; no empty frames.
Definition spinner.hpp:89
Owning deterministic width policy; no font or terminal matching promise.
Definition text.hpp:42