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

Base class for widgets that contain other widgets. More...

#include <BaseContainer.h>

+ Inheritance diagram for HoverRace::Display::BaseContainer:

Classes

class  Child
 
struct  Props
 

Public Member Functions

 BaseContainer (Display &display, uiLayoutFlags_t layoutFlags=0)
 Constructor for an unsized container without clipping. More...
 
 BaseContainer (Display &display, const Vec2 &size, bool clip=true, uiLayoutFlags_t layoutFlags=0)
 Constructor for a sized container. More...
 
virtual ~BaseContainer ()
 
void AttachView (Display &disp) override
 
template<class Fn >
void ForEachChild (Fn fn) const
 Iterate over each child widget. More...
 
template<class Fn >
void ForEachVisibleChild (Fn fn) const
 Iterate over each visible child widget. More...
 
const Vec2GetChildOffset () const
 Retrieve the offset to the position of the child widgets. More...
 
double GetOpacity () const
 Retrieve the opacity. More...
 
const Vec2GetSize () const
 Retrieve the size of the container. More...
 
bool IsClip () const
 Check if child elements are clipped to the container bounds. More...
 
bool IsEmpty () const
 Check if this container is devoid of child widgets. More...
 
bool IsVisible () const
 Check if the children of this container are shown. More...
 
Vec3 Measure () override
 Calculate the size of the component. More...
 
bool OnMouseMoved (const Vec2 &pos) override
 
bool OnMousePressed (const Control::Mouse::Click &click) override
 
bool OnMouseReleased (const Control::Mouse::Click &click) override
 
bool OnMouseScrolled (const Control::Mouse::Scroll &scroll) override
 
void SetClip (bool clip)
 Set whether child elements are clipped to the container bounds. More...
 
void SetOpacity (double opacity)
 Set the opacity of the container. More...
 
void SetSize (const Vec2 &size)
 Set the size of the container. More...
 
void SetSize (double w, double h)
 Convenience function for SetSize(const Vec2&). More...
 
void SetVisible (bool visible)
 Sets whether the widgets in this container are visible. More...
 
void ShrinkWrap ()
 Resize the container to the minimum size that will fit all of the child elements. 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 OnAction ()
 
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 ()
 
ViewGetView () const
 
void PrepareRender ()
 
void Render ()
 
void SetView (std::unique_ptr< View > &&view)
 

Protected Types

using children_t = std::vector< std::unique_ptr< Child >>
 

Protected Member Functions

virtual void Clear ()
 Remove all child elements. More...
 
children_tGetChildren ()
 
template<class T , class... Args>
std::enable_if< std::is_base_of< UiViewModel, T >::value, std::shared_ptr< T > >::type NewChild (Args &&...args)
 Create and append a new child widget to the end of the list. More...
 
virtual void OnChildRelinquishedFocus (UiViewModel &child, const Control::Nav &nav)
 Called when a child widget passes input focus to another widget. More...
 
virtual void OnChildRequestedFocus (UiViewModel &child)
 Called when a child widget requests input focus. More...
 
template<typename T >
std::enable_if< std::is_base_of< UiViewModel, T >::value, std::shared_ptr< T > >::type RemoveChild (const std::shared_ptr< T > &child)
 Remove a child element. More...
 
template<class T >
std::enable_if< std::is_base_of< UiViewModel, T >::value, std::shared_ptr< T > >::type ReorderChild (const std::shared_ptr< T > &child, size_t idx)
 Move a widget to a different position in the list. More...
 
virtual void Reserve (size_t capacity)
 Increase the capacity of the of this container. More...
 
void SetChildOffset (const Vec2 &offset)
 Sets the position offset of child widgets. More...
 
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 Member Functions

template<typename P , bool(UiViewModel::*)(P) F>
bool PropagateMouseEvent (P param)
 

Private Attributes

Vec2 childOffset
 
children_t children
 
bool clip
 
double opacity
 
Vec2 size
 
bool visible
 

Additional Inherited Members

