20#include "AUI/Common/ASmallVector.h"
21#include <AUI/ASS/Property/IProperty.h>
22#include <AUI/ASS/Property/ScrollbarAppearance.h>
23#include "AUI/Common/ABoxFields.h"
24#include "AUI/Common/ADeque.h"
25#include "AUI/Common/AObject.h"
26#include "AUI/Common/SharedPtr.h"
27#include "AUI/Platform/ACursor.h"
28#include "AUI/Platform/AInput.h"
29#include "AUI/Reflect/AClass.h"
30#include "AUI/Font/AFontStyle.h"
31#include "AUI/Util/AFieldSignalEmitter.h"
32#include "AUI/Render/ARenderContext.h"
33#include "AUI/Util/IBackgroundEffect.h"
34#include <AUI/ASS/PropertyListRecursive.h>
35#include <AUI/Enum/AOverflow.h>
36#include <AUI/Enum/Visibility.h>
37#include <AUI/Enum/MouseCollisionPolicy.h>
38#include <AUI/Util/ALayoutDirection.h>
39#include <AUI/Action/AMenu.h>
41#include <AUI/Event/AScrollEvent.h>
42#include <AUI/Event/AGestureEvent.h>
43#include <AUI/Event/APointerPressedEvent.h>
44#include <AUI/Event/APointerReleasedEvent.h>
45#include <AUI/Event/APointerMoveEvent.h>
46#include <AUI/Render/ITexture.h>
47#include <AUI/Render/IRenderViewToTexture.h>
48#include <AUI/Enum/AFloat.h>
49#include <AUI/Common/AProperty.h>
77class API_AUI_VIEWS AView:
public AObject
79 friend class AViewContainerBase;
80 friend class AViewContainer;
81 friend class IRenderViewToTexture;
150 &AView::setVisibility,
229 void setMinSize(glm::ivec2 minSize)
noexcept {
233 virtual void markMinContentSizeInvalid();
246 void setExtraStylesheet(
AStylesheet&& extraStylesheet);
253 return mExtraStylesheet;
265 mOverflow = overflow;
273 return mOverflowMask;
275 void setOverflowMask(AOverflowMask overflow)
277 mOverflowMask = overflow;
284 return mBorderRadius;
286 void setBorderRadius(
float radius) {
287 mBorderRadius = radius;
295 int getHeight()
const
324 return getMinimumSize() +
mMargin.occupiedSize();
353 virtual bool consumesClick(
const glm::ivec2& pos);
377 virtual AString debugString()
const;
424 virtual int getContentMinimumWidth();
430 virtual int getContentMinimumHeight();
437 if (!mCachedMinContentSize) {
439 mCachedMinContentSize = minContentSize;
440 return minContentSize;
442 return *mCachedMinContentSize;
446 bool isContentMinimumSizeInvalidated() noexcept {
447 return !mCachedMinContentSize.hasValue();
450 bool hasFocus()
const;
452 virtual int getMinimumWidth();
453 virtual int getMinimumHeight();
455 glm::ivec2 getMinimumSize() {
456 return { getMinimumWidth(), getMinimumHeight() };
459 void setMaxSize(
const glm::ivec2& maxSize) {
471 int getContentWidth()
const
473 return static_cast<int>(mSize.x - mPadding.horizontal());
476 int getContentHeight()
const
478 return static_cast<int>(mSize.y - mPadding.vertical());
482 const glm::ivec2& getExpanding()
const
495 if (mExpanding ==
expanding) [[unlikely]] {
500 markMinContentSizeInvalid();
518 const _<AAnimator>& getAnimator()
const {
523 void setAnimator(
const _<AAnimator>& animator);
524 void getTransform(glm::mat4& transform)
const;
527 int getExpandingHorizontal()
const
533 int getExpandingVertical()
const
538 [[nodiscard]] aui::float_within_0_1 getOpacity()
const {
541 void setOpacity(aui::float_within_0_1 opacity) {
545 virtual void setPosition(glm::ivec2 position);
554 virtual void setSize(glm::ivec2 size);
555 virtual void setGeometry(
int x,
int y,
int width,
int height);
556 void setGeometry(
const glm::ivec2& position,
const glm::ivec2& size) {
557 setGeometry(position.x, position.y, size.x, size.y);
560 bool isBlockClicksWhenPressed() const noexcept {
561 return mBlockClicksWhenPressed;
564 void setBlockClicksWhenPressed(
bool value)
noexcept {
565 mBlockClicksWhenPressed = value;
575 void setFixedSize(glm::ivec2 size) {
576 AUI_ASSERTX(glm::all(glm::greaterThanEqual(size, glm::ivec2(-100000))),
"abnormal fixed size");
577 if (size == mFixedSize) [[unlikely]] {
581 markMinContentSizeInvalid();
585 bool isMouseHover() const noexcept
591 bool isPressed() const noexcept
593 return !mPressed.empty();
597 bool isPressed(APointerIndex index)
const noexcept
599 return mPressed.contains(index);
602 bool isFocused()
const {
605 bool isMouseEntered()
const {
606 return mMouseEntered;
609 Visibility getVisibility()
const
614 Visibility getVisibilityRecursive()
const;
616 void setVisibility(Visibility visibility)
noexcept;
618 void setVisible(
bool visible)
noexcept
620 setVisibility(visible ? Visibility::VISIBLE : Visibility::INVISIBLE);
624 MouseCollisionPolicy getMouseCollisionPolicy()
const {
625 return mMouseCollisionPolicy;
628 void setMouseCollisionPolicy(MouseCollisionPolicy mouseCollisionPolicy) {
629 mMouseCollisionPolicy = mouseCollisionPolicy;
650 void focus(
bool needFocusChainUpdate =
true);
657 virtual bool capturesFocus();
662 bool hasIndirectParent(
const _<AView>& v);
667 [[nodiscard]] glm::ivec2 getPositionInWindow()
const;
673 void addAssName(
const AString& assName);
679 void removeAssName(
const AString& assName);
697 const _<AAssHelper>& getAssHelper()
const {
701 const ass::PropertyListRecursive& getCustomAss()
const {
702 return mCustomStyleRule;
705 void setCustomStyle(ass::PropertyListRecursive rule);
707 void ensureAssUpdated();
710 _<AView> sharedPtr() {
711 return _cast<AView>(AObject::sharedPtr());
715 _weak<AView> weakPtr() {
716 return _weak<AView>(sharedPtr());
728 virtual bool onGesture(
const glm::ivec2& origin,
const AGestureEvent& event);
730 virtual void onMouseEnter();
741 virtual void onPointerMove(glm::vec2 pos,
const APointerMoveEvent& event);
742 virtual void onMouseLeave();
743 virtual void onDpiChanged();
749 virtual void onPointerPressed(
const APointerPressedEvent& event);
761 virtual void onPointerReleased(
const APointerReleasedEvent& event);
762 virtual void onPointerDoubleClicked(
const APointerPressedEvent& event);
768 virtual void onScroll(
const AScrollEvent& event);
769 virtual void onKeyDown(AInput::Key key);
770 virtual void onKeyRepeat(AInput::Key key);
771 virtual void onKeyUp(AInput::Key key);
772 virtual void onFocusAcquired();
773 virtual void onFocusLost();
774 virtual void onCharEntered(
char16_t c);
779 virtual bool handlesNonMouseNavigation();
781 virtual void forceUpdateLayoutRecursively();
783 virtual void setEnabled(
bool enabled =
true);
785 void setDisabled(
bool disabled =
true) {
786 setEnabled(!disabled);
789 void updateEnableState();
804 setCustomStyle(std::move(rule));
810 virtual void onClickPrevented();
826 virtual void invalidateAllStyles();
846 virtual void invalidateAssHelper();
852 virtual bool wantsTouchscreenKeyboard();
934 emits<> customCssPropertyChanged;
988 bool mMarkedMinContentSizeInvalid =
false;
1080 virtual void commitStyle();
1091 AOverflowMask mOverflowMask = AOverflowMask::ROUNDED_RECT;
1096 Visibility mVisibility = Visibility::VISIBLE;
1107 float mBorderRadius = 0;
1112 MouseCollisionPolicy mMouseCollisionPolicy = MouseCollisionPolicy::DEFAULT;
1117 aui::float_within_0_1 mOpacity = 1;
1140 virtual void notifyParentEnabledStateChanged(
bool enabled);
1147 ALayoutDirection parentLayoutDirection() const noexcept;
1153 bool mMouseEntered = false;
1160 bool mBlockClicksWhenPressed = true;
1165 bool mEnabled = true;
1166 emits<
bool> mEnabledChanged;
1168 bool mDirectlyEnabled = true;
1169 bool mParentEnabled = true;
1172 glm::ivec2 mExpanding = glm::ivec2{0, 0};
1180 struct RenderToTexture {
1181 _unique<IRenderViewToTexture> rendererInterface;
1184 bool drawFromTexture =
true;
1189 bool skipRedrawUntilTextureIsPresented =
false;
1191 AOptional<RenderToTexture> mRenderToTexture;
1196 virtual void invalidateStateStylesImpl(glm::ivec2 prevMinimumSizePlusField);
1198 void notifyParentChildFocused(
const _<AView>& view);
1201API_AUI_VIEWS std::ostream& operator<<(std::ostream& os,
const AView& view);
Definition AAnimator.h:26
Remember, ASS is not a butt. ASS is Aui Style Sheets.
Definition AAssHelper.h:32
@ DEFAULT
Default arrow.
Definition ACursor.h:37
Stores a value and observes it's changes, emitting a signal.
Definition AFieldSignalEmitter.h:21
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
Represents a Unicode character string.
Definition AString.h:37
Definition AStylesheet.h:21
A std::vector with AUI extensions.
Definition AVector.h:39
A view that represents a set of views.
Definition AViewContainerBase.h:68
Base class of all UI objects.
Definition AView.h:78
int getTotalFieldVertical() const
Definition AView.h:391
emits< AInput::Key > keyReleased
Keyboard key released.
Definition AView.h:920
AOptional< ACursor > mCursor
Determines shape which should pointer take when it's above this AView.
Definition AView.h:965
AOverflowMask getOverflowMask() const
Controls how does the overflow (stencil) mask is produced.
Definition AView.h:271
const ABoxFields & getMargin()
Returns the margin.
Definition AView.h:332
glm::ivec2 mSize
Size, including content area, border and padding.
Definition AView.h:980
bool transformGestureEventsToDesktop(const glm::ivec2 &origin, const AGestureEvent &event)
Converts touch screen events to desktop.
Definition AView.cpp:607
auto enabled() const
Whether view is enabled (i.e., reacts to user).
Definition AView.h:90
virtual int getContentMinimumHeight()
Definition AView.cpp:252
AVector< AString > mAssNames
ASS class names.
Definition AView.h:1029
void setExpanding(glm::ivec2 expanding)
Changes the expanding of view.
Definition AView.h:493
virtual void invalidateAssHelper()
Resets mAssHelper.
Definition AView.cpp:291
AFloat getFloating() const noexcept
Floating value for AText.
Definition AView.h:873
glm::ivec2 getCenterPointInWindow() const noexcept
The center point position of the view relatively to top left corner of the window.
Definition AView.h:208
int getTotalOccupiedWidth() const
Definition AView.h:303
auto expanding() const
Expansion coefficient. Hints layout manager how much this AView should be extended relative to other ...
Definition AView.h:134
auto size() const
Size, including content area, border and padding.
Definition AView.h:114
AViewContainerBase * mParent
Parent AView.
Definition AView.h:950
glm::ivec2 mPosition
Top left corner's position relative to top left corner's position of the parent AView.
Definition AView.h:970
virtual void onViewGraphSubtreeChanged()
Called when direct or indirect parent has changed.
Definition AView.cpp:695
glm::ivec2 getMinSize() const noexcept
Definition AView.h:225
bool mSkipUntilLayoutUpdate
If set to true, AViewContainer is obligated ignore this view. This value is set to false by AView::se...
Definition AView.h:1038
glm::ivec2 getPosition() const noexcept
Top left corner's position relative to top left corner's position of the parent AView.
Definition AView.h:194
void setFloating(AFloat f) noexcept
Set floating value for AText.
Definition AView.h:864
emits< glm::ivec2, glm::ivec2 > geometryChanged
Geometry (position and size) changed.
Definition AView.h:905
float getBorderRadius() const
border-radius, specified in ASS.
Definition AView.h:283
glm::ivec2 getTotalFieldSize() const
Definition AView.h:399
ass::PropertyListRecursive mCustomStyleRule
Custom ASS Rules.
Definition AView.h:960
ABoxFields mMargin
Margin, which defines the spacing around this AView. Processed by the layout manager.
Definition AView.h:1017
glm::ivec2 mFixedSize
Fixed size.
Definition AView.h:1012
glm::ivec2 getSize() const noexcept
Size, including content area, border and padding.
Definition AView.h:217
emits< glm::ivec2 > scrolled
Scroll event.
Definition AView.h:910
int getTotalFieldHorizontal() const
Definition AView.h:383
AViewContainerBase * getParent() const
Parent AView.
Definition AView.h:406
glm::ivec2 mMaxSize
Maximal size.
Definition AView.h:1007
void setExtraStylesheet(_< AStylesheet > extraStylesheet)
Definition AView.h:238
std::array< ass::prop::IPropertyBase *, int(ass::prop::PropertySlot::COUNT)> mAss
Drawing list, or baking drawing commands so that you don't have to parse the ASS every time.
Definition AView.h:955
void setSkipUntilLayoutUpdate(bool skipUntilLayoutUpdate)
Definition AView.h:857
virtual AMenuModel composeContextMenu()
Produce context (right click) menu.
Definition AView.cpp:398
virtual int getContentMinimumWidth()
Definition AView.cpp:248
emits< AInput::Key > keyPressed
Keyboard key pressed.
Definition AView.h:915
emits< APointerIndex > clickedButton
Some mouse button clicked.
Definition AView.h:895
emits clickedRightOrLongPressed
Right mouse button clicked or long press gesture applied.
Definition AView.h:930
bool mRedrawRequested
Redraw requested flag for this particular view/.
Definition AView.h:997
AOverflow getOverflow() const
Determines whether display graphics that go out of the bounds of this AView or not.
Definition AView.h:259
ABoxFields mPadding
Padding, which defines the spacing around content area inside the view. Processed by AView implementa...
Definition AView.h:1022
const ABoxFields & getPadding()
Returns the padding.
Definition AView.h:360
void setMargin(const ABoxFields &margin)
Sets the margin.
Definition AView.h:342
emits< bool > focusState
Focus state changed.
Definition AView.h:940
virtual void markPixelDataInvalid(ARect< int > invalidArea)
A view requests to redraw it and passes it's coords relative to this.
Definition AView.cpp:716
glm::ivec2 getPositionInWindow() const
Definition AView.cpp:474
emits viewGraphSubtreeChanged
Definition AView.h:882
const AOptional< ACursor > & getCursor() const
Determines shape which should pointer take when it's above this AView.
Definition AView.h:414
const _< AStylesheet > & extraStylesheet() const noexcept
Definition AView.h:252
glm::ivec2 getMinimumSizePlusMargin()
Definition AView.h:323
void click()
Definition AView.h:635
void invalidateStateStyles()
Updates state selectors for ASS.
Definition AView.h:839
const glm::ivec2 & getMaxSize() const
Definition AView.h:466
int getTotalOccupiedHeight() const
Definition AView.h:311
emits< glm::ivec2 > mPositionChanged
Position changed.
Definition AView.h:975
emits clickedRight
Right mouse button clicked.
Definition AView.h:925
void setSizeForced(glm::ivec2 size)
Definition AView.h:551
void operator+(ass::PropertyListRecursive rule)
Helper function for kAUI.h:with_style.
Definition AView.h:803
auto visibility() const
Visibility value.
Definition AView.h:146
emits< glm::ivec2 > mSizeChanged
Size changed.
Definition AView.h:985
glm::ivec2 getContentMinimumSize() noexcept
Definition AView.h:436
const glm::ivec2 & getFixedSize()
Fixed size.
Definition AView.h:572
void setExpanding(int expanding)
Changes the expanding of view.
Definition AView.h:509
emits clicked
Left mouse button clicked.
Definition AView.h:900
void setPadding(const ABoxFields &padding)
Sets the padding.
Definition AView.h:370
auto position() const
Top left corner's position relative to top left corner's position of the parent AView.
Definition AView.h:102
glm::ivec2 mMinSize
Minimal size.
Definition AView.h:1002
Definition AWindowBase.h:33
Represents a window in the underlying windowing system.
Definition AWindow.h:45
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:178
AOverflow
Controls visibility of the overflowed contents of AView with AView::drawStencilMask.
Definition AOverflow.h:24
AFloat
Specifies text floating in text wrapping views, i.e, ATextArea, AText.
Definition AFloat.h:19
@ 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 emit
emits the specified signal in context of this object.
Definition AObject.h:310
#define AUI_ASSERTX(condition, what)
Asserts that the passed condition evaluates to true. Adds extra message string.
Definition Assert.h:74
Represents a rectangle fields. Useful for margin and padding around AViews.
Definition ABoxFields.h:21
Property implementation to use with custom getter/setter.
Definition AProperty.h:308
Axis aligned 2D rectangle.
Definition ARect.h:24
Render context passed to AView::render.
Definition ARenderContext.h:43
Defines areas to invalidate (redraw).
Definition IRenderViewToTexture.h:32
Definition PropertyListRecursive.h:24
Definition PropertyList.h:25
Base class for all properties.
Definition IPropertyBase.h:50