Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
spin_box.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4#include <portals/line_edit.hpp>
5#include <portals/numeric.hpp>
6
7namespace portals {
14
18class SpinBox : public Row {
19public:
24 : Row({}, policy), skin_(skin) {
25 }
26
28 Node<LineEdit> editor() const noexcept {
29 return editor_;
30 }
31
33 SpinBoxSkin skin() const noexcept {
34 return skin_;
35 }
36
38 std::expected<CellSize, TreeError> measure(CellSize available) override {
39 if (skin_ != SpinBoxSkin::STANDARD && skin_ != SpinBoxSkin::COMPACT && skin_ != SpinBoxSkin::ARROWS) {
40 return std::unexpected(TreeError::INVALID_ARGUMENT);
41 }
42
43 return Row::measure(available);
44 }
45
46private:
47 friend class ManagedScene;
48 SpinBoxSkin skin_;
49 Node<LineEdit> editor_;
50};
51
57 std::optional<PropertyUpdate<NumericValue>> commit;
58};
59
62public:
65 SpinBoxBinding(SpinBoxBinding &&other) noexcept;
68 SpinBoxBinding(const SpinBoxBinding &) = delete;
69 SpinBoxBinding &operator=(const SpinBoxBinding &) = delete;
71 std::expected<void, TreeError> sync(Node<Widget> focused);
75 std::expected<SpinBoxResult, TreeError> setValue(double value);
76
77private:
78 friend class ManagedScene;
79 struct State;
80 friend std::expected<SpinBoxBinding, TreeError> bindSpinBox(WidgetTree &, EventRouter &, Node<LineEdit>, Node<Button>,
81 Node<Button>, std::shared_ptr<Property<NumericValue>>,
82 std::uint64_t, std::function<void(SpinBoxResult)>,
84 explicit SpinBoxBinding(std::shared_ptr<State> state);
85 std::shared_ptr<LineEditBinding> editorBinding() const;
86 bool ownsPart(Node<Widget> node) const noexcept;
87 void retain(std::shared_ptr<void> record);
88 std::shared_ptr<void> retained() const;
89 std::shared_ptr<State> state_;
90};
91
101std::expected<SpinBoxBinding, TreeError> bindSpinBox(WidgetTree &tree, EventRouter &router, Node<LineEdit> editor,
102 Node<Button> decrease, Node<Button> increase,
103 std::shared_ptr<Property<NumericValue>> model,
104 std::uint64_t pageSteps, std::function<void(SpinBoxResult)> result,
105 LineEditEvents events = {});
106} // namespace portals
UI-owned focus and synchronous bubbling over an existing WidgetTree. Tree and Scheduler must outlive ...
Definition action.hpp:169
Additive lifecycle owner over one existing Application subtree. UI affine and nonmovable....
Definition managed.hpp:530
Copyable typed observer; never owns or exposes an unchecked widget pointer.
Definition widget.hpp:92
UI-owned typed value with node-scoped observers and explicit partial delivery. WidgetTree and its Sch...
Definition property.hpp:62
Row(LinearOptions options={}, SizePolicy policy={})
Own settings and policies.
std::expected< SpinBoxResult, TreeError > setValue(double value)
~SpinBoxBinding()
Disconnect future input/data delivery; admitted callbacks retain their owners.
SpinBoxBinding(SpinBoxBinding &&other) noexcept
SpinBoxBinding & operator=(SpinBoxBinding &&other) noexcept
std::expected< void, TreeError > sync(Node< Widget > focused)
friend std::expected< SpinBoxBinding, TreeError > bindSpinBox(WidgetTree &, EventRouter &, Node< LineEdit >, Node< Button >, Node< Button >, std::shared_ptr< Property< NumericValue > >, std::uint64_t, std::function< void(SpinBoxResult)>, LineEditEvents)
Bind pre-mounted editor/decrement/increment children of one SpinBox.
Node< LineEdit > editor() const noexcept
Definition spin_box.hpp:28
SpinBoxSkin skin() const noexcept
Definition spin_box.hpp:33
std::expected< CellSize, TreeError > measure(CellSize available) override
Definition spin_box.hpp:38
SpinBox(SizePolicy policy=DEFAULT_CONTENT_POLICY, SpinBoxSkin skin=SpinBoxSkin::STANDARD)
Definition spin_box.hpp:23
Exclusive parent/child ownership on Scheduler's UI thread. Scheduler must outlive this object....
Definition widget.hpp:179
virtual std::expected< CellSize, TreeError > measure(CellSize available)
Default desired size is empty.
Public Portals API.
Definition action.hpp:8
SpinBoxSkin
Immutable presentation of the two numeric step buttons.
Definition spin_box.hpp:9
@ ARROWS
Bracketed down/up arrows with ASCII width fallback.
Definition spin_box.hpp:12
@ STANDARD
Five-cell bracketed minus/plus buttons; the default.
Definition spin_box.hpp:10
@ COMPACT
Legacy one-cell minus/plus buttons.
Definition spin_box.hpp:11
constexpr SizePolicy DEFAULT_CONTENT_POLICY
Intrinsic content on both axes; explicit policies remain authoritative.
Definition layout.hpp:44
std::expected< SpinBoxBinding, TreeError > bindSpinBox(WidgetTree &tree, EventRouter &router, Node< LineEdit > editor, Node< Button > decrease, Node< Button > increase, std::shared_ptr< Property< NumericValue > > model, std::uint64_t pageSteps, std::function< void(SpinBoxResult)> result, LineEditEvents events={})
Bind pre-mounted editor/decrement/increment children of one SpinBox.
@ INVALID_ARGUMENT
An option, enum value or operation argument is invalid.
Definition widget_types.hpp:27
An owning available extent in terminal columns/rows.
Definition geometry.hpp:44
Optional owning UI callbacks delivered after the legacy result, while the node remains live....
Definition line_edit.hpp:149
Exact editing or confirmation result delivered on the UI thread.
Definition line_edit.hpp:104
Owning independent policies for width and height.
Definition layout.hpp:35
Existing text editing outcome and its exact numeric receipt, if publication occurred....
Definition spin_box.hpp:55
std::optional< PropertyUpdate< NumericValue > > commit
Exact numeric set receipt; never a later snapshot.
Definition spin_box.hpp:57
LineEditResult editing
Owning text/history outcome, including validation/conflict and technical errors.
Definition spin_box.hpp:56