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"
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};
321 template<
typename Iterator>
322 void drawViews(Iterator begin, Iterator end,
ARenderContext contextPassedToContainer) {
333 for (
auto i = begin; i != end; ++i) {
334 drawView(*i, contextPassedToContainer);
408 drawViews(mViews.begin(), mViews.end(), contextPassedToContainer);
411 virtual void applyGeometryToChildren();
420 _unique<ALayout> mLayout;
421 bool mSizeSet =
false;
425 bool triggered =
false;
429 struct ConsumesClickCache {
440 AOptional<ConsumesClickCache> mConsumesClickCache;
448 _weak<AView> mFocusChainTarget;
454 ASmallVector<PointerEventsMapping, 1> mPointerEventsMapping;
456 void notifyParentEnabledStateChanged(
bool enabled)
override;
457 void invalidateCaches();
462 _<AView> pointerEventsMapping(APointerIndex index);
Bit field implementation.
Definition ABitField.h:20
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition AOptional.h:33
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 addViewCustomLayout(const _< AView > &view)
Adds view to container without exposing it to the layout manager.
void setFocusChainTarget(_weak< AView > target)
Set focus chain target.
Definition AViewContainerBase.h:267
void setViews(AVector< _< AView > > views)
Replace views.
void invalidateAssHelper() override
Resets mAssHelper.
void removeView(size_t index)
Remove view from the container at specified index.
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
void setLayout(_unique< ALayout > layout)
Set new layout manager for this AViewContainerBase. DESTROYS OLD LAYOUT MANAGER WITH ITS VIEWS!...
emits childrenChanged
Emitted when addView(s)/removeView/setLayout was called.
Definition AViewContainerBase.h:417
void removeView(AView *view)
Remove view from the container.
void onViewGraphSubtreeChanged() override
Called when direct or indirect parent has changed.
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
void addView(size_t index, const _< AView > &view)
Add view at specific index to the container.
void onPointerPressed(const APointerPressedEvent &event) override
Called on pointer (mouse) released event.
_< AView > getViewAtRecursive(glm::ivec2 pos, ABitField< AViewLookupFlags > flags=AViewLookupFlags::NONE) const noexcept
Acts as AViewContainerBase::getViewAt but recursively (may include non-direct child).
bool onGesture(const glm::ivec2 &origin, const AGestureEvent &event) override
int getContentMinimumWidth() override
void addViews(AVector< _< AView > > views)
Add all views from vector.
_< AView > focusChainTarget()
Definition AViewContainerBase.h:278
void onPointerMove(glm::vec2 pos, const APointerMoveEvent &event) override
Handles pointer hover events.
void removeAllViews()
Remove all views from container.
void removeView(const _< AView > &view)
Remove view from the container.
void markPixelDataInvalid(ARect< int > invalidArea) override
A view requests to redraw it and passes it's coords relative to this.
void addView(const _< AView > &view)
Add view to the container.
void onClickPrevented() override
Called on AWindowBase::preventClickOnPointerRelease.
const ASmallVector< PointerEventsMapping, 1 > & pointerEventsMapping() const noexcept
Definition AViewContainerBase.h:305
bool consumesClick(const glm::ivec2 &pos) override
Determines whether this AView processes this click or passes it thru.
void onPointerReleased(const APointerReleasedEvent &event) override
Called on pointer (mouse) released event.
void onScroll(const AScrollEvent &event) override
void removeViews(aui::range< AVector< _< AView > >::iterator > views)
Remove views from the container.
bool capturesFocus() override
void setContents(const _< AViewContainer > &container)
Moves (like via std::move) all children and layout of the specified container to this container.
void invalidateAllStyles() override
Invalidates all styles, causing to iterate over all rules in global and parent stylesheets.
_< 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
virtual _< AView > getViewAt(glm::ivec2 pos, ABitField< AViewLookupFlags > flags=AViewLookupFlags::NONE) const noexcept
Finds first direct child view under position.
const AVector< _< AView > > & getViews() const
Get all views of the container.
Definition AViewContainerBase.h:131
int getContentMinimumHeight() override
void render(ARenderContext context) override
Draws this AView. Noone should call this function except rendering routine.
auto enabled() const
Whether view is enabled (i.e., reacts to user).
Definition AView.h:90
auto size() const
Size, including content area, border and padding.
Definition AView.h:114
glm::ivec2 getSize() const noexcept
Size, including content area, border and padding.
Definition AView.h:217
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
@ 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
#define AUI_ENUM_FLAG(name)
Make a bitfield-style enum class.
Definition AEnumerate.h:227
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:572
#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:52
Definition iterators.h:50
Definition iterators.h:34