HoverRace
2.0
|
Base class for UI (2D) components. More...
#include <UiViewModel.h>
Classes | |
struct | Props |
Public Types | |
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 &)> |
Public Member Functions | |
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 | OnAction () |
virtual bool | OnMouseMoved (const Vec2 &) |
virtual bool | OnMousePressed (const Control::Mouse::Click &) |
virtual bool | OnMouseReleased (const Control::Mouse::Click &) |
virtual bool | OnMouseScrolled (const Control::Mouse::Scroll &) |
virtual bool | OnNavigate (const Control::Nav &) |
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... | |
virtual bool | TryFocus (const Control::Nav &nav=Control::Nav::NEUTRAL) |
Attempts to give this widget focus. More... | |
![]() | |
ViewModel () | |
virtual | ~ViewModel () |
virtual void | AttachView (Display &disp)=0 |
View * | GetView () const |
virtual Vec3 | Measure () |
Calculate the size of the component. More... | |
void | PrepareRender () |
void | Render () |
void | SetView (std::unique_ptr< View > &&view) |
Protected Member Functions | |
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) |
virtual void | FireModelUpdate (int prop) |
Indicate that a model property has changed. More... | |
virtual void | Layout () |
Adjust the size and position of any child elements. More... | |
void | RequestLayout () |
Indicate that the current layout is out-of-date and needs to be adjusted. More... | |
Private Types | |
using | SUPER = ViewModel |
Private Attributes | |
Alignment | alignment |
bool | focused |
focusRelinquishedSignal_t | focusRelinquishedSignal |
focusRequestedSignal_t | focusRequestedSignal |
uiLayoutFlags_t | layoutFlags |
Vec2 | pos |
Vec2 | translation |
Base class for UI (2D) components.
using HoverRace::Display::UiViewModel::focusRelinquishedSignal_t = boost::signals2::signal<void(UiViewModel&, const Control::Nav&)> |
using HoverRace::Display::UiViewModel::focusRequestedSignal_t = boost::signals2::signal<void(UiViewModel&)> |
|
private |
|
strong |
Imagine the component pinned to the container with a thumbtack.
The thumbtack's position is at GetPos(), and the alignment determines which corner the component hangs from.
|
inline |
|
inlinevirtual |
|
inlinevirtual |
Force this widget to give up focus, if it is currently focused.
This is called by the parent container if focus is shifting away to another widget.
Reimplemented in HoverRace::Display::FlexGrid, HoverRace::Display::BasePickList, and HoverRace::Display::Container.
Retrieve an arbitrary position adjusted by the current alignment.
pos | The position to adjust. |
w | The width of the component. |
h | The height of the component. |
|
inline |
Retrieve the position adjusted by the current alignment.
w | The width of the component. |
h | The height of the component. |
|
inline |
|
inline |
|
inline |
|
inline |
Retrieve the layout flags.
|
inline |
Get the position of the component.
|
inline |
Retrieves the position translation.
|
inline |
Check if this widget currently has input focus.
true
if focused, false
if not.
|
inline |
|
inline |
|
inlinevirtual |
|
inlinevirtual |
Reimplemented in HoverRace::Display::BaseContainer, and HoverRace::Display::ClickRegion.
|
inlinevirtual |
Reimplemented in HoverRace::Display::BaseContainer, and HoverRace::Display::ClickRegion.
|
inlinevirtual |
Reimplemented in HoverRace::Display::BaseContainer, and HoverRace::Display::ClickRegion.
|
inlinevirtual |
Reimplemented in HoverRace::Display::BaseContainer, and HoverRace::Display::BasePickList.
|
inlinevirtual |
|
protected |
Voluntarily give up input focus, passing it on to the next widget.
nav | The direction in which focus should shift, if possible. |
void HoverRace::Display::UiViewModel::RequestFocus | ( | ) |
Attempt to hand over the input focus to this widget.
The request may not be successful, possibly leaving no widget focused.
void HoverRace::Display::UiViewModel::SetAlignment | ( | Alignment | alignment | ) |
Set the alignment of the component.
alignment | The alignment (see Alignment). |
|
protected |
Set the focused state.
focused | true if focused, false otherwise. |
void HoverRace::Display::UiViewModel::SetPos | ( | const Vec2 & | pos | ) |
Set the position of the component.
pos | The position, relative to the container (if any). |
|
inline |
Convenience function for SetPos(const Vec2&).
void HoverRace::Display::UiViewModel::SetTranslation | ( | const Vec2 & | translation | ) |
Sets the position translation.
The translation allows the position to be adjusted (e.g. for animations) without adjusting the actual position.
translation | The translation. |
|
inline |
Convenience function for SetTranslation(const Vec2&).
|
inlinevirtual |
Attempts to give this widget focus.
Subclasses should override this with logic to determine if the widget is focusable.
This is called by the parent container if focus has been requested.
nav | The direction in which the focus is heading. |
true
if it succeeds (widget is now focused), false
if it fails (widget did not take focus). Reimplemented in HoverRace::Display::FlexGrid, HoverRace::Display::BasePickList, HoverRace::Display::ClickRegion, and HoverRace::Display::Container.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |