Classes

UI

Brief descriptions

Structures

nau::ui::UiManager

Provides basic control over canvases and GUI elements within GUI hierarchy.

Classes

nau::ui::UiNodeAnimator

nau::ui::SymbolFactory

nau::ui::UIControl

Manages GUI element state and input events.

nau::ui::UiComponent

nau::ui::ClippingNode

nau::ui::DrawNode

nau::ui::Layer

nau::ui::Node

Detailed information

ui::UiManager

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

struct UiManager

Provides basic control over canvases and GUI elements within GUI hierarchy.

Public Types

using TElementChangedCallback = eastl::function<void(class Node*)>
using TCanvasLoadedCallback = eastl::function<void(const eastl::string &canvasName)>
using TCallbackHandle = uint32_t

Public Functions

virtual void applicationDidEnterBackground() = 0
virtual void applicationWillEnterForeground() = 0
virtual void update() = 0
virtual void update(float dt) = 0
virtual void render(BaseTexture *backBuffer) = 0
virtual void setAnimationInterval(float interval) = 0
virtual bool shouldShutDown() const = 0
virtual void setScreenSize(float width, float height) = 0
virtual void setReferenceResolution(float width, float height) = 0
virtual void addCanvas(Canvas *canvas) = 0

Adds canvas to the GUI hierarchy.

Parameters:

canvas[in] A pointer to the canvas to add.

virtual Canvas *getCanvas(const eastl::string &canvasName) = 0

Retrieves the canvas from the GUI hierarchy.

Parameters:

canvasName[in] Name of the canvas object to retrieve.

Returns:

A pointer to the requested canvas object or NULL if the canvas has not been found.

virtual void removeCanvas(const eastl::string &canvasName) = 0

Removes the canvas from the GUI hierarchy.

Parameters:

canvasName[in] Name of the canvas to delete.

virtual void updateCanvases() = 0
virtual TCallbackHandle setOnCanvasLoadedCallback(TCanvasLoadedCallback &&callback) = 0
virtual bool setOnCanvasLoadedCallback(TCallbackHandle handle) = 0
virtual void configureResourcePath() = 0
virtual void setEngineScene(scene::IScene::WeakRef scene) = 0
virtual scene::IScene *getEngineScene() = 0
virtual Node *getCanvasChildUnderCursor(const eastl::string &canvasName) = 0

Retrieves a GUI element attached to the canvas that is currently located under the cursor.

Parameters:

canvasName[in] Name of the canvas that the object is attached to.

Returns:

A pointer to the object that the cursor is currenrly pointing at or NULL if the cursor is not currently pointing at anything.

virtual void setElementChangedCallback(nau::Uid elementUid, TElementChangedCallback &&callback) = 0

Sets a function that is called when a GUI element is modified in update.

Warning

This is a debug-only function. Do not use it in release builds.

Parameters:
  • elementUid[in] Identifier of the changed element.

  • callback[in] Callback to assign.

virtual void removeElementChangedCallback(nau::Uid id) = 0

Unbinds the onElementChangedCallback callback.

See setElementChangedCallback.

Parameters:

id[in] Identifier of the element to unbind the callback from.

Public Static Attributes

static const TCallbackHandle INVALID_CB_HANDLE = 0

ui::UiNodeAnimator

engine/core/modules/ui/include/nau/effects/node_animation.h

class UiNodeAnimator : public nau::animation::ITransformAndSkewAnimatable, public nau::animation::IGraphicPropsAnimatable

Public Functions

UiNodeAnimator(nau::ui::Node &node)
virtual void animateTransform(const math::Transform &transform) override
virtual void animateTranslation(const math::vec3 &translation) override
virtual void animateRotation(const math::quat &rotation) override
virtual void animateScale(const math::vec3 &scale) override
virtual void animateSkew(math::vec2 skew) override
virtual void animateColor(const math::Color3 &color) override
virtual void animateOpacity(float opacity) override

Private Members

nau::ui::Node &m_node

ui::SymbolFactory

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

class SymbolFactory

Public Functions

