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

Detailed Description

A button displaying the selected item of a list of labels, opening a popup list to select another one.

+ Inheritance diagram for DropDownList:

Public Member Functions

 DropDownList (const std::vector< std::string > &items={}, int32 selected=NO_ITEM)
 
int32 addItem (const std::string &label)
 
void setItems (const std::vector< std::string > &items, const std::string &selected={})
 
void removeAllItems ()
 
int32 getCount () const
 
const auto & getItems () const
 
std::string getItem (int32 index) const
 
int32 indexOf (const std::string &label) const
 
auto getSelectedIndex () const
 
std::string getSelectedItem () const
 
void select (int32 index)
 
void select (const std::string &label)
 
const auto & getPlaceHolder () const
 
void setPlaceHolder (const std::string &label)
 
void open ()
 
void close ()
 
bool isOpen () const
 
auto getMaxDisplayedItems () const
 
void setMaxDisplayedItems (const int32 count)
 
auto getArrowWidth () const
 
void setArrowWidth (float width)
 
auto getButton () const
 
auto getLabel () const
 
auto getArrow () const
 
const auto & getListResource () const
 
void setListResource (const std::string &resource)
 
void setResources (const std::string &resButton, const std::string &resArrow, const std::string &resList)
 
void onDetach () override
 
void onHide () override
 
- 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 onShow ()
 
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_ITEM {-1}
 No item is selected or no item have a given label. More...
 
static constexpr float DEFAULT_ARROW_WIDTH {16.0f}
 Default width of the column of the arrow, at the right of the label. More...
 
static constexpr int32 DEFAULT_MAX_DISPLAYED_ITEMS {10}
 Default maximum number of items displayed at once by the opened list. More...
 
static constexpr float DEFAULT_ITEM_PADDING {4.0f}
 Default space between the borders of the items & their labels. 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

DropDownList ( const std::vector< std::string > &  items = {},
int32  selected = NO_ITEM 
)

Creates a drop-down list.

Parameters
itemsLabels of the items, in display order.
selectedIndex of the selected item or NO_ITEM.

Member Function Documentation

int32 addItem ( const std::string &  label)

Adds an item at the end of the list.

Returns
The index (0-based) of the added item.
void close ( )

Closes the popup list.

auto getArrow ( ) const
inline

Returns the arrow displayed at the right of the label.

auto getArrowWidth ( ) const
inline

Returns the width of the column of the arrow.

auto getButton ( ) const
inline

Returns the button displaying the selected item.

int32 getCount ( ) const
inline

Returns the number of items.

std::string getItem ( int32  index) const

Returns the label of an item or an empty string for an invalid index.

const auto& getItems ( ) const
inline

Returns the labels of all the items.

auto getLabel ( ) const
inline

Returns the widget displaying the label of the selected item.

const auto& getListResource ( ) const
inline

Returns the resource string of the popup list.

auto getMaxDisplayedItems ( ) const
inline

Returns the maximum number of items displayed at once by the opened list.

const auto& getPlaceHolder ( ) const
inline

Returns the text displayed when no item is selected.

auto getSelectedIndex ( ) const
inline

Returns the index of the selected item or NO_ITEM.

std::string getSelectedItem ( ) const
inline

Returns the label of the selected ite, or an empty string.

int32 indexOf ( const std::string &  label) const

Returns the index of the first item with a given label or NO_ITEM.

bool isOpen ( ) const
inline

Returns true if the popup list is currently displayed.

void onDetach ( )
overridevirtual

Event called before Widget is detached from its parent.

Reimplemented from lysa::ui::Widget::onDetach()

void onHide ( )
overridevirtual

Event called when (after) the Window manager need to hide the Window.

Reimplemented from lysa::ui::Widget::onHide()

void open ( )

Opens the popup list.

void removeAllItems ( )

Removes all the items, closing the list if it is opened.

void select ( const std::string &  label)
inline

Selects the first item with a given label if any.

void select ( int32  index)

Selects an item NO_ITEM to select nothing.

void setArrowWidth ( float  width)

Changes the width of the column of the arrow.

void setItems ( const std::vector< std::string > &  items,
const std::string &  selected = {} 
)

Replaces all the items & the selection, closing the list if it is opened.

The selection is changed silently : no UIEvent::OnSelectItem event is pushed.

Parameters
itemsLabels of the items, in display order.
selectedLabel of the selected item, empty to select nothing.
void setListResource ( const std::string &  resource)
inline

Changes the resource string of the popup list, applied the next time it is opened.

void setMaxDisplayedItems ( const int32  count)
inline

Changes the maximum number of items displayed at once by the opened list.

void setPlaceHolder ( const std::string &  label)

Changes the text displayed when no item is selected.

void setResources ( const std::string &  resButton,
const std::string &  resArrow,
const std::string &  resList 
)

Sets the UI resources of the widgets created by the drop-down list.

Parameters
resButtonResource for the button displaying the selected item.
resArrowResource for the arrow displayed at the right of the label.
resListResource for the popup list.

Member Data Documentation

constexpr float DEFAULT_ARROW_WIDTH {16.0f}
staticconstexpr

Default width of the column of the arrow, at the right of the label.

constexpr float DEFAULT_ITEM_PADDING {4.0f}
staticconstexpr

Default space between the borders of the items & their labels.

constexpr int32 DEFAULT_MAX_DISPLAYED_ITEMS {10}
staticconstexpr

Default maximum number of items displayed at once by the opened list.

constexpr int32 NO_ITEM {-1}
staticconstexpr

No item is selected or no item have a given label.