- 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 &)>
 

Detailed Description

Base class for widgets that contain other widgets.

Most containers differ only in how their child widgets are managed (i.e., layout, visibility, navigation, etc.) but share a common view and, beneath it all, just need a way to keep track of the child widgets and propagate events.

The majority of the member functions regarding adding, removing, or otherwise manipulating the list of child widgets are marked as protected, since each subclass will want to control what operations are allowed and what the side-effects are. For example, Container simply redefines the functions as public, while FlexGrid requires children to be placed into cells in the grid, while PickList treats child widgets as an implementation detail. All of them share the same view.

Author
Michael Imamura

Member Typedef Documentation

using HoverRace::Display::BaseContainer::children_t = std::vector<std::unique_ptr<Child>>
protected

Constructor & Destructor Documentation

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

Constructor for an unsized container without clipping.

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

Constructor for a sized container.

Parameters
displayThe display child elements will be attached to.
sizeThe size of the container.
clipEnable (default) or disable clipping of child widgets.
layoutFlagsOptional layout flags.
virtual HoverRace::Display::BaseContainer::~BaseContainer ( )
inlinevirtual

Member Function Documentation

void HoverRace::Display::BaseContainer::AttachView ( Display disp)
inlineoverridevirtual
virtual void HoverRace::Display::BaseContainer::Clear ( )
inlineprotectedvirtual
template<class Fn >
void HoverRace::Display::BaseContainer::ForEachChild ( Fn  fn) const
inline

Iterate over each child widget.

Parameters
fnThe function to execute for each widget.
template<class Fn >
void HoverRace::Display::BaseContainer::ForEachVisibleChild ( Fn  fn) const
inline

Iterate over each visible child widget.

Parameters
fnThe function to execute for each widget.
const Vec2& HoverRace::Display::BaseContainer::GetChildOffset ( ) const
inline

Retrieve the offset to the position of the child widgets.

Returns
The child offset.
children_t& HoverRace::Display::BaseContainer::GetChildren ( )
inlineprotected
double HoverRace::Display::BaseContainer::GetOpacity ( ) const
inline

Retrieve the opacity.

Returns
The opacity (1.0 is fully-opaque, 0.0 is fully-transparent).
const Vec2& HoverRace::Display::BaseContainer::GetSize ( ) const
inline

Retrieve the size of the container.

Note
If clipping is turned off, the size is undefined.
Returns
The size, where x is the width and y is the height.
bool HoverRace::Display::BaseContainer::IsClip ( ) const
inline

Check if child elements are clipped to the container bounds.

Returns
true if clipping is enabled, false if elements are allowed to render outside of the bounds.
bool HoverRace::Display::BaseContainer::IsEmpty ( ) const
inline

Check if this container is devoid of child widgets.

Returns
true if empty, false if not.
bool HoverRace::Display::BaseContainer::IsVisible ( ) const
inline

Check if the children of this container are shown.

Returns
true if visible, false if not.
Vec3 HoverRace::Display::BaseContainer::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::FlexGrid.

template<class T , class... Args>
std::enable_if<std::is_base_of<UiViewModel, T>::value, std::shared_ptr<T> >::type HoverRace::Display::BaseContainer::NewChild ( Args &&...  args)
inlineprotected

Create and append a new child widget to the end of the list.

Template Parameters
TThe type of the child widget.
ArgsThe types of the arguments.
Parameters
argsThe arguments to pass to the child widget's constructor.
Returns
A shared pointer to the newly-constructed widget.
virtual void HoverRace::Display::BaseContainer::OnChildRelinquishedFocus ( UiViewModel child,
const Control::Nav nav 
)
inlineprotectedvirtual

Called when a child widget passes input focus to another widget.

Parameters
childThe child widget.
navThe navigation direction.

Reimplemented in HoverRace::Display::BasePickList, HoverRace::Display::FlexGrid, and HoverRace::Display::Container.

