Simple GUI Library
Sgl::AnchorPane Class Reference

Allows the edges of components to be anchored to anchor pane's edges. More...

#include <anchor_pane.h>

Inheritance diagram for Sgl::AnchorPane:
Collaboration diagram for Sgl::AnchorPane:

Classes

struct  Anchors
 
struct  Constraints
 

Public Member Functions

Constraints getConstraints (Component *child) const
 
bool hasConstraints (Component *child) const
 
void setHorizontalRelativePositioning (Component *child, bool enabled)
 
void setVerticalRelativePositioning (Component *child, bool enabled)
 
bool isHorizontalRelativePositioning (Component *child) const
 
bool isVerticalRelativePositioning (Component *child) const
 
void setTopAnchor (Component *child, int32_t anchor)
 
void setRightAnchor (Component *child, int32_t anchor)
 
void setBottomAnchor (Component *child, int32_t anchor)
 
void setLeftAnchor (Component *child, int32_t anchor)
 
int32_t getTopAnchor (Component *child) const
 
int32_t getRightAnchor (Component *child) const
 
int32_t getBottomAnchor (Component *child) const
 
int32_t getLeftAnchor (Component *child) const
 
- Public Member Functions inherited from Sgl::LayeredContainer
bool isAutoAdjust () const
 
void setAutoAdjust (bool autoAdjust)
 
void moveToFront (Component *child)
 
void moveToBack (Component *child)
 
ComponentgetFront ()
 
ComponentgetBack ()
 
- Public Member Functions inherited from Sgl::Container
virtual ComponentgetHitComponent (int32_t x, int32_t y) override
 
virtual void render (const Sml::Rectangle< int32_t > &targetRegion) override
 
- Public Member Functions inherited from Sgl::Parent
virtual void layout () override final
 
virtual void prerender () override final
 
virtual bool containsComponent (Component *component) override final
 
virtual bool isResizable () const override
 
void addChild (Component *child)
 Convenience method for adding a child to Parent. More...
 
void addChildren ()
 
template<typename Head , typename... Tail>
void addChildren (Head head, Tail... tail)
 Convenience method for adding multiple children to Parent. More...
 
void removeChild (Component *child)
 Convenience method for removing a child to Parent. More...
 
void removeChildren ()
 
std::list< Component * > & getChildren ()
 
const std::list< Component * > & getChildrenReadonly () const
 
Sml::Texture * getSnapshot ()
 
bool needLayoutPass () const
 
void requestLayoutPass ()
 
const BackgroundgetBackground () const
 
void setBackground (const Background *background)
 
const BordergetBorder () const
 
void setBorder (const Border *border)
 
Insets getInsets () const
 
Sml::Rectangle< int32_t > getContentArea () const
 
Insets getPadding () const
 
void setPadding (const Insets &padding)
 
void setPrefWidth (int32_t width)
 
void setPrefHeight (int32_t height)
 
void setMinWidth (int32_t width)
 
void setMinHeight (int32_t height)
 
void setMaxWidth (int32_t width)
 
void setMaxHeight (int32_t height)
 
int32_t getPrefWidth () const
 
int32_t getPrefHeight () const
 
int32_t getMinWidth () const
 
int32_t getMinHeight () const
 
int32_t getMaxWidth () const
 
int32_t getMaxHeight () const
 
virtual int32_t computePrefWidth (int32_t height=-1) const override final
 
virtual int32_t computePrefHeight (int32_t width=-1) const override final
 
virtual int32_t computeMinWidth (int32_t height=-1) const override final
 
virtual int32_t computeMinHeight (int32_t width=-1) const override final
 
virtual int32_t computeMaxWidth (int32_t height=-1) const override final
 
virtual int32_t computeMaxHeight (int32_t width=-1) const override final
 
- Public Member Functions inherited from Sgl::Component
virtual Sml::EventDispatchChain * buildEventDispatchChain (Sml::EventDispatchChain *chain) override
 
bool isVisible () const
 
void setVisible (bool visible)
 
bool isInteractable () const
 
