HoverRace
2.0
|
A standard button, with a text label. More...
#include <Button.h>
Classes | |
struct | Props |
Public Member Functions | |
Button (Display &display, const std::string &text, uiLayoutFlags_t layoutFlags=0) | |
Constructor for automatically-sized button. More... | |
Button (Display &display, const Vec2 &size, const std::string &text, uiLayoutFlags_t layoutFlags=0) | |
Constructor for fixed-sized button. More... | |
virtual | ~Button () |
void | AttachView (Display &disp) override |
void | FireModelUpdate (int prop) override |
Indicate that a model property has changed. More... | |
Box * | GetBackgroundChild () const |
BaseContainer * | GetContentsChild () const |
FillBox * | GetHighlightChild () const |
Box * | GetIcon () const |
Box * | GetIconChild () const |
Label * | GetLabelChild () const |
Picture * | GetPictureChild () const |
const std::string & | GetText () const |
Alignment | getTextAlignment () const |
Vec3 | Measure () override |
Calculate the size of the component. More... | |
bool | OnNavigate (const Control::Nav &nav) override |
void | SetContents (std::shared_ptr< BaseContainer > contents) |
Set a container of widgets to render as the contents of the button. More... | |
void | SetFixedWidth (double width) |
Enable auto-sizing on the height only (i.e. More... | |
void | SetIcon (std::shared_ptr< Box > icon) |
Set the optional icon to appear on the button, in addition to the text. More... | |
void | SetText (const std::string &text) |
void | SetTextAlignment (Alignment textAlignment) |
Sets the alignment of the text within the button. More... | |
void | SetTexture (std::shared_ptr< Res< Texture >> image) |
Set the background image. More... | |
std::shared_ptr< Box > | ShareIcon () const |
std::shared_ptr< Res< Texture > > | ShareTexture () const |
![]() | |
ClickRegion (Display &display, uiLayoutFlags_t layoutFlags=0) | |
Constructor for automatically-sized button. More... | |
ClickRegion (Display &display, const Vec2 &size, uiLayoutFlags_t layoutFlags=0) | |
Constructor for fixed-sized button. More... | |
virtual | ~ClickRegion () |
void | AttachView (Display &disp) override |
clickedSignal_t & | GetClickedSignal () |
const Vec2 & | GetSize () |
Retrieve the size of the button. More... | |
bool | IsAutoSize () const |
Check if automatic sizing is enabled. More... | |
bool | IsEnabled () const |
Check if the widget is enabled. More... | |
Vec3 | Measure () override |
Calculate the size of the component. More... | |
bool | OnAction () override |
bool | OnMouseMoved (const Vec2 &pos) override |
bool | OnMousePressed (const Control::Mouse::Click &click) override |
bool | OnMouseReleased (const Control::Mouse::Click &click) override |
void | SetAutoSize () |
Enable automatic sizing. More... | |
void | SetEnabled (bool enabled) |
void | SetSize (const Vec2 &size) |
Set the button to a fixed size. More... | |
void | SetSize (double w, double h) |
Convenience function for SetSize(const Vec2&). More... | |
bool | TryFocus (const Control::Nav &nav=Control::Nav::NEUTRAL) override |
Attempts to give this widget focus. More... | |
![]() | |
UiViewModel (uiLayoutFlags_t layoutFlags=0) | |
virtual | ~UiViewModel () |
virtual void | DropFocus () |
Force this widget to give up focus, if it is currently focused. More... | |
Vec2 | GetAlignedPos (const Vec2 &pos, double w, double h) const |
Retrieve an arbitrary position adjusted by the current alignment. More... | |
Vec2 | GetAlignedPos (double w, double h) const |
Retrieve the position adjusted by the current alignment. More... | |
Alignment | GetAlignment () const |
Retrieve the alignment of the component. More... | |
focusRelinquishedSignal_t & | GetFocusRelinquishedSignal () |
focusRequestedSignal_t & | GetFocusRequestedSignal () |
uiLayoutFlags_t | GetLayoutFlags () const |
Retrieve the layout flags. More... | |
const Vec2 & | GetPos () const |
Get the position of the component. More... | |
const Vec2 & | GetTranslation () const |
Retrieves the position translation. More... | |
bool | IsFocused () const |
Check if this widget currently has input focus. More... | |
uiLayoutFlags_t | IsLayoutFloating () const |
uiLayoutFlags_t | IsLayoutUnscaled () const |
virtual bool | OnMouseScrolled (const Control::Mouse::Scroll &) |
void | RequestFocus () |
Attempt to hand over the input focus to this widget. More... | |
void | SetAlignment (Alignment alignment) |
Set the alignment of the component. More... | |
void | SetPos (const Vec2 &pos) |
Set the position of the component. More... | |
void | SetPos (double x, double y) |
Convenience function for SetPos(const Vec2&). More... | |
void | SetTranslation (const Vec2 &translation) |
Sets the position translation. More... | |
void | SetTranslation (double x, double y) |
Convenience function for SetTranslation(const Vec2&). More... | |
![]() | |
ViewModel () | |
virtual | ~ViewModel () |
View * | GetView () const |
void | PrepareRender () |
void | Render () |
void | SetView (std::unique_ptr< View > &&view) |
Protected Member Functions | |
void | Layout () override |
Adjust the size and position of any child elements. More... | |
![]() | |
virtual void | FireClickedSignal () |
bool | IsPressed () const |
virtual void | OnMouseDrag (const Vec2 &relPos) |
Handle when the mouse is dragged over the widget. More... | |
void | RequestSizing () |
Indicate that the size of the button may have changed, when auto-sizing is enabled. More... | |
Vec2 | ScreenPosToRel (const Vec2 &pos) |
Convert screen coordinates to relative (widget) coordinates. More... | |
void | SetPressed (bool pressed) |
bool | TestHit (const Vec2 &pos) |
Check if the coordinates of an event are within the bounds of this component. More... | |
![]() | |
void | RelinquishFocus (const Control::Nav &nav) |
Voluntarily give up input focus, passing it on to the next widget. More... | |
void | SetFocused (bool focused) |
Set the focused state. More... | |
![]() | |
template<class T > | |
void | AttachViewDynamic (Display &disp, T *self) |
void | RequestLayout () |
Indicate that the current layout is out-of-date and needs to be adjusted. More... | |
Private Types | |
using | SUPER = ClickRegion |
Private Member Functions | |
void | Init (const std::string &text) |
Private Attributes | |
std::unique_ptr< FillBox > | background |
std::shared_ptr< BaseContainer > | contents |
boost::optional< double > | fixedWidth |
std::unique_ptr< FillBox > | highlight |
std::shared_ptr< Box > | icon |
double | iconGap |
std::unique_ptr< Label > | label |
double | paddingBottom |
double | paddingLeft |
double | paddingRight |
double | paddingTop |
std::unique_ptr< Picture > | picture |
Additional Inherited Members | |
![]() | |
using | clickedSignal_t = boost::signals2::signal< void(ClickRegion &)> |
![]() | |
enum | Alignment { Alignment::NW, Alignment::N, Alignment::NE, Alignment::E, Alignment::SE, Alignment::S, Alignment::SW, Alignment::W, Alignment::CENTER } |
Imagine the component pinned to the container with a thumbtack. More... | |
using | focusRelinquishedSignal_t = boost::signals2::signal< void(UiViewModel &, const Control::Nav &)> |
using | focusRequestedSignal_t = boost::signals2::signal< void(UiViewModel &)> |
![]() | |
Display & | display |
A standard button, with a text label.
|
private |
HoverRace::Display::Button::Button | ( | Display & | display, |
const std::string & | text, | ||
uiLayoutFlags_t | layoutFlags = 0 |
||
) |
Constructor for automatically-sized button.
display | The display child elements will be attached to. |
text | The text for the button. |
layoutFlags | Optional layout flags. |
HoverRace::Display::Button::Button | ( | Display & | display, |
const Vec2 & | size, | ||
const std::string & | text, | ||
uiLayoutFlags_t | layoutFlags = 0 |
||
) |
Constructor for fixed-sized button.
display | The display child elements will be attached to. |
size | The fixed button size. |
text | The text for the button. |
layoutFlags | Optional layout flags. |
|
virtual |
|
inlineoverridevirtual |
Implements HoverRace::Display::ViewModel.
|
overridevirtual |
Indicate that a model property has changed.
If a view is attached, it will be notified.
prop | The model-specific ID of the property that changed. |
Reimplemented from HoverRace::Display::ViewModel.
Reimplemented in HoverRace::Display::StateButton.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
const std::string & HoverRace::Display::Button::GetText | ( | ) | const |
UiViewModel::Alignment HoverRace::Display::Button::getTextAlignment | ( | ) | const |
|
private |
|
overrideprotectedvirtual |
Adjust the size and position of any child elements.
Subclasses with child elements should override this function.
This is called automatically during the PrepareRender() phase if RequestLayout() has been called. It is also called the first time PrepareRender() is invoked. After this function is called, it will not be called again until another call to RequestLayout().
Reimplemented from HoverRace::Display::ViewModel.
|
overridevirtual |
Calculate the size of the component.
For UI components, the return value is affected by layout flags.
Reimplemented from HoverRace::Display::ViewModel.
|
overridevirtual |
Reimplemented from HoverRace::Display::UiViewModel.
void HoverRace::Display::Button::SetContents | ( | std::shared_ptr< BaseContainer > | contents | ) |
Set a container of widgets to render as the contents of the button.
This allows for more advanced customization of the rendering of the button.
contents | The container containing the contents (may be nullptr ). |
void HoverRace::Display::Button::SetFixedWidth | ( | double | width | ) |
Enable auto-sizing on the height only (i.e.
fixed width, auto height). This only has an effect if auto-sizing is enabled.
width | The width. |
void HoverRace::Display::Button::SetIcon | ( | std::shared_ptr< Box > | icon | ) |
Set the optional icon to appear on the button, in addition to the text.
The icon will be sized to the standard size for the button (namely, the height of the text), so while it is safe to share the icon between buttons, be aware that it may be modified.
icon | A subclass of FillBox to use as an icon, or nullptr to unset the icon. |
void HoverRace::Display::Button::SetText | ( | const std::string & | text | ) |
void HoverRace::Display::Button::SetTextAlignment | ( | Alignment | textAlignment | ) |
Sets the alignment of the text within the button.
textAlignment | The text alignment. |
Set the background image.
image | The image, or nullptr to unset the background image. |
|
inline |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |