Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
Loading...
Searching...
No Matches
AppKitAdapter.hpp
Go to the documentation of this file.
1#pragma once
2
33
35#include "aria/subscription.hpp"
36
37#import <Cocoa/Cocoa.h>
38
39#include <cstdint>
40#include <functional>
41#include <memory>
42#include <stdexcept>
43#include <string>
44#include <string_view>
45
46// ─── ObjC bridging targets (defined in AppKitAdapter.mm) ────────────────
47
49@interface AriaClickTarget : NSObject
50- (instancetype)initWithCallback:(std::function<void()>)cb;
51- (void)fire:(id)sender;
52@end
53
55@interface AriaToggleTarget : NSObject
56- (instancetype)initWithCallback:(std::function<void(bool)>)cb;
57- (void)fire:(id)sender;
58@end
59
61@interface AriaStepperTarget : NSObject
62- (instancetype)initWithCallback:(std::function<void(int)>)cb;
63- (void)fire:(id)sender;
64@end
65
67@interface AriaSliderTarget : NSObject
68- (instancetype)initWithCallback:(std::function<void(double)>)cb;
69- (void)fire:(id)sender;
70@end
71
73@interface AriaTextDelegate : NSObject <NSTextFieldDelegate>
74- (instancetype)initWithCallback:(std::function<void(std::string_view)>)cb;
75@end
76
78
79// ─── View wrapper ───────────────────────────────────────────────────────
80
82public:
83 explicit AppKitView(NSView* view) : view_(view) {}
84 ~AppKitView() override {
85 // Fire while the NSView* is still alive; handlers (BindingEngine)
86 // can erase the per-view bucket before our storage goes away.
88 }
89
90 [[nodiscard]] std::string_view kind() const noexcept override { return "appkit"; }
91 [[nodiscard]] NSView* native() const noexcept { return view_; }
92
93 template<class T>
94 [[nodiscard]] T* as() const { return static_cast<T*>(view_); }
95
96private:
97 NSView* __strong view_; // ARC: retain
98};
99
100// ─── Adapter ────────────────────────────────────────────────────────────
101
103public:
105 ~AppKitAdapter() override;
106
107 AppKitAdapter(const AppKitAdapter&) = delete;
109
110 [[nodiscard]] std::string_view platform_name() const noexcept override {
111 return "appkit";
112 }
113
114 // ── Handle → IView ──────────────────────────────────────────────────
139 [[nodiscard]] AppKitView& view_for(NSView* view);
140
148 void release_view(NSView* view) noexcept;
149
150 // ── Text ────────────────────────────────────────────────────────────
151 void set_text(::aria::binding::IView& v, std::string_view text) override;
152 [[nodiscard]] std::string get_text(::aria::binding::IView& v) override;
154 std::function<void(std::string_view)> cb) override;
155
156 // ── Bool ────────────────────────────────────────────────────────────
157 void set_bool(::aria::binding::IView& v, bool value) override;
160 std::function<void(bool)> cb) override;
161
162 // ── Int ─────────────────────────────────────────────────────────────
163 void set_int(::aria::binding::IView& v, int value) override;
166 std::function<void(int)> cb) override;
167
168 void set_int64(::aria::binding::IView& v, std::int64_t value) override;
169 [[nodiscard]] std::int64_t get_int64(::aria::binding::IView& v) override;
171 std::function<void(std::int64_t)> cb) override;
172
173 void set_uint64(::aria::binding::IView& v, std::uint64_t value) override;
174 [[nodiscard]] std::uint64_t get_uint64(::aria::binding::IView& v) override;
176 std::function<void(std::uint64_t)> cb) override;
177
178 void set_float(::aria::binding::IView& v, float value) override;
181 std::function<void(float)> cb) override;
182
183 // ── Double ──────────────────────────────────────────────────────────
184 void set_double(::aria::binding::IView& v, double value) override;
187 std::function<void(double)> cb) override;
188
189 // ── Visibility / enabled ────────────────────────────────────────────
190 void set_visible(::aria::binding::IView& v, bool visible) override;
191 void set_enabled(::aria::binding::IView& v, bool enabled) override;
192
193 // ── Click ───────────────────────────────────────────────────────────
195 std::function<void()> cb) override;
196
197private:
198 struct Impl;
199 std::unique_ptr<Impl> p_;
200};
201
202} // namespace aria::adapters::appkit
203
204// ─── Backwards-compatible type alias ────────────────────────────────────
205//
206// Backwards-compat aliases: legacy showcase code imported
207// `AppKitAdapter` / `AppKitView` from the global namespace; the
208// canonical home is now `aria::adapters::appkit`. The aliases
209// below keep the existing showcase compile paths working unchanged.
212
213// Backwards-compat ObjC type alias for the showcase that used the old name.
214@compatibility_alias AppKitClickWrapper AriaClickTarget;
::aria::adapters::appkit::AppKitAdapter AppKitAdapter
Definition AppKitAdapter.hpp:210
::aria::adapters::appkit::AppKitView AppKitView
Definition AppKitAdapter.hpp:211
RAII handle to a single subscription.
Definition subscription.hpp:44
Definition AppKitAdapter.hpp:102
void set_int64(::aria::binding::IView &v, std::int64_t value) override
AppKitAdapter(const AppKitAdapter &)=delete
void set_int(::aria::binding::IView &v, int value) override
void set_float(::aria::binding::IView &v, float value) override
::aria::Subscription on_int_changed(::aria::binding::IView &v, std::function< void(int)> cb) override
AppKitAdapter & operator=(const AppKitAdapter &)=delete
int get_int(::aria::binding::IView &v) override
void set_uint64(::aria::binding::IView &v, std::uint64_t value) override
::aria::Subscription on_uint64_changed(::aria::binding::IView &v, std::function< void(std::uint64_t)> cb) override
std::string_view platform_name() const noexcept override
Definition AppKitAdapter.hpp:110
::aria::Subscription on_text_changed(::aria::binding::IView &v, std::function< void(std::string_view)> cb) override
::aria::Subscription on_click(::aria::binding::IView &v, std::function< void()> cb) override
void set_visible(::aria::binding::IView &v, bool visible) override
::aria::Subscription on_int64_changed(::aria::binding::IView &v, std::function< void(std::int64_t)> cb) override
void release_view(NSView *view) noexcept
Drop the cached AppKitView for view, if any.
void set_bool(::aria::binding::IView &v, bool value) override
AppKitView & view_for(NSView *view)
Wrap a native NSView* as an IView owned by this adapter.
void set_double(::aria::binding::IView &v, double value) override
std::uint64_t get_uint64(::aria::binding::IView &v) override
void set_enabled(::aria::binding::IView &v, bool enabled) override
std::string get_text(::aria::binding::IView &v) override
float get_float(::aria::binding::IView &v) override
bool get_bool(::aria::binding::IView &v) override
::aria::Subscription on_float_changed(::aria::binding::IView &v, std::function< void(float)> cb) override
std::int64_t get_int64(::aria::binding::IView &v) override
double get_double(::aria::binding::IView &v) override
void set_text(::aria::binding::IView &v, std::string_view text) override
::aria::Subscription on_bool_changed(::aria::binding::IView &v, std::function< void(bool)> cb) override
::aria::Subscription on_double_changed(::aria::binding::IView &v, std::function< void(double)> cb) override
Definition AppKitAdapter.hpp:81
std::string_view kind() const noexcept override
Definition AppKitAdapter.hpp:90
~AppKitView() override
Definition AppKitAdapter.hpp:84
T * as() const
Definition AppKitAdapter.hpp:94
AppKitView(NSView *view)
Definition AppKitAdapter.hpp:83
NSView * native() const noexcept
Definition AppKitAdapter.hpp:91
Abstract platform adapter — knows how to read/write/observe widgets.
Definition view_adapter.hpp:80
Abstract platform widget reference.
Definition view_adapter.hpp:28
void fire_destroy_() noexcept
Invoked by ~IView() to fan out the notification — this is the last-resort trigger.
Definition AppKitAdapter.hpp:77
Definition validation_key.hpp:110