void setInteractable (bool interactable)
 
Visibility getVisibility () const
 
void setVisibility (Visibility visibility)
 
bool isFocused () const
 
bool isHovered () const
 
void requestFocus ()
 
void requestDrag ()
 
const ShadowgetShadow () const
 
void setShadow (const ShadowSpecification *specification)
 
GuiEventDispatchergetEventDispatcher ()
 
ScenegetScene ()
 
void setScene (Scene *scene)
 
const ParentgetParent () const
 
ParentgetModifiableParent ()
 
void setParent (Parent *parent)
 
Sml::Vec2i computeLocalToScenePos (const Sml::Vec2i &localPos) const
 
Sml::Vec2i computeSceneToLocalPos (const Sml::Vec2i &scenePos) const
 
Sml::Rectangle< int32_t > getOriginBounds () const
 
const Sml::Rectangle< int32_t > & getLayoutBounds () const
 
const Sml::Vec2i & getLayoutPos () const
 
int32_t getLayoutX () const
 
int32_t getLayoutY () const
 
int32_t getLayoutWidth () const
 
int32_t getLayoutHeight () const
 
void setLayoutX (int32_t x)
 
void setLayoutY (int32_t y)
 
void setLayoutWidth (int32_t width)
 
void setLayoutHeight (int32_t height)
 
Sml::Vec2i computeScenePos ()
 

Static Public Attributes

static constexpr int32_t ANCHOR_NOT_ENABLED = -1
 
- Static Public Attributes inherited from Sgl::Container
static const ColorFill DEFAULT_FILL = ColorFill{Sml::COLOR_WHITE}
 
static const Background DEFAULT_BACKGROUND = Background{&Container::DEFAULT_FILL}
 
- Static Public Attributes inherited from Sgl::Component
static const int32_t USE_COMPUTED_SIZE = INT32_MIN
 
static const int32_t UNLIMITED_SIZE = INT32_MAX
 

Additional Inherited Members

- Public Types inherited from Sgl::Component
enum class  Visibility { INVISIBLE_DISABLED = 0b00 , INVISIBLE_INTERACTABLE = 0b01 , VISIBLE_DISABLED = 0b10 , VISIBLE_INTERACTABLE = 0b11 }
 Used to determine if Component should be rendered and targeted by events. More...
 
- Public Attributes inherited from Sgl::Component
friend Scene
 
- Protected Member Functions inherited from Sgl::Container
virtual void prerenderSelf () override
 
- Protected Member Functions inherited from Sgl::Parent
virtual void setSceneInSceneTree (Scene *scene) override final
 
void updateSnapshotSize ()
 
virtual int32_t computeCustomMaxWidth (int32_t height=-1) const
 
virtual int32_t computeCustomMaxHeight (int32_t width=-1) const
 
- Protected Member Functions inherited from Sgl::Component
void updateShadow ()
 
void renderShadow (const Sml::Rectangle< int32_t > &targetRegion)
 
- Protected Attributes inherited from Sgl::Parent
std::list< Component * > m_Children
 
Sml::Texture * m_Snapshot = nullptr
 
bool m_NeedLayoutPass = false
 
const Backgroundm_Background = nullptr
 
const Borderm_Border = nullptr
 
Insets m_Padding = Insets::EMPTY
 
int32_t m_PrefWidth = USE_COMPUTED_SIZE
 
int32_t m_PrefHeight = USE_COMPUTED_SIZE
 
int32_t m_MinWidth = USE_COMPUTED_SIZE
 
int32_t m_MinHeight = USE_COMPUTED_SIZE
 
int32_t m_MaxWidth = USE_COMPUTED_SIZE
 
int32_t m_MaxHeight = USE_COMPUTED_SIZE
 
- Protected Attributes inherited from Sgl::Component
Visibility m_Visibility = Visibility::VISIBLE_INTERACTABLE
 
bool m_Focused = false
 
bool m_Hovered = false
 
Shadow m_Shadow
 
GuiEventDispatcher m_Dispatcher
 
Scenem_Scene = nullptr
 
