Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
Loading...
Searching...
No Matches
view_adapter.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "aria/abi/export.hpp"
4#include "aria/detail/typed_signal.hpp"
6
7#include <cstdint>
8#include <functional>
9#include <memory>
10#include <string>
11#include <string_view>
12
13namespace aria::binding {
14
29public:
31 IView(const IView&) = delete;
32 IView& operator=(const IView&) = delete;
33 IView(IView&&) = delete;
34 IView& operator=(IView&&) = delete;
35
36 virtual ~IView();
37
38 [[nodiscard]] virtual std::string_view kind() const noexcept = 0;
39
44 [[nodiscard]] Subscription on_destroy(std::function<void()> cb) const;
45
46protected:
61 void fire_destroy_() noexcept;
62
63private:
64 struct Impl;
65 // RAII pImpl (TypedSignal lives inside, view_adapter.cpp). `mutable`
66 // because `on_destroy` is const but mutates the signal. C4251 on the
67 // unique_ptr member is a false positive for an incomplete opaque
68 // pointee consumed only via this module's API.
69#ifdef _MSC_VER
70# pragma warning(push)
71# pragma warning(disable: 4251)
72#endif
73 mutable std::unique_ptr<Impl> impl_;
74#ifdef _MSC_VER
75# pragma warning(pop)
76#endif
77};
78
81public:
82 virtual ~IViewAdapter();
83
84 [[nodiscard]] virtual std::string_view platform_name() const noexcept = 0;
85
86 // ── Text controls (label, line edit) ───────────────────────────
87 virtual void set_text(IView& v, std::string_view text) = 0;
88 [[nodiscard]] virtual std::string get_text(IView& v) = 0;
90 std::function<void(std::string_view)> cb) = 0;
91
92 // ── Boolean controls (checkbox, switch) ────────────────────────
93 virtual void set_bool(IView& v, bool value) = 0;
94 [[nodiscard]] virtual bool get_bool(IView& v) = 0;
96 std::function<void(bool)> cb) = 0;
97
98 // ── Numeric controls (slider, spinbox, progress bar) ───────────
99 //
100 // `int` / `double` are the canonical fast paths. The wider /
101 // narrower variants below exist for real workloads that hit their
102 // limits:
103 // * int64_t — timestamps (ms since epoch), IDs, byte counts
104 // that can exceed 2^31.
105 // * uint64_t — raw handles, hash digests, non-negative counters
106 // that need the full 64-bit range.
107 // * float — platform controls that speak float natively
108 // (CALayer, UISlider, Metal uniforms) — avoids the
109 // implicit double↔float round-trip on every poll.
110 //
111 // Adapters whose native widget has no direct equivalent for a
112 // wider/narrower type are welcome to implement the wider variant
113 // by delegating to the narrower one with a range-check; see
114 // `FakeAdapter` for the default pattern.
115
116 virtual void set_int(IView& v, int value) = 0;
117 [[nodiscard]] virtual int get_int(IView& v) = 0;
119 std::function<void(int)> cb) = 0;
120
121 virtual void set_int64(IView& v, std::int64_t value) = 0;
122 [[nodiscard]] virtual std::int64_t get_int64(IView& v) = 0;
124 std::function<void(std::int64_t)> cb) = 0;
125
126 virtual void set_uint64(IView& v, std::uint64_t value) = 0;
127 [[nodiscard]] virtual std::uint64_t get_uint64(IView& v) = 0;
129 std::function<void(std::uint64_t)> cb) = 0;
130
131 virtual void set_float(IView& v, float value) = 0;
132 [[nodiscard]] virtual float get_float(IView& v) = 0;
134 std::function<void(float)> cb) = 0;
135
136 virtual void set_double(IView& v, double value) = 0;
137 [[nodiscard]] virtual double get_double(IView& v) = 0;
139 std::function<void(double)> cb) = 0;
140
141 // ── Visibility / enabled state ─────────────────────────────────
142 virtual void set_visible(IView& v, bool visible) = 0;
143 virtual void set_enabled(IView& v, bool enabled) = 0;
144
145 // ── Click events ───────────────────────────────────────────────
146 virtual Subscription on_click(IView& v, std::function<void()> cb) = 0;
147};
148
149} // namespace aria::binding
RAII handle to a single subscription.
Definition subscription.hpp:44
Abstract platform adapter — knows how to read/write/observe widgets.
Definition view_adapter.hpp:80
virtual Subscription on_int_changed(IView &v, std::function< void(int)> cb)=0
virtual void set_visible(IView &v, bool visible)=0
virtual double get_double(IView &v)=0
virtual std::uint64_t get_uint64(IView &v)=0
virtual float get_float(IView &v)=0
virtual Subscription on_float_changed(IView &v, std::function< void(float)> cb)=0
virtual std::int64_t get_int64(IView &v)=0
virtual void set_uint64(IView &v, std::uint64_t value)=0
virtual void set_float(IView &v, float value)=0
virtual Subscription on_bool_changed(IView &v, std::function< void(bool)> cb)=0
virtual Subscription on_double_changed(IView &v, std::function< void(double)> cb)=0
virtual void set_double(IView &v, double value)=0
virtual std::string get_text(IView &v)=0
virtual std::string_view platform_name() const noexcept=0
virtual bool get_bool(IView &v)=0
virtual void set_bool(IView &v, bool value)=0
virtual void set_int(IView &v, int value)=0
virtual Subscription on_int64_changed(IView &v, std::function< void(std::int64_t)> cb)=0
virtual void set_text(IView &v, std::string_view text)=0
virtual void set_enabled(IView &v, bool enabled)=0
virtual int get_int(IView &v)=0
virtual Subscription on_text_changed(IView &v, std::function< void(std::string_view)> cb)=0
virtual Subscription on_uint64_changed(IView &v, std::function< void(std::uint64_t)> cb)=0
virtual void set_int64(IView &v, std::int64_t value)=0
virtual Subscription on_click(IView &v, std::function< void()> cb)=0
Abstract platform widget reference.
Definition view_adapter.hpp:28
Subscription on_destroy(std::function< void()> cb) const
Subscribe to "this view is about to be destroyed".
IView(const IView &)=delete
IView & operator=(const IView &)=delete
void fire_destroy_() noexcept
Invoked by ~IView() to fan out the notification — this is the last-resort trigger.
IView(IView &&)=delete
virtual std::string_view kind() const noexcept=0
IView & operator=(IView &&)=delete
#define ARIA_BINDING_API
Definition export.hpp:39
Definition binding_engine.hpp:25
Definition validation_key.hpp:110