virtual void HoverRace::Display::BaseContainer::OnChildRequestedFocus ( UiViewModel child)
inlineprotectedvirtual

Called when a child widget requests input focus.

Parameters
childThe child widget.

Reimplemented in HoverRace::Display::BasePickList, HoverRace::Display::FlexGrid, and HoverRace::Display::Container.

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

Reimplemented from HoverRace::Display::UiViewModel.

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

Reimplemented from HoverRace::Display::UiViewModel.

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

Reimplemented from HoverRace::Display::UiViewModel.

bool HoverRace::Display::BaseContainer::OnMouseScrolled ( const Control::Mouse::Scroll scroll)
overridevirtual
template<typename P , bool(UiViewModel::*)(P) F>
bool HoverRace::Display::BaseContainer::PropagateMouseEvent ( param)
inlineprivate
template<typename T >
std::enable_if<std::is_base_of<UiViewModel, T>::value, std::shared_ptr<T> >::type HoverRace::Display::BaseContainer::RemoveChild ( const std::shared_ptr< T > &  child)
inlineprotected

Remove a child element.

Parameters
childThe child element; must be a shared_ptr to a subclass of UiViewModel.
Returns
The same child element that was passed in.
template<class T >
std::enable_if<std::is_base_of<UiViewModel, T>::value, std::shared_ptr<T> >::type HoverRace::Display::BaseContainer::ReorderChild ( const std::shared_ptr< T > &  child,
size_t  idx 
)
inlineprotected

Move a widget to a different position in the list.

Parameters
childThe child.
idxThe destination index. If beyond the end, then the child will be moved to the end of the list.
Returns
The same child element that was passed in.
virtual void HoverRace::Display::BaseContainer::Reserve ( size_t  capacity)
inlineprotectedvirtual

Increase the capacity of the of this container.

The internal capacity will be increased (never decreased). This is useful as a hint to prevent re-allocation due to resizing the internal storage. It's not required; the internal storage will be resized as necessary anyway, at the cost of re-allocation. Containers with a lot of child elements will benefit the most from specifying the capacity early.

Parameters
capacityThe new capacity.

Reimplemented in HoverRace::Display::FlexGrid, HoverRace::Display::PickList< T >, and HoverRace::Display::Container.

void HoverRace::Display::BaseContainer::SetChildOffset ( const Vec2 childOffset)
protected

Sets the position offset of child widgets.

Parameters
childOffsetThe child offset.
void HoverRace::Display::BaseContainer::SetClip ( bool  clip)

Set whether child elements are clipped to the container bounds.

Parameters
cliptrue if clipping is enabled, false if elements are allowed to render outside of the bounds.
void HoverRace::Display::BaseContainer::SetOpacity ( double  opacity)

Set the opacity of the container.

The opacity is applied to the container as a whole; the container is first rendered off-screen, then the opacity is applied when drawing the buffer to the screen.

The value will be clamped to the range 0.0 to 1.0 inclusive.

Parameters
opacityThe opacity (1.0 is fully-opaque, 0.0 is fully-transparent).
void HoverRace::Display::BaseContainer::SetSize ( const Vec2 size)

Set the size of the container.

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

Convenience function for SetSize(const Vec2&).

void HoverRace::Display::BaseContainer::SetVisible ( bool  visible)

Sets whether the widgets in this container are visible.

Parameters
visibletrue to show, false to hide.
void HoverRace::Display::BaseContainer::ShrinkWrap ( )

Resize the container to the minimum size that will fit all of the child elements.

bool HoverRace::Display::BaseContainer::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.

Member Data Documentation

Vec2 HoverRace::Display::BaseContainer::childOffset
private
children_t HoverRace::Display::BaseContainer::children
private
bool HoverRace::Display::BaseContainer::clip
private
Display& HoverRace::Display::BaseContainer::display
protected
double HoverRace::Display::BaseContainer::opacity
private
Vec2 HoverRace::Display::BaseContainer::size
private
bool HoverRace::Display::BaseContainer::visible
private

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