Lysa UI  0.0
Lysa UI —UI components for the Lysa Engine
FoldableContainer Class Reference

Detailed Description

A container with a clickable title bar folding & unfolding its content.

+ Inheritance diagram for FoldableContainer:

Public Member Functions

 FoldableContainer (const std::string &title="", bool folded=false)
 
const auto & getTitle () const
 
void setTitle (const std::string &title)
 
auto isFolded () const
 
void setFolded (bool folded=true)
 
void toggle ()
 
std::shared_ptr< WidgetaddContent (const std::shared_ptr< Widget > &child, Alignment alignment=Alignment::TOP, const std::string &resource="")
 
template<typename T , typename... Args>
std::shared_ptr< T > createContent (const std::string &resource, const Alignment alignment, Args &&...args)
 
template<typename T , typename... Args>
std::shared_ptr< T > createContent (const Alignment alignment, Args &&...args)
 
void removeContent (const std::shared_ptr< Widget > &child)
 
void removeAllContent ()
 
void setTitleBarHeight (float height)
 
auto getTitleBarHeight () const
 
void setContentHeight (float height)
 
auto getContentHeight () const
 
float getAutoTitleBarHeight () const
 
float getAutoContentHeight () const
 
void updateSize ()
 
auto getTitleBar () const
 
auto getTitleWidget () const
 
auto getArrow () const
 
auto getContent () const
 
void setResources (const std::string &resTitleBar, const std::string &resArrow)
 
- Public Member Functions inherited from Widget
 Widget (Type type=WIDGET)
 
 ~Widget () override
 
Type getType () const
 
bool isVisible () const
 
void setVisible (bool show=true)
 
bool isEnabled () const
 
void setEnabled (bool isEnabled=true)
 
virtual void setPos (float x, float y)
 
float getWidth () const
 
float getHeight () const
 
float getRequestedWidth () const
 
float getRequestedHeight () const
 
virtual void setSize (float width, float height)
 
void setWidth (const float width)
 
void setHeight (const float height)
 
const Rect & getRect () const
 
void setRect (float x, float y, float width, float height)
 
void setRect (const Rect &rect)
 
float getAspectRatio () const
 
Alignment getAlignment () const
 
void setAlignment (Alignment alignment)
 
std::shared_ptr< Font > getFont () const
 
void setFont (const std::shared_ptr< Font > &font)
 
float getFontScale () const
 
virtual void setFontScale (float fontScale)
 
bool isFocused () const
 
Widget * getParent () const
 
void setOverlap (const bool overlap)
 
template<typename T , typename... Args>
std::shared_ptr< T > create (const std::string &resource, const Alignment alignment, Args &&...args)
 
template<typename T , typename... Args>
std::shared_ptr< T > create (const Alignment alignment, Args &&...args)
 
template<typename T >
std::shared_ptr< T > add (std::shared_ptr< T > child, const Alignment alignment=Alignment::NONE, const std::string &resource="", const bool overlap=false)
 
template<typename T >
std::shared_ptr< T > addPopup (std::shared_ptr< T > child, const std::string &resource="")
 
template<typename T >
std::shared_ptr< T > addAfter (std::shared_ptr< T > child, const std::shared_ptr< Widget > &after, const Alignment alignment, const std::string &resource="", const bool overlap=false)
 
virtual void remove (const std::shared_ptr< Widget > &child)
 
virtual void removeAll ()
 
void setPadding (float padding)
 
float getPadding () const
 
float getVBorder () const
 
float getHBorder () const
 
void setVBorder (float size)
 
void setHBorder (float size)
 
bool isDrawBackground () const
 
void setDrawBackground (bool drawBackground)
 
bool isPushed () const
 
bool isPointed () const
 
bool isFreezed () const
 
bool isRedrawOnMouseEvent () const
 
bool isOverlapping () const
 
Rect getChildrenRect () const
 
void setFreezed (const bool f)
 
void setPushed (const bool p)
 
void refresh ()
 
void setResource (std::shared_ptr< UIResource > res)
 
uint32 getGroupIndex () const
 
void setGroupIndex (int32 index)
 
template<typename T >
getUserData () const
 
template<typename T >
std::shared_ptr< T > getPointerUserData () const
 
const std::any & getUserData () const
 
void setUserData (const std::any &data)
 
float getTransparency () const
 
void setTransparency (float alpha)
 
void resizeChildren ()
 
float getChildrenOffsetX () const
 
float getChildrenOffsetY () const
 
void setChildrenOffset (float x, float y)
 
std::shared_ptr< Widget > setFocus (bool focus=true)
 
virtual void onAttach ()
 
virtual void onDetach ()
 
virtual void onShow ()
 
virtual void onHide ()
 
virtual void onResize ()
 
virtual void onMove ()
 
virtual bool onKeyDown (Key key)
 
virtual bool onTextInput (const std::string &text)
 
virtual bool onKeyUp (Key key)
 
virtual bool onMouseDown (MouseButton button, float x, float y)
 
virtual bool onMouseUp (MouseButton button, float x, float y)
 
virtual bool onMouseMove (uint32 buttonsState, float x, float y)
 
virtual void onMouseLeave ()
 
virtual void onDisable ()
 
virtual void onEnable ()
 
virtual void onGotFocus ()
 
virtual void onLostFocus ()
 
bool getConsumeMouseEvent () const
 
void setConsumeMouseEvent (const bool consumeMouseEvent)
 
const std::list< std::shared_ptr< Widget > > & getChildren () const
 
bool hasChildren () const
 
void subscribe (const event_type &type, unique_id id, EventHandlerCallback callback)
 
void subscribe (const event_type &type, EventHandlerCallback callback)
 