Parentm_Parent = nullptr
 
Sml::Rectangle< int32_t > m_LayoutBounds = {{0, 0}, 0, 0}
 

Detailed Description

Allows the edges of components to be anchored to anchor pane's edges.

You can set constraints for a child using set<Side>Anchor() method, which accepts an integer offset. This child's <Side> will be anchored to the pane's <Side> with this offset.

If offset is equal to ANCHOR_NOT_ENABLED, then it is interpreted as there's no anchor attached to this edge.

You can use setHorizontalRelative() or setVerticalRelative() methods to enable relative offsets. This means that the enabled offsets (if one of the opposite offsets is not enabled, then does nothing) are interpreted as integer weights of respective offsets. In this case the child is set to its preffered size in this direction, and the free space in this direction is split according to weighted offsets. For example, imagine that anchor pane's height is set to 1280, child's preffered height is 280 and the top and bottom anchors are equal to 1 and 4 respectively. In this case the free vertical 1000 pixels will be split as following: absolute top offset = 1000 * 1 / (1 + 4) = 200, absolute bottom offset = 1000 * 4 / (1 + 4) = 800.

Definition at line 37 of file anchor_pane.h.

Member Function Documentation

◆ getBottomAnchor()

int32_t Sgl::AnchorPane::getBottomAnchor ( Component child) const

Definition at line 113 of file anchor_pane.cpp.

◆ getConstraints()

AnchorPane::Constraints Sgl::AnchorPane::getConstraints ( Component child) const

Definition at line 32 of file anchor_pane.cpp.

◆ getLeftAnchor()

int32_t Sgl::AnchorPane::getLeftAnchor ( Component child) const

Definition at line 118 of file anchor_pane.cpp.

◆ getRightAnchor()

int32_t Sgl::AnchorPane::getRightAnchor ( Component child) const

Definition at line 108 of file anchor_pane.cpp.

◆ getTopAnchor()

int32_t Sgl::AnchorPane::getTopAnchor ( Component child) const

Definition at line 103 of file anchor_pane.cpp.

◆ hasConstraints()

bool Sgl::AnchorPane::hasConstraints ( Component child) const

Definition at line 45 of file anchor_pane.cpp.

◆ isHorizontalRelativePositioning()

bool Sgl::AnchorPane::isHorizontalRelativePositioning ( Component child) const

Definition at line 73 of file anchor_pane.cpp.

◆ isVerticalRelativePositioning()

bool Sgl::AnchorPane::isVerticalRelativePositioning ( Component child) const

Definition at line 78 of file anchor_pane.cpp.

◆ setBottomAnchor()

void Sgl::AnchorPane::setBottomAnchor ( Component child,
int32_t  anchor 
)

Definition at line 93 of file anchor_pane.cpp.

◆ setHorizontalRelativePositioning()

void Sgl::AnchorPane::setHorizontalRelativePositioning ( Component child,
bool  enabled 
)

Definition at line 63 of file anchor_pane.cpp.

◆ setLeftAnchor()

void Sgl::AnchorPane::setLeftAnchor ( Component child,
int32_t  anchor 
)

Definition at line 98 of file anchor_pane.cpp.

◆ setRightAnchor()

void Sgl::AnchorPane::setRightAnchor ( Component child,
int32_t  anchor 
)

Definition at line 88 of file anchor_pane.cpp.

◆ setTopAnchor()

void Sgl::AnchorPane::setTopAnchor ( Component child,
int32_t  anchor 
)

Definition at line 83 of file anchor_pane.cpp.

◆ setVerticalRelativePositioning()

void Sgl::AnchorPane::setVerticalRelativePositioning ( Component child,
bool  enabled 
)

Definition at line 68 of file anchor_pane.cpp.

Member Data Documentation

◆ ANCHOR_NOT_ENABLED

constexpr int32_t Sgl::AnchorPane::ANCHOR_NOT_ENABLED = -1
staticconstexpr

Definition at line 40 of file anchor_pane.h.


The documentation for this class was generated from the following files: