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

Detailed Description

A horizontal bar of tabs. The bar only draws & selects the tabs.

+ Inheritance diagram for TabBar:

Classes

struct  Tab
 

Public Member Functions

 TabBar (TabPlacement placement=TabPlacement::TOP)
 
int32 addTab (const std::string &label, const std::string &resource="", const std::shared_ptr< Widget > &leading=nullptr, const std::shared_ptr< Widget > &trailing=nullptr)
 
int32 addTab (const std::shared_ptr< Widget > &label, const std::string &resource="", const std::shared_ptr< Widget > &leading=nullptr, const std::shared_ptr< Widget > &trailing=nullptr)
 
void removeTab (int32 index)
 
void removeAllTabs ()
 
int32 getCount () const
 
const auto & getTabs () const
 
template<typename T = Text>
std::shared_ptr< T > getTab (int32 index) const
 
int32 getTabAt (float x, float y) const
 
void select (int32 index)
 
auto getSelected () const
 
auto getPointed () const
 
void setTabPadding (const float padding)
 
auto getTabPadding () const
 
float getContentWidth () const
 
float getContentHeight () const
 
void setPlacement (TabPlacement placement)
 
auto getPlacement () const
 
void setResources (const std::string &resPointed)
 
- 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 int32 NO_TAB {-1}
 No tab is selected or pointed, or no tab is at a given position. More...
 
static constexpr float DEFAULT_TAB_PADDING {6.0f}
 Space between the borders of a tab & its content. 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

TabBar ( TabPlacement  placement = TabPlacement::TOP)

Creates an empty tab bar.

Member Function Documentation

int32 addTab ( const std::shared_ptr< Widget > &  label,
const std::string &  resource = "",
const std::shared_ptr< Widget > &  leading = nullptr,
const std::shared_ptr< Widget > &  trailing = nullptr 
)

Adds a tab at the right of the last tab.

The first tab added is selected without emitting UIEvent::OnSelectItem.

Parameters
labelWidget displayed by the tab, like an icon or a text.
resourceResource string for the label of the tab.
leadingOptional widget displayed at the left of the label, like an icon.
trailingOptional widget displayed at the right of the label, like a closing cross.
Returns
The index (0-based) of the added tab.
int32 addTab ( const std::string &  label,
const std::string &  resource = "",
const std::shared_ptr< Widget > &  leading = nullptr,
const std::shared_ptr< Widget > &  trailing = nullptr 
)

Adds a tab at the right of the last tab.

The first tab added is selected without emitting UIEvent::OnSelectItem.

Parameters
labelText of the tab.
resourceResource string for the text of the tab.
leadingOptional widget displayed at the left of the text, like an icon.
trailingOptional widget displayed at the right of the text, like a closing cross.
Returns
The index (0-based) of the added tab.
float getContentHeight ( ) const

Returns the height needed to display the highest tab.

float getContentWidth ( ) const

Returns the width needed to display all the tabs.

int32 getCount ( ) const
inline

Returns the number of tabs.

auto getPlacement ( ) const
inline

Returns the position of the bar relatively to the content displayed by the tabs.

auto getPointed ( ) const
inline

Returns the index of the tab below the mouse cursor or NO_TAB.

auto getSelected ( ) const
inline

Returns the index of the selected tab or NO_TAB.

std::shared_ptr< T > getTab ( int32  index) const

Returns the text widget of a tab, or nullptr for an invalid index.

int32 getTabAt ( float  x,
float  y 
) const

Returns the index of the tab at a given position or NO_TAB.

auto getTabPadding ( ) const
inline

Returns the space between the borders of a tab & its content.

const auto& getTabs ( ) const
inline

Returns the tabs, in display order.

void removeAllTabs ( )

Removes all the tabs, without emitting UIEvent::OnSelectItem.

void removeTab ( int32  index)

Removes the tab at a given index.

Removing the selected tab selects the next one, or the previous one for the last tab, and emits UIEvent::OnSelectItem.

void select ( int32  index)

Selects a tab, NO_TAB or an invalid index removes the selection.

void setPlacement ( TabPlacement  placement)

Sets the position of the bar relatively to the content displayed by the tabs.

void setResources ( const std::string &  resPointed)
inline

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

Parameters
resPointedResource for the highlights displayed behind the leading & trailing widgets when the mouse is above them.
void setTabPadding ( const float  padding)
inline

Sets the space between the borders of a tab & its content.

Member Data Documentation

constexpr float DEFAULT_TAB_PADDING {6.0f}
staticconstexpr

Space between the borders of a tab & its content.

constexpr int32 NO_TAB {-1}
staticconstexpr

No tab is selected or pointed, or no tab is at a given position.