Classes

UI/Scroll

Brief descriptions

Classes

nau::ui::NauScroll

Encapsulates scroll GUI element which allows to scroll through a collection of its children either horizontally or verticall using a scroll bar.

Detailed information

ui::NauScroll

engine/core/modules/ui/include/nau/ui/scroll.h

class NauScroll : public nau::ui::UIControl

Encapsulates scroll GUI element which allows to scroll through a collection of its children either horizontally or verticall using a scroll bar.

Public Types

enum class ScrollType

Enumerates scrolling directions.

Values:

enumerator vertical
enumerator horizontal

Public Functions

NauScroll()

Default constructor.

virtual ~NauScroll()

Default destructor.

inline FORCEINLINE Sprite * getScrollBarSprite ()

Retrieves the scroll bar sprite.

Returns:

A pointer to scroll bar sprite.

NauScroll::ScrollType getScrollType()
void setScrollType(NauScroll::ScrollType scrollType)
virtual void addChild(Node *contentNode) override

Attaches a child GUI object to the scroll.

Parameters:

contentNode[in] A pointer to the object to attach.

void addChildWithAlignment(Node *contentNode)

Attaches a child GUI object to the scroll and performs necessary resizing and allignment according to the scrolling direction.

Parameters:

contentNode[in] A pointer to the object to attach.

virtual void removeChild(Node *contentNode) override

Detaches the GUI element from the scroll.

Parameters:

contentNode[in] A pointer to the object to detach.

void removeChildWithAlignment(Node *contentNode)

Detaches the GUI element from the scroll and performs necessary resizing and allignment according to the scrolling direction.

virtual void setContentSize(const math::vec2 &contentSize) override

Resizes the content area of the scroll.

Calling this method also resizes the clipping area of the scroll and aligns its content by the scroll center. Should you wish to provide different resize/alignment logic, address to setContentRootSize method.

Parameters:

contentSize[in] Size to set the scroll content to.

void setContentRootSize(const math::vec2 &contentSize)

Resizes the content area of the scroll.

Note

Users should apply some external logic for clipping and aligning the content when using this method to resize the scroll.

Parameters:

contentSize[in] Size to set the scroll content to.

math::vec2 getContentRootSize()
math::vec2 getContentRootPosition()
void addScrollBarSprite(const std::string &filePath)

Changes the sprite of the scroll bar.

Parameters:

Path[in] to the image file to construct sprite from.

void addScrollBarSprite(Sprite *sprite)

Changes the sprite of the scroll bar.

Parameters:

sprite[in] A pointer to the sprite to use.

void moveTo(Node *contentNode)

Scrolls the bar to the specified GUI element.

Parameters:

contentNode[in] A pointer to the element to scroll to. It has to be a child of the scroll.

void moveTo(float x, float y)

Scrolls the bar to the specified position.

Parameters:

x, y[in] Position to scroll the bar to.

void moveScroll(const math::vec2 &delta)

Scrolls the bar by the specified offset.

Parameters:

delta[in] Offset to scroll the bar by.

virtual void redrawDebug() override

Draws outline around scroll content.

Public Static Functions

static NauScroll *create(NauScroll::ScrollType srollType)

Creates a scroll element.

Parameters:

scrollType[in] Scrolling direction.

Returns:

A pointer to the created scroll object.

static NauScroll *create(NauScroll::ScrollType srollType, const math::vec2 &size)

Creates a scroll element.

Parameters:
  • scrollType[in] Scrolling direction.

  • size[in] Scroll size.

Returns:

A pointer to the created scroll object.

Public Static Attributes

static const int CLIPPER_TAG

Protected Functions

virtual bool initialize() override
virtual bool isInputEventInElementBorder(math::vec2 inputPosition) override

Private Functions

void onScrollMovedByWheel(const math::vec2 &delta)
void onScrollMovedByDrag(const math::vec2 &delta)
void onScrollMovedByScrollBar(const math::vec2 &delta)
void addChildAsHorizontally(Node *contentNode)
void addChildAsVertically(Node *contentNode)
void removeChildAsHorizontally(Node *contentNode)
void removeChildAsVertically(Node *contentNode)
void reorderChildAsVertically()
void reorderChildAsHorizontally()
void moveToHorizontally(Node *contentNode)
void moveToVertically(Node *contentNode)
void moveToHorizontally(float x)
void moveToVertically(float y)
void updateScrollBarSpritePosition()
bool isInputEventInScrollBarButtonBorder(math::vec2 inputPosition)

Private Members

Node *m_contentRoot = {nullptr}
eastl::vector<Node*> m_content = {}
NauScroll::ScrollType m_scrollType = {NauScroll::ScrollType::vertical}
Sprite *m_scrollBarSprite = {nullptr}
bool m_scrollTumbCaptured = {false}