14#include <AUI/View/AViewContainer.h>
15#include <AUI/Util/kAUI.h>
16#include <AUI/Traits/callables.h>
17#include <AUI/Traits/parameter_pack.h>
18#include <AUI/ASS/ASS.h>
21namespace aui::ui_building {
28 template<
typename ViewFactory>
33 operator View()
const {
34 return asViewFactory()->operator()();
37 return asViewFactory()->operator()();
39 auto operator<<(
const AString& assEntry)
const {
40 return asViewFactory()->operator()() << assEntry;
43 auto operator^(
const T& t)
const {
44 return asViewFactory()->operator()() ^ t;
47 auto operator+(
const T& t)
const {
48 return asViewFactory()->operator()() + t;
52 auto operator^(T&& t)
const {
53 return asViewFactory()->operator()() ^ std::forward<T>(t);
56 auto operator&&(T&& t)
const {
57 return asViewFactory()->operator()() && std::forward<T>(t);
60 auto operator+(T&& t)
const {
61 return asViewFactory()->operator()() + std::forward<T>(t);
64 auto operator->()
const {
65 return asViewFactory()->operator()();
69 template<
typename SignalField,
typename Object,
typename Function>
70 auto connect(SignalField&& signalField, Object&&
object, Function&&
function) {
71 return asViewFactory()->operator()().connect(std::forward<SignalField>(signalField), std::forward<Object>(
object), std::forward<Function>(
function));
74 template<
typename Object,
typename Function>
75 auto clicked(Object&&
object, Function&&
function) {
76 return connect(&
AView::clicked, std::forward<Object>(
object), std::forward<Function>(
function));
79 template<
typename SignalField,
typename Function>
80 auto connect(SignalField&& signalField, Function&&
function) {
81 return asViewFactory()->operator()().connect(std::forward<SignalField>(signalField), std::forward<Function>(
function));
85 ViewFactory* asViewFactory()
const {
86 return const_cast<ViewFactory*
>(
static_cast<const ViewFactory*
>(
this));
90 template<
typename View>
94 template<
typename... Args>
95 view(Args&&...
args): mView(_new<View>(std::forward<Args>(
args)...)) {}
109 static_assert(std::is_convertible_v<view<AView>,
View>,
"declarative view wrapper is not convertible to _<AView>");
111 template<
typename Layout, aui::derived_from<AViewContainer> Container = AViewContainer>
117 template<
typename... Views>
119 mViews.reserve(
sizeof...(views));
120 aui::parameter_pack::for_each([
this](
auto&& item) {
121 using type =
decltype(item);
122 constexpr bool isViewGroup = std::is_convertible_v<type, ViewGroup>;
123 constexpr bool isView = std::is_convertible_v<type, View>;
124 constexpr bool isInvokable = std::is_invocable_v<type>;
126 static_assert(isViewGroup || isView || isInvokable,
"the item is neither convertible to View nor ViewGroup, nor invokable");
128 if constexpr (isViewGroup) {
130 mViews << std::move(asViewGroup);
131 }
else if constexpr (isView) {
132 auto asView =
View(item);
133 mViews << std::move(asView);
134 }
else if constexpr(isInvokable) {
137 }, std::forward<Views>(views)...);
141 auto c = _new<Container>();
142 if constexpr(!std::is_same_v<Layout, std::nullopt_t>) {
143 c->setLayout(std::make_unique<Layout>());
145 c->setViews(std::move(mViews));
151 template<
typename Layout, aui::derived_from<AViewContainer> Container = AViewContainer>
158 template<
typename... Views>
171 template <
typename Layout, aui::derived_from<AViewContainer> Container = AViewContainer>
174 template <
typename... Views>
180namespace declarative {
201 Style(std::initializer_list<Rule> rules): mStylesheet(_new<AStylesheet>(
AStylesheet(rules))) {
206 for (
const auto& view : views) {
207 AUI_ASSERTX(view->extraStylesheet() ==
nullptr,
"extra stylesheet already specified");
208 view->setExtraStylesheet(mStylesheet);
210 mViews = std::move(views);
215 return std::move(mViews);
Represents a Unicode character string.
Definition: AString.h:37
Definition: AStylesheet.h:21
A std::vector with AUI extensions.
Definition: AVector.h:38
emits clicked
Left mouse button clicked.
Definition: AView.h:1073
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
API_AUI_CORE const ACommandLineArgs & args() noexcept
Definition: OSAndroid.cpp:29
#define let
Performs multiple operations on a single object without repeating its name (in place) This function c...
Definition: kAUI.h:262
#define AUI_ASSERTX(condition, what)
Asserts that the passed condition evaluates to true. Adds extra message string.
Definition: Assert.h:74
Definition: Declarative.h:156
Definition: Declarative.h:152
Definition: Declarative.h:112
Definition: Declarative.h:173
Definition: Declarative.h:29
Definition: Declarative.h:91
Extra styles wrapper.
Definition: Declarative.h:199