SymbolFactory()
SymbolFactory(const SymbolFactory&) = delete
SymbolFactory &operator=(const SymbolFactory&) = delete
SymbolFactory(SymbolFactory &&other) noexcept
SymbolFactory &operator=(SymbolFactory &&other) noexcept
~SymbolFactory()
void registerProvider(const std::string &fontFileName)
void unRegisterProvider(const std::string &fontFileName)
bool tryGetSymbol (char32_t utf32Code, FontLetterDefinition &symbolDefinition, const std::u32string &font=U"") const
bool hasSymbol (char32_t utf32Code, const std::u32string &font=U"") const
bool warmUpSymbosCache(const eastl::u32string &text) const
cocos2d::Texture2D * getSymbolTexture (int textureId, char32_t utf32Code, const std::u32string &font=U"") const
int *getHorizontalKerning(const eastl::u32string &text, int &outNumLetters) const

Private Functions

std::string getFileExtension(const std::string &fileName) const
std::u32string extractFontName(const std::string &filePath) const
eastl::shared_ptr<ISymbolProvider> getProvider(const std::u32string &fontName) const

Private Members

eastl::vector<eastl::shared_ptr<ISymbolProvider>> m_providers = {}

ui::UIControl

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

class UIControl : public nau::ui::Node

Manages GUI element state and input events.

Subclassed by nau::ui::NauButton, nau::ui::NauScroll, nau::ui::NauSlider

Public Types

using OnPressedCallback = std::function<void(math::vec2 mousePositionLocal)>

A functor type that is called upon EventType::press event triggering.

using OnReleasedCallback = std::function<void()>

A functor type that is called upon EventType::release event triggering.

using OnHoverCallback = std::function<void(math::vec2 mousePositionLocal)>

A functor type that is called upon EventType::hover event triggering.

using OnLeaveCallback = std::function<void()>

A functor type that is called upon EventType::leave event triggering.

using TouchMovedCallback = std::function<void(math::vec2 mousePositionLocal, math::vec2 delta)>

A functor type that is called when the cursor is held and moved within the element borders.

Public Functions

UIControl()

Default constructor.

virtual ~UIControl()

Destructor.

inline FORCEINLINE void setOnPressedCallback (OnPressedCallback cb)

Changes the callback for EventType::press event.

Parameters:

cb[in] Callback to set.

inline FORCEINLINE void setOnReleasedCallback (OnReleasedCallback cb)

Changes the callback for EventType::release event.

Parameters:

cb[in] Callback to set.

inline FORCEINLINE void setOnHoverCallback (OnHoverCallback cb)

Changes the callback for EventType::hover event.

Parameters:

cb[in] Callback to set.

inline FORCEINLINE void setOnLeaveCallback (OnLeaveCallback cb)

Changes the callback for EventType::leave event.

Parameters:

cb[in] Callback to set.

inline FORCEINLINE void setOnTouchMovedCallback (TouchMovedCallback cb)

Changes the callback that is dispatched when the cursor is moved within the element borders.

Parameters:

cb[in] Callback to set.

inline FORCEINLINE void setInputRestrictForChild (bool isRestrict)

Changes whether child interactable area should be restricted to the element area.

If false is passed, then cursor events can be triggered over the entire child area. If true is passed, then cursor events can be triggered only over the part of child area that is inside the parent (this) element area.

Parameters:

isRestrict[in] true if children should be interactable only within the element borders, false otherwise.

virtual void setInteractable(bool interactable)

Changes whether the GUI element can be interacted with (i.e. whether it can trigger cursor events).

Parameters:

interactable[in] Indicates whether the GUI element should be interactable.

virtual bool isInteractable() const

Checks whether the element can be interacted with (i.e. whether it can trigger cursor events).

Returns:

true if the element is interactable, false otherwise.

virtual bool isTouchCaptured() const

Checks whether the element is currently being pressed on (given that it is interactable at the cursor location point).

Returns:

true if the EventType::press is currently being registered, false otherwise.

virtual bool isMouseCaptured() const

Checks whether the element is currently being hovered on (given that it is interactable at the cursor location point).

Returns:

true if the EventType::hover is currently being registered, false otherwise.

virtual void handleEvent(nau::ui::EventType eventType)

This function is called when any cursor event is triggered.

Note

This is a callback with default no-op implementation. Users can provide their own overloads in the custom elemnts implementing UIControl.

Note

Event-specific callbacks (like OnPressed) are called outside this function, so user do not need to call them manually.

Parameters:

eventType[in] Type of the triggered event.

Protected Functions

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

Protected Attributes

