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

Base class for clickable areas. More...

#include <ClickRegion.h>

+ Inheritance diagram for HoverRace::Display::ClickRegion:

Classes

struct  Props
 

Public Types

using clickedSignal_t = boost::signals2::signal< void(ClickRegion &)>
 
- Public Types inherited from HoverRace::Display::UiViewModel
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

 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_tGetClickedSignal ()
 
const Vec2GetSize ()
 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...
 
- Public Member Functions inherited from HoverRace::Display::UiViewModel
 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 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...
 
- Public Member Functions inherited from HoverRace::Display::ViewModel
 ViewModel ()
 
virtual ~ViewModel ()
 
ViewGetView () const
 
void PrepareRender ()
 
void Render ()
 
void SetView (std::unique_ptr< View > &&view)
 

Protected Member Functions

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...
 
- Protected Member Functions inherited from HoverRace::Display::UiViewModel
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...
 

Protected Attributes

Displaydisplay
 

Private Types

using SUPER = UiViewModel
 

Private Attributes

bool autoSize
 
clickedSignal_t clickedSignal
 
bool enabled
 
bool needsSizing
 
bool pressed
 
Vec2 size
 

Detailed Description

Base class for clickable areas.

Author
Michael Imamura

Member Typedef Documentation

using HoverRace::Display::ClickRegion::clickedSignal_t = boost::signals2::signal<void(ClickRegion&)>

Constructor & Destructor Documentation

HoverRace::Display::ClickRegion::ClickRegion ( Display display,
uiLayoutFlags_t  layoutFlags = 0 
)

Constructor for automatically-sized button.

Parameters
displayThe display child elements will be attached to.
layoutFlagsOptional layout flags.
HoverRace::Display::ClickRegion::ClickRegion ( Display display,
const Vec2 size,
uiLayoutFlags_t  layoutFlags = 0 
)

Constructor for fixed-sized button.

Parameters
displayThe display child elements will be attached to.
sizeThe fixed button size.
layoutFlagsOptional layout flags.
HoverRace::Display::ClickRegion::~ClickRegion ( )
virtual

Member Function Documentation

void HoverRace::Display::ClickRegion::AttachView ( Display disp)
inlineoverridevirtual
void HoverRace::Display::ClickRegion::FireClickedSignal ( )
protectedvirtual
clickedSignal_t& HoverRace::Display::ClickRegion::GetClickedSignal ( )
inline
const Vec2 & HoverRace::Display::ClickRegion::GetSize ( )

Retrieve the size of the button.

If automatic sizing is enabled, then this will calculate the size immediately (the same caveats as calling Measure()).

Returns
The size, where x is the width and y is the height.
bool HoverRace::Display::ClickRegion::IsAutoSize ( ) const
inline

Check if automatic sizing is enabled.

Returns
true if the size is determined by the contents of the button, false if using a fixed size.
bool HoverRace::Display::ClickRegion::IsEnabled ( ) const
inline

Check if the widget is enabled.

Disabled widgets are visible but not clickable or focusable.

Returns
true if enabled, false if disabled.
bool HoverRace::Display::ClickRegion::IsPressed ( ) const
inlineprotected
Vec3 HoverRace::Display::ClickRegion::Measure ( )
inlineoverridevirtual

Calculate the size of the component.

For UI components, the return value is affected by layout flags.

Returns
The size (may be zero if the size cannot be determined yet).
Warning
Depending on the view, this may be an expensive operation since the view may have to call View::PrepareRender to apply model changes. As such, it is recommended to call Measure in the PrepareRender phase itself.

Reimplemented from HoverRace::Display::ViewModel.

Reimplemented in HoverRace::Display::Slider.

bool HoverRace::Display::ClickRegion::OnAction ( )
overridevirtual

Reimplemented from HoverRace::Display::UiViewModel.

virtual void HoverRace::Display::ClickRegion::OnMouseDrag ( const Vec2 relPos)
inlineprotectedvirtual

Handle when the mouse is dragged over the widget.

Parameters
relPosThe relative position.

Reimplemented in HoverRace::Display::Slider.

bool HoverRace::Display::ClickRegion::OnMouseMoved ( const Vec2 pos)
overridevirtual

Reimplemented from HoverRace::Display::UiViewModel.

bool HoverRace::Display::ClickRegion::OnMousePressed ( const Control::Mouse::Click click)
overridevirtual

Reimplemented from HoverRace::Display::UiViewModel.

bool HoverRace::Display::ClickRegion::OnMouseReleased ( const Control::Mouse::Click click)
overridevirtual

Reimplemented from HoverRace::Display::UiViewModel.

void HoverRace::Display::ClickRegion::RequestSizing ( )
protected

Indicate that the size of the button may have changed, when auto-sizing is enabled.

If auto-sizing is not enabled, then this does nothing.

Vec2 HoverRace::Display::ClickRegion::ScreenPosToRel ( const Vec2 pos)
protected

Convert screen coordinates to relative (widget) coordinates.

Parameters
posThe screen coordinates.
Returns
The relative coordinates.
void HoverRace::Display::ClickRegion::SetAutoSize ( )

Enable automatic sizing.

The size of the button will be determined by the contents. To set a fixed size, call SetSize(const Vec2&).

void HoverRace::Display::ClickRegion::SetEnabled ( bool  enabled)
void HoverRace::Display::ClickRegion::SetPressed ( bool  pressed)
protected
void HoverRace::Display::ClickRegion::SetSize ( const Vec2 size)

Set the button to a fixed size.

Parameters
sizeThe size of the container, where x is the width and y is the height.
See also
SetAutoSize()
void HoverRace::Display::ClickRegion::SetSize ( double  w,
double  h 
)
inline

Convenience function for SetSize(const Vec2&).

bool HoverRace::Display::ClickRegion::TestHit ( const Vec2 pos)
protected

Check if the coordinates of an event are within the bounds of this component.

Parameters
posThe screen-space position.
Returns
true if the test passes, false if the test fails.
bool HoverRace::Display::ClickRegion::TryFocus ( const Control::Nav nav = Control::Nav::NEUTRAL)
overridevirtual

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 from HoverRace::Display::UiViewModel.

Member Data Documentation

bool HoverRace::Display::ClickRegion::autoSize
private
clickedSignal_t HoverRace::Display::ClickRegion::clickedSignal
private
Display& HoverRace::Display::ClickRegion::display
protected
bool HoverRace::Display::ClickRegion::enabled
private
bool HoverRace::Display::ClickRegion::needsSizing
private
bool HoverRace::Display::ClickRegion::pressed
private
Vec2 HoverRace::Display::ClickRegion::size
private

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