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

Detailed Description

A vertical list of text items

+ Inheritance diagram for Menu:

Public Member Functions

 Menu (Type type=MENU)
 
int32 addItem (const std::string &label, const std::string &shortcut="", const std::string &resource="", const std::string &shorcutResource="", const std::shared_ptr< Widget > &leading=nullptr)
 
int32 addSubmenu (const std::string &label, const std::shared_ptr< Menu > &submenu)
 
void addSeparator (const std::string &resource="")
 
void removeAllItems ()
 
int32 getCount () const
 
std::shared_ptr< Text > getItem (int32 index) const
 
std::shared_ptr< Text > getItemShortcut (int32 index) const
 
int32 getItemAt (float x, float y) const
 
void highlight (int32 index)
 
auto getHighlighted () const
 
void setItemPadding (const float padding)
 
auto getItemPadding () const
 
float getContentHeight () const
 
float getContentWidth () const
 
void setResources (const std::string &resSeparator, const std::string &resHighlight)
 
bool eventMouseDown (MouseButton button, float x, float y) override
 
bool eventMouseMove (uint32 buttonsState, float x, float y) override
 
void eventResize () override
 
void eventHide () override
 
void eventDetach () 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
 
Rect getScreenRect () 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)
 
void setLayoutDirection (TextDirection direction)
 
TextDirection getLayoutDirection () const
 
TextDirection getEffectiveLayoutDirection () const
 
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
 
bool isFocusable () const
 
bool isTabStop () const
 
void setTabStop (const bool tabStop)
 
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 >
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 subscribe (const event_type &type, SignalHandlerCallback callback)
 
void unsubscribe (unique_id id)
 
virtual void eventAttach ()
 
virtual void eventShow ()
 
virtual void eventAspectRatioChanged ()
 
virtual void eventEnable ()
 
virtual void eventDisable ()
 
virtual void eventMove (float x, float y)
 
virtual bool eventTextInput (const std::string &text)
 
virtual bool eventKeyDown (Key key)
 
virtual bool eventKeyUp (Key key)
 
virtual bool eventMouseUp (MouseButton button, float x, float y)
 
virtual void eventMouseLeave ()
 
virtual void eventGotFocus ()
 
virtual void eventLostFocus ()
 
bool isAttached () const
 
Window & getWindow () const
 
Style & getStyle () const
 
Vector2DRenderer & getRenderer () const
 
RenderingWindow & getRenderingWindow () const
 
WindowManager & getWindowManager () const
 
bool isCustomDraw () const
 
virtual void draw (UIResource &resources, Vector2DRenderer &renderer, bool stage) const
 
void skipInvisibleChildren (const bool s)
 

Static Public Attributes

static constexpr int32 NO_ITEM {-1}
 Nno item is highlighted or no item is at a given position. More...
 
static constexpr int32 HIGHLIGHT_PADDING {1}
 Default padding applied at the left & right of separators & hightlights. More...
 
static constexpr float DEFAULT_ITEM_PADDING {4.0f}
 Space between the borders of an item & its text. 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, RULER, 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, RADIALPIEMENU,
  NUMBEREDIT
}
 
- 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 tabStop {true}
 
bool allowChildren {true}
 
bool drawBackground {true}
 
bool moveChildrenOnPush {false}
 
bool scrollChildren {false}
 
bool skipInvisibleChildrenEnabled {false}
 
bool redrawOnMouseEvent {false}
 
bool redrawOnMouseMove {false}
 
bool customDraw {false}
 
float transparency {1.0f}
 
Widget * parent {nullptr}
 
Alignment alignment {Alignment::NONE}
 
TextDirection layoutDirection {TextDirection::AUTO}
 
std::shared_ptr< UIResource > resource
 
std::list< std::shared_ptr< Widget > > children
 
bool mouseMoveOnFocus {false}
 
float childrenOffsetX {0}
 
float childrenOffsetY {0}
 

Constructor & Destructor Documentation

Menu ( Type  type = MENU)

Member Function Documentation

int32 addItem ( const std::string &  label,
const std::string &  shortcut = "",
const std::string &  resource = "",
const std::string &  shorcutResource = "",
const std::shared_ptr< Widget > &  leading = nullptr 
)

Adds an item at the end of the menu.

Parameters
labelText of the item.
shortcutOptional text displayed right aligned, for a keyboard shortcut.
resourceResource string for the item.
shorcutResourceResource string for the shortcut.
leadingOptional widget displayed at the left of the text, like a check mark or a radio button.
Returns
The index (0-based) of the added item, separators excluded.
void addSeparator ( const std::string &  resource = "")

Adds a line separating the previous items from the next ones.

int32 addSubmenu ( const std::string &  label,
const std::shared_ptr< Menu > &  submenu 
)

Adds an item opening a submenu on click without emitting OnSelectItem.

void eventDetach ( )
overridevirtual

Raw detach event, see onDetach

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

void eventHide ( )
overridevirtual

Raw hide event, see onHide

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

bool eventMouseDown ( MouseButton  button,
float  x,
float  y 
)
overridevirtual

Raw mouse down event, see onMouseDown

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

bool eventMouseMove ( uint32  buttonsState,
float  x,
float  y 
)
overridevirtual

Raw mouse move event, see onMouseMove

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

void eventResize ( )
overridevirtual

Raw resize event, see onResize

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

float getContentHeight ( ) const

Returns the height needed to display all the items & separators.

float getContentWidth ( ) const

Returns the width needed to display the widest item shortcut included.

int32 getCount ( ) const
inline

Returns the number of items, separators excluded.

auto getHighlighted ( ) const
inline

Returns the index of the highlighted item or NO_ITEM.

std::shared_ptr<Text> getItem ( int32  index) const

Returns the text widget of an item or nullptr for an invalid index.

int32 getItemAt ( float  x,
float  y 
) const

Returns the index of the item at a given position or NO_ITEM.

auto getItemPadding ( ) const
inline

Returns the space between the borders of an item & its text.

std::shared_ptr<Text> getItemShortcut ( int32  index) const

Returns the shortcut text widget of an item or nullptr if the item have no shortcut.

void highlight ( int32  index)

Highlights an item, passing NO_ITEM removes the highlight.

void removeAllItems ( )

Removes all the items & separators.

void setItemPadding ( const float  padding)
inline

Sets the space between the borders of an item & its text

void setResources ( const std::string &  resSeparator,
const std::string &  resHighlight 
)

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

Parameters
resSeparatorResource for the separator lines.
resHighlightResource for the highlight of the item under the mouse.

Member Data Documentation

constexpr float DEFAULT_ITEM_PADDING {4.0f}
staticconstexpr

Space between the borders of an item & its text.

constexpr int32 HIGHLIGHT_PADDING {1}
staticconstexpr

Default padding applied at the left & right of separators & hightlights.

constexpr int32 NO_ITEM {-1}
staticconstexpr

Nno item is highlighted or no item is at a given position.