OnPressedCallback m_onPressed
OnReleasedCallback m_onReleased
OnHoverCallback m_onHover
OnLeaveCallback m_onLeave
TouchMovedCallback m_touchMovedCallback
bool m_interactable = {true}
bool m_inNeedRestrictInputForChildWidgets = {false}

Private Functions

void addTouchListener()
void releaseTouchListener()
UIControl *getAncestorWidget(Node *node)
bool isInteractableAndVisible(math::vec2 localInputPosition)

Private Members

bool m_touchCaptured = {false}
bool m_mouseCaptured = {false}

ui::UiComponent

engine/core/modules/ui/include/nau/ui/components/ui_component.h

class UiComponent : public nau::scene::SceneComponent, public nau::scene::IComponentEvents, public nau::scene::IComponentActivation

Private Functions

NAU_OBJECT(nau::ui::UiComponent, scene::SceneComponent, scene::IComponentEvents, scene::IComponentActivation) 1 1(1(scene ~UiComponent ()
virtual async::Task activateComponentAsync() override
virtual void deactivateComponent() override

Deactivates the component.

void clearCanvas()

Private Members

mutable UiSceneAssetRef m_uiSceneAsset
mutable double m_width = 800.
mutable double m_height = 600.
Canvas *m_canvas = nullptr
bool m_canvasInScene = false

ui::ClippingNode

engine/core/modules/ui/include/nau/ui/elements/clipping_node.h

class ClippingNode : public nau::ui::Node, protected cocos2d::ClippingNode

Public Functions

Node *getStencil() const
void setStencil(Node *stencil)

Public Static Functions

static ClippingNode *create()

ui::DrawNode

engine/core/modules/ui/include/nau/ui/elements/draw_node.h

class DrawNode : public nau::ui::Node, protected cocos2d::DrawNode

Public Functions

void drawPoint(const math::vec2 &point, const float pointSize, const math::Color4 &color)
void drawPoints(const math::vec2 *position, unsigned int numberOfPoints, const math::Color4 &color)
void drawPoints(const math::vec2 *position, unsigned int numberOfPoints, const float pointSize, const math::Color4 &color)
void drawLine(const math::vec2 &origin, const math::vec2 &destination, const math::Color4 &color)
void drawRect(const math::vec2 &origin, const math::vec2 &destination, const math::Color4 &color)
void drawPoly(const math::vec2 *poli, unsigned int numberOfPoints, bool closePolygon, const math::Color4 &color)
void drawCircle(const math::vec2 &center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY, const math::Color4 &color)
void drawCircle(const math::vec2 &center, float radius, float angle, unsigned int segments, bool drawLineToCenter, const math::Color4 &color)
void drawQuadBezier(const math::vec2 &origin, const math::vec2 &control, const math::vec2 &destination, unsigned int segments, const math::Color4 &color)
void drawCubicBezier(const math::vec2 &origin, const math::vec2 &control1, const math::vec2 &control2, const math::vec2 &destination, unsigned int segments, const math::Color4 &color)
void drawDot(const math::vec2 &pos, float radius, const math::Color4 &color)
void drawRect(const math::vec2 &p1, const math::vec2 &p2, const math::vec2 &p3, const math::vec2 &p4, const math::Color4 &color)
void drawSolidRect(const math::vec2 &origin, const math::vec2 &destination, const math::Color4 &color)
void drawSolidPoly(const math::vec2 *poli, unsigned int numberOfPoints, const math::Color4 &color)
void drawSolidCircle(const math::vec2 &center, float radius, float angle, unsigned int segments, float scaleX, float scaleY, const math::Color4 &color)
void drawSolidCircle(const math::vec2 &center, float radius, float angle, unsigned int segments, const math::Color4 &color)
void drawSegment(const math::vec2 &from, const math::vec2 &to, float radius, const math::Color4 &color)
void drawPolygon(const math::vec2 *verts, int count, const math::Color4 &fillColor, float borderWidth, const math::Color4 &borderColor)
void drawTriangle(const math::vec2 &p1, const math::vec2 &p2, const math::vec2 &p3, const math::Color4 &color)
void clearDrawNode()

Public Static Functions

static DrawNode *create()

ui::Layer

engine/core/modules/ui/include/nau/ui/elements/layer.h

class Layer : public nau::ui::Node, protected cocos2d::Layer

Public Static Functions

static Layer *create()

ui::Node

engine/core/modules/ui/include/nau/ui/elements/node.h

class Node : protected virtual cocos2d::Node

Subclassed by nau::ui::Canvas, nau::ui::ClippingNode, nau::ui::DrawNode, nau::ui::Layer, nau::ui::NauLabel, nau::ui::Sprite, nau::ui::UIControl

Public Functions

Node()
virtual ~Node()
nau::Uid getUid() const
virtual bool initialize()
animation::IAnimationTarget *getAnimator()
animation::AnimationComponent *getAnimationComponent()
virtual void setZOrder(uint32_t order)
virtual uint32_t geZOrder() const
virtual void setScaleX(float scaleX) override
virtual void setScaleY(float scaleY) override
virtual void setScale(float scale) override
virtual void setScale(float scaleX, float scaleY) override
virtual void setPosition(const math::vec2 &position)
virtual math::vec2 getPosition() const
virtual void setPositionX(float x) override
virtual void setPositionY(float y) override
virtual void setSkewX(float skewX) override
virtual void setSkewY(float skewY) override
virtual void setAnchorPoint(const math::vec2 &anchorPoint)
virtual math::vec2 getAnchorPoint() const
virtual void setContentSize(const math::vec2 &contentSize)
virtual math::vec2 getContentSize() const
virtual void setVisible(bool visible) override
virtual void setRotation(float rotation) override
virtual void setRotationSkewX(float rotationX) override
virtual void setRotationSkewY(float rotationY) override
virtual void addChild(Node *child)
virtual void addChild(Node *child, const eastl::string &name)
Node *getNestedNodeByName(const eastl::string &name)
Node *getNestedNodeByUid(nau::Uid uid)
virtual Node *getChildByTag(int tag) const override
virtual Node *getChildByName(const eastl::string &name) const
virtual void getChildren(eastl::vector<Node*> &children) const
virtual Node *getParent()
virtual const Node *getParent() const
virtual void removeChild(Node *child)
virtual void removeAllChildren() override
virtual void reorderChild(Node *child, int zOrder)
virtual void setTag(int tag) override
void nau_setName(const eastl::string &name)
math::vec2 convertToNodeSpace(const math::vec2 &worldPoint) const
math::vec2 convertToWorldSpace(const math::vec2 &nodePoint) const
math::vec2 convertToNodeSpaceAR(const math::vec2 &worldPoint) const
math::vec2 convertToWorldSpaceAR(const math::vec2 &nodePoint) const
virtual void setOpacity(uint8_t opacity) override
virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled) override
virtual nau::math::E3DCOLOR getColor() const
virtual void setColor(const nau::math::E3DCOLOR &color)
virtual void setCascadeColorEnabled(bool cascadeColorEnabled) override
virtual void setOpacityModifyRGB(bool value) override
void callRecursivly(eastl::function<void(Node*)> fn)
void enableDebugDraw(bool isEnable, DebugDrawLevel level = DebugDrawLevel::borders, const math::Color4 &debugColor = {1.0f, 1.0f, 1.0f, 1.0f})
virtual void redrawDebug()

Public Static Functions

static Node *create()
template<class T>
static inline T *cast(Node *node)

Protected Functions

void markDirty()
void markClean()
bool isDirty() const

Protected Attributes

math::Color4 m_debugColor
bool m_isDebugEnable = false
DebugDrawLevel m_debugLevel = DebugDrawLevel::borders

Protected Static Functions

template<std::derived_from<Node> TNode>
static inline TNode *create()

Private Functions

void setUid(nau::Uid uid)
virtual void *getPointer(const std::type_info &t) override
virtual nau::Ptr<UiNodeAnimator> createAnimator()
void addToEngineScene(scene::IScene *scene)
void removeFromEngineScene()

Private Members

nau::Uid m_uid
eastl::unordered_map<uint64_t, nau::ui::Node*> m_childNodesByName
eastl::unordered_map<nau::Uid, nau::ui::Node*> m_childNodesByUid
Ptr<UiNodeAnimator> m_animatorCached
scene::ObjectWeakRef<scene::SceneObject> m_sceneObject

Friends

friend class UiManagerImpl
friend class TestCanvasFitToSize
friend class TestCanvasFitVertically
friend class TestCanvasFitHorizontally
friend class TestCanvasStretch
friend class TestCanvasNoRescale