73#include <doctest/doctest.h>
90template<
class Harness>
105template<
class Harness>
107 auto vh = h.make_text_view();
108 IView& v = vh.view();
109 auto adapter = h.make_adapter();
111 adapter->set_text(v,
"hello");
112 CHECK(adapter->get_text(v) ==
"hello");
116 auto sub = adapter->on_text_changed(v, [&](std::string_view sv) {
118 last = std::string(sv);
121 h.user_type(v,
"world");
123 CHECK(last ==
"world");
127 h.user_type(v,
"after-release");
132template<
class Harness>
137 auto vh = h.make_text_view();
138 IView& v = vh.view();
139 engine.bind_text(p, v);
141 CHECK(engine.adapter().get_text(v) ==
"alpha");
144 CHECK(engine.adapter().get_text(v) ==
"beta");
146 h.user_type(v,
"gamma");
147 CHECK(p.
get() ==
"gamma");
154template<
class Harness>
156 auto vh = h.make_bool_view();
157 IView& v = vh.view();
158 auto adapter = h.make_adapter();
160 adapter->set_bool(v,
true);
161 CHECK(adapter->get_bool(v));
165 auto sub = adapter->on_bool_changed(v, [&](
bool b) { ++hits; last = b; });
167 h.user_toggle(v,
false);
172template<
class Harness>
177 auto vh = h.make_bool_view();
178 IView& v = vh.view();
179 engine.bind_bool(p, v);
181 CHECK_FALSE(engine.adapter().get_bool(v));
184 CHECK(engine.adapter().get_bool(v));
186 h.user_toggle(v,
false);
187 CHECK_FALSE(p.
get());
194template<
class Harness>
196 auto vh = h.make_int_view();
197 IView& v = vh.view();
198 auto adapter = h.make_adapter();
200 adapter->set_int(v, 42);
201 CHECK(adapter->get_int(v) == 42);
204 auto sub = adapter->on_int_changed(v, [&](
int n) { last = n; });
205 h.user_set_int(v, 7);
213template<
class Harness>
215 auto vh = h.make_double_view();
216 IView& v = vh.view();
217 auto adapter = h.make_adapter();
219 adapter->set_double(v, 3.25);
220 CHECK(adapter->get_double(v) == doctest::Approx(3.25));
223 auto sub = adapter->on_double_changed(v, [&](
double d) { last = d; });
224 h.user_set_double(v, 7.5);
225 CHECK(last == doctest::Approx(7.5));
237template<
class Harness>
239 auto vh = h.make_int_view();
240 IView& v = vh.view();
241 auto adapter = h.make_adapter();
243 adapter->set_int64(v, 1'000'000);
244 CHECK(adapter->get_int64(v) == 1'000'000);
247template<
class Harness>
249 auto vh = h.make_int_view();
250 IView& v = vh.view();
251 auto adapter = h.make_adapter();
253 adapter->set_uint64(v, 123'456u);
254 CHECK(adapter->get_uint64(v) == 123'456u);
257template<
class Harness>
259 auto vh = h.make_double_view();
260 IView& v = vh.view();
261 auto adapter = h.make_adapter();
263 adapter->set_float(v, 2.5f);
268 CHECK(
static_cast<double>(adapter->get_float(v)) == doctest::Approx(2.5));
275template<
class Harness>
277 auto vh = h.make_click_view();
278 IView& v = vh.view();
279 auto adapter = h.make_adapter();
282 auto sub = adapter->on_click(v, [&]() { ++hits; });
297template<
class Harness>
305 [&]() {
return gate.
get(); }
308 auto vh = h.make_click_view();
309 IView& v = vh.view();
310 engine.bind_command(cmd, v);
338template<
class Harness>
343 auto survivor_vh = h.make_text_view();
344 engine.bind_text(survivor, survivor_vh.view());
348 auto dying_vh = h.make_text_view();
349 engine.bind_text(dying, dying_vh.view());
350 CHECK(engine.adapter().get_text(dying_vh.view()) ==
"x");
353 CHECK(engine.adapter().get_text(dying_vh.view()) ==
"y");
359 dying =
"after-death";
362 survivor =
"still here";
363 CHECK(engine.adapter().get_text(survivor_vh.view()) ==
"still here");
373template<
class Harness>
Definition command.hpp:154
BindingEngine: connects ViewModel properties to platform views via an adapter.
Definition binding_engine.hpp:103
BindingEngine(std::shared_ptr< IViewAdapter > adapter)
Convenience constructor: no dispatcher, Direct policy.
Abstract platform widget reference.
Definition view_adapter.hpp:28
Definition property.hpp:103
T get() const
Auto-tracked read.
Definition property.hpp:138