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

Detailed Description

A modal dialog box centered above its parent widget.

+ Inheritance diagram for DialogBox:

Public Member Functions

 DialogBox (const std::string &title, const std::vector< std::string > &buttons={}, float width=DEFAULT_WIDTH, float height=DEFAULT_HEIGHT)
 
const auto & getTitle () const
 
void setTitle (const std::string &title)
 
auto getTitleWidget () const
 
WidgetgetContent () const
 
int32 getCount () const
 
std::shared_ptr< ButtongetButton (int32 index) const
 
std::shared_ptr< TextgetButtonText (int32 index) const
 
void setDefaultButton (const int32 index)
 
auto getDefaultButton () const
 
void setCancelButton (const int32 index)
 
auto getCancelButton () const
 
void setButtonSize (const float width, const float height)
 
void select (int32 index) const
 
void setResources (const std::string &resBox, const std::string &resSeparator, const std::string &resButton)
 
- 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_BUTTON {-1}
 No button is associated with a keyboard key. More...
 
static constexpr float DEFAULT_WIDTH {300.0f}
 Default width of the dialog box. More...
 
static constexpr float DEFAULT_HEIGHT {160.0f}
 Default height of the dialog box. More...
 
static constexpr float DEFAULT_BUTTON_WIDTH {90.0f}
 Default width of the buttons. More...
 
static constexpr float DEFAULT_BUTTON_HEIGHT {30.0f}
 Default height of the buttons. More...
 
static constexpr float DEFAULT_PADDING {4.0f}
 Default space between the borders of the dialog & its content. More...
 
static constexpr float DEFAULT_BUTTON_PADDING {4.0f}
 Default padding inside the buttons. 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

DialogBox ( const std::string &  title,
const std::vector< std::string > &  buttons = {},
float  width = DEFAULT_WIDTH,
float  height = DEFAULT_HEIGHT 
)

Creates a dialog box.

Parameters
titleText displayed at the top of the dialog.
buttonsLabels of the buttons, displayed left to right.
widthWidth of the dialog box, reduced if the parent is too small.
heightHeight of the dialog box, reduced if the parent is too small.

Member Function Documentation

std::shared_ptr<Button> getButton ( int32  index) const

Returns the button of a given index or nullptr for an invalid index.

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

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

auto getCancelButton ( ) const
inline

Returns the index of the button activated by the ESCAPE key or NO_BUTTON.

Widget& getContent ( ) const

Returns the widget the application fills with the content of the dialog.

int32 getCount ( ) const
inline

Returns the number of buttons.

auto getDefaultButton ( ) const
inline

Returns the index of the button activated by the ENTER key or NO_BUTTON.

const auto& getTitle ( ) const
inline

Returns the title displayed at the top of the dialog.

auto getTitleWidget ( ) const
inline

Returns the text widget displaying the title.

void select ( int32  index) const

Activates a button by its index, pushing an UIEvent::OnSelectItem event.

void setButtonSize ( const float  width,
const float  height 
)
inline

Changes the size of the buttons.

void setCancelButton ( const int32  index)
inline

Sets the index of the button activated by the ESCAPE key or NO_BUTTON for none.

void setDefaultButton ( const int32  index)
inline

Sets the index of the button activated by the ENTER key or NO_BUTTON for none.

void setResources ( const std::string &  resBox,
const std::string &  resSeparator,
const std::string &  resButton 
)

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

Parameters
resBoxResource for the box drawn around the dialog.
resSeparatorResource for the line between the title & the content.
resButtonResource for the buttons.
void setTitle ( const std::string &  title)

Changes the title displayed at the top of the dialog.

Member Data Documentation

constexpr float DEFAULT_BUTTON_HEIGHT {30.0f}
staticconstexpr

Default height of the buttons.

constexpr float DEFAULT_BUTTON_PADDING {4.0f}
staticconstexpr

Default padding inside the buttons.

constexpr float DEFAULT_BUTTON_WIDTH {90.0f}
staticconstexpr

Default width of the buttons.

constexpr float DEFAULT_HEIGHT {160.0f}
staticconstexpr

Default height of the dialog box.

constexpr float DEFAULT_PADDING {4.0f}
staticconstexpr

Default space between the borders of the dialog & its content.

constexpr float DEFAULT_WIDTH {300.0f}
staticconstexpr

Default width of the dialog box.

constexpr int32 NO_BUTTON {-1}
staticconstexpr

No button is associated with a keyboard key.