void unsubscribe (unique_id id)
 
bool isAttached () const
 
WindowgetWindow () const
 
StylegetStyle () const
 
Vector2DRenderer & getRenderer () const
 
RenderingWindow & getRenderingWindow () const
 
WindowManagergetWindowManager () const
 

Static Public Attributes

static constexpr float DEFAULT_TITLE_BORDER {2.0f}
 Vertical border of the title bar. More...
 

Additional Inherited Members

- Public Types inherited from Widget
enum  Type {
  WIDGET, PANEL, BOX, LINE,
  FRAME, BUTTON, TOGGLEBUTTON, RADIOBUTTON,
  CHECKBOX, CHECKMARK, CROSSMARK, ARROW,
  TEXT, TEXTEDIT, RICHTEXTAREA, SCROLLBAR,
  SLIDER, COLORSLIDER, COLORWHEEL, KNOB,
  TREEVIEW, IMAGE, POPUP, LIST,
  LISTBOX, SELECTION, PROGRESSBAR, SCROLLCONTAINER,
  MENU, MENUPANEL, MENUBOX, TABBAR,
  TABCONTAINER, DIALOG, FOLDABLECONTAINER, COLORPICKER,
  COLORPICKERBUTTON, SPINBOX, SPINBUTTONS, ICONIMAGE,
  ICONSVG, DROPDOWNLIST, TOOLTIP, GRIDCELL,
  GRID, TABLE
}
 
- Protected Attributes inherited from Widget
const Type type
 
Rect rect
 
float requestedWidth {0}
 
float requestedHeight {0}
 
float hborder {0}
 
float vborder {0}
 
float padding {0}
 
bool consumeMouseEvent {false}
 
bool overlap {false}
 
bool focused {false}
 
bool allowFocus {false}
 
bool allowChildren {true}
 
bool drawBackground {true}
 
bool moveChildrenOnPush {false}
 
bool scrollChildren {false}
 
bool skipInvisibleChildren {false}
 
bool redrawOnMouseEvent {false}
 
bool redrawOnMouseMove {false}
 
float transparency {1.0f}
 
Widget * parent {nullptr}
 
Alignment alignment {Alignment::NONE}
 
std::shared_ptr< UIResourceresource
 
std::list< std::shared_ptr< Widget > > children
 
bool mouseMoveOnFocus {false}
 
float childrenOffsetX {0}
 
float childrenOffsetY {0}
 

Constructor & Destructor Documentation

FoldableContainer ( const std::string &  title = "",
bool  folded = false 
)

Creates a container displaying a title bar above its content.

Parameters
titleText of the title bar.
foldedInitial state, true to hide the content.

Member Function Documentation

std::shared_ptr<Widget> addContent ( const std::shared_ptr< Widget > &  child,
Alignment  alignment = Alignment::TOP,
const std::string &  resource = "" 
)

Adds a widget to the content of the container & updates its height.

Parameters
childWidget to add.
alignmentPlacement of the widget inside the content.
resourceResource string.
Returns
The added widget.
std::shared_ptr<T> createContent ( const Alignment  alignment,
Args &&...  args 
)
inline

Creates & adds a widget to the content of the container.

Template Parameters
TThe type of the widget to create.
ArgsThe types of the arguments to pass to the widget constructor.
Parameters
alignmentPlacement of the widget inside the content.
argsThe arguments to pass to the widget constructor.
Returns
The created widget.
std::shared_ptr<T> createContent ( const std::string &  resource,
const Alignment  alignment,
Args &&...  args 
)
inline

Creates & adds a widget to the content of the container.

Template Parameters
TThe type of the widget to create.
ArgsThe types of the arguments to pass to the widget constructor.
Parameters
resourceResource string.
alignmentPlacement of the widget inside the content.
argsThe arguments to pass to the widget constructor.
Returns
The created widget.
auto getArrow ( ) const
inline

Returns the arrow displaying the folded state.

float getAutoContentHeight ( ) const

Returns the height needed to display all the widgets of the content stacked with Alignment::TOP.

float getAutoTitleBarHeight ( ) const

Returns the height needed to display the title.

auto getContent ( ) const
inline

Returns the widget holding the content.

auto getContentHeight ( ) const
inline

Returns the requested height of the content or zero if adjusted to its widgets.

const auto& getTitle ( ) const
inline

Returns the current title of the container.

auto getTitleBar ( ) const
inline

Returns the clickable title bar.

auto getTitleBarHeight ( ) const
inline

Returns the requested height of the title bar or zero if adjusted to the title.

auto getTitleWidget ( ) const
inline

Returns the text widget displaying the title.

auto isFolded ( ) const
inline

Returns true if the content is hidden.

void removeAllContent ( )

Removes all the widgets of the content of the container & updates its height.

void removeContent ( const std::shared_ptr< Widget > &  child)

Removes a widget from the content of the container & updates its height.

void setContentHeight ( float  height)

Sets the height of the content when unfolder or zero to adjust it to the widgets it holds.

void setFolded ( bool  folded = true)

Hides or displays the content & resizes the container.

void setResources ( const std::string &  resTitleBar,
const std::string &  resArrow 
)

Sets the UI resources of the widgets created by the container.

Parameters
resTitleBarResource for the clickable title bar.
resArrowResource for the arrow displaying the folded state.
void setTitle ( const std::string &  title)

Changes the title of the container.

void setTitleBarHeight ( float  height)

Sets the height of the title bar or zero to adjust it to the height of the title.

void toggle ( )
inline

Displays the content if it is hidden & hides it if it is displayed.

void updateSize ( )

Member Data Documentation

constexpr float DEFAULT_TITLE_BORDER {2.0f}
staticconstexpr

Vertical border of the title bar.