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>
20namespace aui::ui_building {
23using ViewContainer = _<AViewContainer>;
24using ViewGroup = AVector<_<AView>>;
25using ViewOrViewGroup = std::variant<_<AView>, AVector<_<AView>>>;
28template <
typename ViewFactory>
33 operator View()
const {
return asViewFactory()->operator()(); }
34 operator ViewContainer()
const {
return asViewFactory()->operator()(); }
35 auto operator<<(
const AString& assEntry)
const {
return asViewFactory()->operator()() << assEntry; }
37 auto operator^(
const T& t)
const {
38 return asViewFactory()->operator()() ^ t;
41 auto operator+(
const T& t)
const {
42 return asViewFactory()->operator()() + t;
46 auto operator^(T&& t)
const {
47 return asViewFactory()->operator()() ^ std::forward<T>(t);
50 auto operator&(T&& t)
const {
51 return asViewFactory()->operator()() & std::forward<T>(t);
54 auto operator&&(T&& t)
const {
55 return asViewFactory()->operator()() && std::forward<T>(t);
58 auto operator+(T&& t)
const {
59 return asViewFactory()->operator()() + std::forward<T>(t);
62 auto operator->()
const {
return asViewFactory()->operator()(); }
64 template <
typename SignalField,
typename Object,
typename Function>
65 auto connect(SignalField&& signalField, Object&&
object, Function&& function) {
66 return asViewFactory()->operator()().connect(
67 std::forward<SignalField>(signalField), std::forward<Object>(
object), std::forward<Function>(function));
70 template <
typename Object,
typename Function>
71 auto clicked(Object&&
object, Function&& function) {
72 return connect(&
AView::clicked, std::forward<Object>(
object), std::forward<Function>(function));
75 template <
typename SignalField,
typename Function>
76 auto connect(SignalField&& signalField, Function&& function) {
77 return asViewFactory()->operator()().connect(
78 std::forward<SignalField>(signalField), std::forward<Function>(function));
82 [[nodiscard]] ViewFactory* asViewFactory()
const {
83 return const_cast<ViewFactory*
>(
static_cast<const ViewFactory*
>(
this));
87template <
typename Item>
88concept LayoutItemView = aui::convertible_to<Item, View>;
89template <
typename Item>
90concept LayoutItemViewGroup = aui::convertible_to<Item, ViewGroup>;
91template <
typename Item>
92concept LayoutItemViewFactory = aui::factory<Item, View>;
94template <
typename Item>
95concept ValidLayoutItem = LayoutItemView<Item> || LayoutItemViewGroup<Item> || LayoutItemViewFactory<Item>;
97template <
typename Layout, aui::derived_from<AViewContainer> Container = AViewContainer>
98struct layouted_container_factory_impl {
100 AVector<View> mViews;
103 template <
typename... Views>
104 layouted_container_factory_impl(Views&&... views) {
105 mViews.reserve(
sizeof...(views));
107 (ValidLayoutItem<Views> && ...),
108 "One of the items passed to declarative container is not valid. "
109 "Please check your compiler's diagnostics on constraint satisfaction.");
110 aui::parameter_pack::for_each(
111 [
this]<ValidLayoutItem Item>(Item&& item) {
112 constexpr bool isView = LayoutItemView<Item>;
113 constexpr bool isViewGroup = LayoutItemViewGroup<Item>;
114 constexpr bool isInvokable = LayoutItemViewFactory<Item>;
116 if constexpr (isViewGroup) {
117 auto asViewGroup = ViewGroup(item);
118 mViews << std::move(asViewGroup);
119 }
else if constexpr (isView) {
120 auto asView = View(item);
121 mViews << std::move(asView);
122 }
else if constexpr (isInvokable) {
126 std::forward<Views>(views)...);
129 _<Container> operator()() {
130 auto c = _new<Container>();
131 if constexpr (!std::is_same_v<Layout, std::nullopt_t>) {
132 c->setLayout(std::make_unique<Layout>());
134 c->setViews(std::move(mViews));
139template <
typename Layout, aui::derived_from<AViewContainer> Container = AViewContainer>
140struct layouted_container_factory_impl_with_expanding : layouted_container_factory_impl<Layout, Container> {
142 using layouted_container_factory_impl<Layout, Container>::layouted_container_factory_impl;
144 struct Expanding : view_helper<Expanding>, layouted_container_factory_impl<Layout, Container> {
146 template <
typename... Views>
147 Expanding(Views&&... views) : layouted_container_factory_impl<Layout>(std::forward<Views>(views)...) {}
149 _<Container> operator()() {
150 return layouted_container_factory_impl<Layout>::operator()()
let { it->setExpanding(); };
155template <
typename Layout, aui::derived_from<AViewContainer> Container = AViewContainer>
156struct layouted_container_factory
157 : view_helper<layouted_container_factory<Layout, Container>>,
158 layouted_container_factory_impl_with_expanding<Layout, Container> {
159 template <
typename... Views>
160 layouted_container_factory(Views&&... views)
161 : layouted_container_factory_impl_with_expanding<Layout, Container>(std::forward<Views>(views)...) {}
169template <
typename View>
170struct view : detail::view_helper<view<View>> {
172 template <
typename... Args>
173 view(Args&&...
args) : mView(_new<View>(std::forward<Args>(
args)...)) {}
175 _<View>& operator()() {
return mView; }
177 operator _<View>&() {
return mView; }
183static_assert(std::is_convertible_v<view<AView>, View>,
"declarative view wrapper must be convertible to _<AView>");
189template <
typename Layout, aui::derived_from<AViewContainer> Container = AViewContainer>
190using view_container_layout = detail::layouted_container_factory<Layout, Container>;
194namespace declarative {
215 Style(std::initializer_list<Rule> rules) : mStylesheet(_new<AStylesheet>(
AStylesheet(rules))) {}
218 for (
const auto& view : views) {
219 AUI_ASSERTX(view->extraStylesheet() ==
nullptr,
"extra stylesheet already specified");
220 view->setExtraStylesheet(mStylesheet);
222 mViews = std::move(views);
Definition AStylesheet.h:21
A std::vector with AUI extensions.
Definition AVector.h:39
emits clicked
Left mouse button clicked.
Definition AView.h:900
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:178
class_of c
Selects views that are of the specified classes.
Definition class_of.h:84
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