15#include <AUI/View/AView.h>
16#include "AUI/Common/SharedPtr.h"
17#include "AUI/Enum/AOverflow.h"
18#include "AUI/Util/ABitField.h"
20#include "AUI/Layout/ALayout.h"
21#include "AUI/Common/AVector.h"
22#include "AUI/Render/IRenderer.h"
23#include "AUI/Render/RenderHints.h"
24#include "AUI/Render/ARenderContext.h"
28AUI_ENUM_FLAG(AViewLookupFlags) {
34 IGNORE_VISIBILITY = 0b1,
42 ONLY_ONE_PER_CONTAINER = 0b10,
50 ONLY_THAT_CONSUMES_CLICK = 0b100,
68class API_AUI_VIEWS AViewContainerBase :
public AView {
83 ~AViewContainerBase()
override = 0;
90 void onMouseEnter()
override;
94 void onMouseLeave()
override;
96 void onDpiChanged()
override;
112 bool onGesture(
const glm::ivec2& origin,
const AGestureEvent& event)
override;
116 void setSize(glm::ivec2
size)
override;
118 void setEnabled(
bool enabled =
true)
override;
121 return mViews.cbegin();
125 return mViews.cend();
174 template<aui::predicate<_<AView>> Callback>
177 auto process = [&](
const _<AView>& view) {
180 if (
auto container = _cast<AViewContainerBase>(view)) {
181 if (container->getViewAtRecursive(pos - view->getPosition(), callback, flags)) {
189 auto targetPos = pos - view->getPosition();
191 if (targetPos.x < 0 || targetPos.y < 0 || targetPos.x >= view->getSize().x || targetPos.y >= view->getSize().y) {
194 if (!flags.test(AViewLookupFlags::IGNORE_VISIBILITY) && !(view->getVisibility() & Visibility::FLAG_CONSUME_CLICKS)) {
198 if (view->consumesClick(targetPos)) {
199 if (flags.test(AViewLookupFlags::IGNORE_VISIBILITY) || !!(view->getVisibility() & Visibility::FLAG_CONSUME_CLICKS)) {
204 if (flags.test(AViewLookupFlags::ONLY_ONE_PER_CONTAINER)) {
209 if (possibleOutput ==
nullptr) {
210 possibleOutput = view;
214 if (possibleOutput) {
215 return process(possibleOutput);
227 template<aui::predicate<_<AView>> Callback>
229 for (
auto it = mViews.rbegin(); it != mViews.rend(); ++it) {
231 if (flags.test(AViewLookupFlags::IGNORE_VISIBILITY) || !!(view->getVisibility() & Visibility::FLAG_CONSUME_CLICKS)) {
234 if (
auto container = _cast<AViewContainerBase>(view)) {
235 if (container->visitsViewRecursive(callback, flags)) {
239 if (flags.test(AViewLookupFlags::ONLY_ONE_PER_CONTAINER)) {
268 if (
auto v = target.lock()) {
271 mFocusChainTarget = std::move(target);
279 if (
auto v = mFocusChainTarget.lock()) {
280 if (v->mParent !=
this) {
281 mFocusChainTarget.reset();
290 void applyGeometryToChildrenIfNecessary();
292 void onKeyDown(AInput::Key key)
override;
294 void onKeyRepeat(AInput::Key key)
override;
296 void onKeyUp(AInput::Key key)
override;
298 void onCharEntered(
char16_t c)
override;
306 return mPointerEventsMapping;
309 void forceUpdateLayoutRecursively()
override;
311 void markMinContentSizeInvalid()
override;
316 bool mWantsLayoutUpdate =
true;
317 glm::ivec2 mLastLayoutUpdateSize{0, 0};
319 void drawView(
const _<AView>& view, ARenderContext contextOfTheContainer);
321 template<
typename Iterator>
322 void drawViews(Iterator begin, Iterator end, ARenderContext contextPassedToContainer) {
327 contextPassedToContainer.clip(ARect<int>{
333 for (
auto i = begin; i != end; ++i) {
334 drawView(*i, contextPassedToContainer);
345 void setViews(AVector<_<AView>> views);
354 void addViewCustomLayout(
const _<AView>& view);
359 void addViews(AVector<_<AView>> views);
364 void addView(
const _<AView>& view);
369 void addView(
size_t index,
const _<AView>& view);
374 void removeView(
const _<AView>& view);
379 void removeView(AView* view);
384 void removeView(
size_t index);
389 void removeAllViews();
395 void setContents(
const _<AViewContainer>& container);
400 void setLayout(_unique<ALayout> layout);
402 void renderChildren(ARenderContext contextPassedToContainer) {
403 drawViews(mViews.begin(), mViews.end(), contextPassedToContainer);
406 virtual void applyGeometryToChildren();
415 _unique<ALayout> mLayout;
416 bool mSizeSet =
false;
420 bool triggered =
false;
424 struct ConsumesClickCache {
435 AOptional<ConsumesClickCache> mConsumesClickCache;
443 _weak<AView> mFocusChainTarget;
449 ASmallVector<PointerEventsMapping, 1> mPointerEventsMapping;
451 void notifyParentEnabledStateChanged(
bool enabled)
override;
452 void invalidateCaches();
457 _<AView> pointerEventsMapping(APointerIndex index);
Bit field implementation.
Definition ABitField.h:20
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition AOptional.h:32
Wrapper class that stores either mouse button index or finger index.
Definition APointerIndex.h:21
Vector-like container consisting of few elements on stack and switches to dynamic allocation vector i...
Definition ASmallVector.h:34
A std::vector with AUI extensions.
Definition AVector.h:39
void setFocusChainTarget(_weak< AView > target)
Set focus chain target.
Definition AViewContainerBase.h:267
bool getViewAtRecursive(glm::ivec2 pos, const Callback &callback, ABitField< AViewLookupFlags > flags=AViewLookupFlags::NONE)
Acts as AViewContainerBase::getViewAtRecursive but calls a callback instead of returning value.
Definition AViewContainerBase.h:175
emits childrenChanged
Emitted when addView(s)/removeView/setLayout was called.
Definition AViewContainerBase.h:412
const _unique< ALayout > & getLayout() const noexcept
Get layout manager of the container.
Definition AViewContainerBase.h:140
bool visitsViewRecursive(Callback &&callback, ABitField< AViewLookupFlags > flags=AViewLookupFlags::NONE)
Performs recursive view traversal.
Definition AViewContainerBase.h:228
_< AView > getViewAtRecursive(glm::ivec2 pos, ABitField< AViewLookupFlags > flags=AViewLookupFlags::NONE) const noexcept
Acts as AViewContainerBase::getViewAt but recursively (may include non-direct child).
Definition AViewContainerBase.cpp:437
_< AView > focusChainTarget()
Definition AViewContainerBase.h:278
const ASmallVector< PointerEventsMapping, 1 > & pointerEventsMapping() const noexcept
Definition AViewContainerBase.h:305
_< T > getViewAtRecursiveOfType(glm::ivec2 pos, ABitField< AViewLookupFlags > flags=AViewLookupFlags::NONE)
Acts as AViewContainerBase::getViewAtRecursive but finds a view castable to specified template type.
Definition AViewContainerBase.h:255
const AVector< _< AView > > & getViews() const
Get all views of the container.
Definition AViewContainerBase.h:131
auto enabled() const
Whether view is enabled (i.e., reacts to user).
Definition AView.h:90
virtual int getContentMinimumHeight()
Definition AView.cpp:252
virtual bool consumesClick(const glm::ivec2 &pos)
Determines whether this AView processes this click or passes it thru.
Definition AView.cpp:540
virtual bool onGesture(const glm::ivec2 &origin, const AGestureEvent &event)
Definition AView.cpp:604
virtual void invalidateAssHelper()
Resets mAssHelper.
Definition AView.cpp:291
auto size() const
Size, including content area, border and padding.
Definition AView.h:114
virtual void onPointerMove(glm::vec2 pos, const APointerMoveEvent &event)
Handles pointer hover events.
Definition AView.cpp:343
virtual void onViewGraphSubtreeChanged()
Called when direct or indirect parent has changed.
Definition AView.cpp:695
virtual void onClickPrevented()
Called on AWindowBase::preventClickOnPointerRelease.
Definition AView.cpp:680
glm::ivec2 getSize() const noexcept
Size, including content area, border and padding.
Definition AView.h:217
virtual int getContentMinimumWidth()
Definition AView.cpp:248
virtual void onPointerPressed(const APointerPressedEvent &event)
Called on pointer (mouse) released event.
Definition AView.cpp:357
virtual bool capturesFocus()
Definition AView.cpp:573
virtual void markPixelDataInvalid(ARect< int > invalidArea)
A view requests to redraw it and passes it's coords relative to this.
Definition AView.cpp:716
virtual void onPointerReleased(const APointerReleasedEvent &event)
Called on pointer (mouse) released event.
Definition AView.cpp:366
virtual void render(ARenderContext ctx)
Draws this AView. Noone should call this function except rendering routine.
Definition AView.cpp:142
virtual void invalidateAllStyles()
Invalidates all styles, causing to iterate over all rules in global and parent stylesheets.
Definition AView.cpp:179
virtual void onScroll(const AScrollEvent &event)
Definition AView.cpp:407
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:178
@ HIDDEN_FROM_THIS
Like HIDDEN, but view's ASS-styled background is also affected by mask.
Definition AOverflow.h:40
@ HIDDEN
Overflowed contents are hidden. Suitable for lists with scroll.
Definition AOverflow.h:35
@ VISIBLE
Overflowed contents are visible.
Definition AOverflow.h:28
@ NONE
Definition AFloat.h:23
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:348
#define AUI_ASSERT(condition)
Asserts that the passed condition evaluates to true.
Definition Assert.h:55
Pointing method move event.
Definition APointerMoveEvent.h:21
Pointing method press event.
Definition APointerPressedEvent.h:21
Pointing method press event.
Definition APointerReleasedEvent.h:19
Axis aligned 2D rectangle.
Definition ARect.h:24
Render context passed to AView::render.
Definition ARenderContext.h:43
Definition AViewContainerBase.h:72
bool isBlockClicksWhenPressed
true if the view or any child (direct or indirect) of the view blocks clicks when pressed
Definition AViewContainerBase.h:79
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:51
Definition iterators.h:34