HoverRace  2.0
Classes | Public Types | Public Member Functions | Protected Member Functions | Private Types | Private Attributes | List of all members
HoverRace::Display::UiViewModel Class Reference

Base class for UI (2D) components. More...

#include <UiViewModel.h>

+ Inheritance diagram for HoverRace::Display::UiViewModel:

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_tGetFocusRelinquishedSignal ()
 
focusRequestedSignal_tGetFocusRequestedSignal ()
 
uiLayoutFlags_t GetLayoutFlags () const
 Retrieve the layout flags. More...
 
const Vec2GetPos () const
 Get the position of the component. More...
 
const Vec2GetTranslation () 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...
 
- Public Member Functions inherited from HoverRace::Display::ViewModel
 ViewModel ()
 
virtual ~ViewModel ()
 
virtual void AttachView (Display &disp)=0
 
ViewGetView () 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...
 
- Protected Member Functions inherited from HoverRace::Display::ViewModel
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
 

Detailed Description

Base class for UI (2D) components.

Author
Michael Imamura

Member Typedef Documentation

Member Enumeration Documentation

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.

Enumerator
NW 

Northwest corner (default).

North (horizontally-centered).

NE 

Northeast corner.

East (vertically-centered).

SE 

Southeast corner.

South (horizontally-centered).

SW 

Southwest corner.

West (vertically-centered).

CENTER 

Horizontally and vertically centered.

Constructor & Destructor Documentation

HoverRace::Display::UiViewModel::UiViewModel ( uiLayoutFlags_t  layoutFlags = 0)
inline
virtual HoverRace::Display::UiViewModel::~UiViewModel ( )
inlinevirtual

Member Function Documentation

virtual void HoverRace::Display::UiViewModel::DropFocus ( )
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.

Vec2 HoverRace::Display::UiViewModel::GetAlignedPos ( const Vec2 pos,
double  w,
double  h 
) const

Retrieve an arbitrary position adjusted by the current alignment.

Parameters
posThe position to adjust.
wThe width of the component.
hThe height of the component.
Returns
The adjusted position.
Vec2 HoverRace::Display::UiViewModel::GetAlignedPos ( double  w,
double  h 
) const
inline

Retrieve the position adjusted by the current alignment.

Parameters
wThe width of the component.
hThe height of the component.
Returns
The adjusted position.
Alignment HoverRace::Display::UiViewModel::GetAlignment ( ) const
inline

Retrieve the alignment of the component.

Returns
The alignment.
See also
UiViewModel::Alignment
focusRelinquishedSignal_t& HoverRace::Display::UiViewModel::GetFocusRelinquishedSignal ( )
inline
focusRequestedSignal_t& HoverRace::Display::UiViewModel::GetFocusRequestedSignal ( )
inline
uiLayoutFlags_t HoverRace::Display::UiViewModel::GetLayoutFlags ( ) const
inline

Retrieve the layout flags.

See also
UiViewModel::LayoutFlags
const Vec2& HoverRace::Display::UiViewModel::GetPos ( ) const
inline

Get the position of the component.

Returns
The position, relative to the parent (if any).
See also
GetAlignment()
const Vec2& HoverRace::Display::UiViewModel::GetTranslation ( ) const
inline

Retrieves the position translation.

Returns
The translation.
bool HoverRace::Display::UiViewModel::IsFocused ( ) const
inline

Check if this widget currently has input focus.

Returns
true if focused, false if not.
uiLayoutFlags_t HoverRace::Display::UiViewModel::IsLayoutFloating ( ) const
inline
uiLayoutFlags_t HoverRace::Display::UiViewModel::IsLayoutUnscaled ( ) const
inline
virtual bool HoverRace::Display::UiViewModel::OnAction ( )
inlinevirtual
virtual bool HoverRace::Display::UiViewModel::OnMouseMoved ( const Vec2 )
inlinevirtual
virtual bool HoverRace::Display::UiViewModel::OnMousePressed ( const Control::Mouse::Click )
inlinevirtual
virtual bool HoverRace::Display::UiViewModel::OnMouseReleased ( const Control::Mouse::Click )
inlinevirtual
virtual bool HoverRace::Display::UiViewModel::OnMouseScrolled ( const Control::Mouse::Scroll )
inlinevirtual
virtual bool HoverRace::Display::UiViewModel::OnNavigate ( const Control::Nav )
inlinevirtual
void HoverRace::Display::UiViewModel::RelinquishFocus ( const Control::Nav nav)
protected

Voluntarily give up input focus, passing it on to the next widget.

Parameters
navThe 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.

Parameters
alignmentThe alignment (see Alignment).
void HoverRace::Display::UiViewModel::SetFocused ( bool  focused)
protected

Set the focused state.

Parameters
focusedtrue if focused, false otherwise.
void HoverRace::Display::UiViewModel::SetPos ( const Vec2 pos)

Set the position of the component.

Parameters
posThe position, relative to the container (if any).
void HoverRace::Display::UiViewModel::SetPos ( double  x,
double  y 
)
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.

Parameters
translationThe translation.
void HoverRace::Display::UiViewModel::SetTranslation ( double  x,
double  y 
)
inline

Convenience function for SetTranslation(const Vec2&).

virtual bool HoverRace::Display::UiViewModel::TryFocus ( const Control::Nav nav = Control::Nav::NEUTRAL)
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.

Parameters
navThe direction in which the focus is heading.
Returns
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.

Member Data Documentation

Alignment HoverRace::Display::UiViewModel::alignment
private
bool HoverRace::Display::UiViewModel::focused
private
focusRelinquishedSignal_t HoverRace::Display::UiViewModel::focusRelinquishedSignal
private
focusRequestedSignal_t HoverRace::Display::UiViewModel::focusRequestedSignal
private
uiLayoutFlags_t HoverRace::Display::UiViewModel::layoutFlags
private
Vec2 HoverRace::Display::UiViewModel::pos
private
Vec2 HoverRace::Display::UiViewModel::translation
private

The documentation for this class was generated from the following files: