HoverRace  2.0
Classes | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
HoverRace::Display::PickList< T > Class Template Reference

Scrollable list of selectable items. More...

#include <PickList.h>

+ Inheritance diagram for HoverRace::Display::PickList< T >:

Classes

class  DefaultItem
 
class  ItemChild
 Maps the container child wrapper to each item. More...
 

Public Member Functions

 PickList (Display &display, const Vec2 &size, uiLayoutFlags_t layoutFlags=0)
 
 PickList (Display &display, Mode mode, const Vec2 &size, uiLayoutFlags_t layoutFlags=0)
 
virtual ~PickList ()
 
void Add (const std::string &label, const T &value)
 Add a list item with a specific label. More...
 
void Add (const T &value)
 Add a list item with a default label. More...
 
template<class Fn >
void ApplyFilter (Fn fn)
 Apply a filter to the list items. More...
 
void Clear () override
 Remove all child elements. More...
 
boost::optional< const T & > GetValue () const
 Get the value of the selected item. More...
 
void RemoveFilter ()
 Undo any applied filter (so all items are visible). More...
 
void Reserve (size_t capacity) override
 Increase the capacity of the of this container. More...
 
void SetValue (const T &val)
 Set the selected value. More...
 
- Public Member Functions inherited from HoverRace::Display::BasePickList
 BasePickList (Display &display, const Vec2 &size, uiLayoutFlags_t layoutFlags=0)
 
virtual ~BasePickList ()
 
void ClearSelection ()
 If an item is selected, unset the selection so that nothing is selected. More...
 
void DropFocus () override
 Force this widget to give up focus, if it is currently focused. More...
 
valueChangedSignal_tGetValueChangedSignal ()
 
bool HasSelected () const
 Check if this list has a selected item. More...
 
bool OnAction () override
 
bool OnMouseScrolled (const Control::Mouse::Scroll &) override
 
bool OnNavigate (const Control::Nav &nav) override
 
void SetIndex (size_t idx)
 Select an item by index. 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::BaseContainer
 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
 
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 ()
 
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
 
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

boost::optional< size_t > FindChildIndex (const UiViewModel &child) const override
 Search for the index of the given child widget. More...
 
UiViewModelGetFocusedChild () const override
 Get the focused child widget. More...
 
void SetSelection (const boost::optional< size_t > &newSel) override
 Set the selected item by index. More...
 
- Protected Member Functions inherited from HoverRace::Display::BasePickList
double GetScroll () const
 Retrieve how far down the list we have scrolled. More...
 
void Layout () override
 Adjust the size and position of any child elements. More...
 
void OnChildRelinquishedFocus (UiViewModel &, const Control::Nav &nav) override
 Called when a child widget passes input focus to another widget. More...
 
void OnChildRequestedFocus (UiViewModel &child) override
 Called when a child widget requests input focus. More...
 
void ScrollTo (double y)
 Scroll the list to the specified UI-space position. More...
 
void ScrollToFocused ()
 Scroll the list to ensure the focused item is visible. More...
 
- Protected Member Functions inherited from HoverRace::Display::BaseContainer
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...
 
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...
 
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...
 
void RequestLayout ()
 Indicate that the current layout is out-of-date and needs to be adjusted. More...
 

Private Types

using SUPER = BasePickList
 

Private Member Functions

void SetSelectedItem (DefaultItem *sel)
 

Private Attributes

std::vector< ItemChilditems
 
Mode mode
 

Additional Inherited Members

- Public Types inherited from HoverRace::Display::BasePickList
enum  Mode { Mode::RADIO, Mode::LIST }
 
using valueChangedSignal_t = boost::signals2::signal< void()>
 
- 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 &)>
 
- Protected Types inherited from HoverRace::Display::BaseContainer
using children_t = std::vector< std::unique_ptr< Child >>
 
- Protected Attributes inherited from HoverRace::Display::BasePickList
std::vector< size_t > filteredItems
 Indexes of filtered items. More...
 
boost::optional< size_t > focusedItem
 filteredItems index of focused. More...
 
double listHeight
 
boost::optional< size_t > selItem
 items index of selected. More...
 
valueChangedSignal_t valueChangedSignal
 
- Protected Attributes inherited from HoverRace::Display::BaseContainer
Displaydisplay
 

Detailed Description

template<class T>
class HoverRace::Display::PickList< T >

Scrollable list of selectable items.

Template Parameters
TThe type of the values held by the list items.
Todo:
Scrolling.
Author
Michael Imamura

Member Typedef Documentation

template<class T>
using HoverRace::Display::PickList< T >::SUPER = BasePickList
private

Constructor & Destructor Documentation

template<class T>
HoverRace::Display::PickList< T >::PickList ( Display display,
const Vec2 size,
uiLayoutFlags_t  layoutFlags = 0 
)
inline
template<class T>
HoverRace::Display::PickList< T >::PickList ( Display display,
Mode  mode,
const Vec2 size,
uiLayoutFlags_t  layoutFlags = 0 
)
inline
template<class T>
virtual HoverRace::Display::PickList< T >::~PickList ( )
inlinevirtual

Member Function Documentation

template<class T>
void HoverRace::Display::PickList< T >::Add ( const std::string &  label,
const T &  value 
)
inline

Add a list item with a specific label.

Parameters
labelThe label.
valueThe value.
template<class T>
void HoverRace::Display::PickList< T >::Add ( const T &  value)
inline

Add a list item with a default label.

Parameters
valueThe value.
template<class T>
template<class Fn >
void HoverRace::Display::PickList< T >::ApplyFilter ( Fn  fn)
inline

Apply a filter to the list items.

This filter is is applied immediately; it does not affect items added after this call is made. It is up to the owner of this list to re-apply the filter whenever an item is added.

Parameters
fnThe filter function. Takes the value and returns either true if the item is visible, false otherwise.
template<class T>
void HoverRace::Display::PickList< T >::Clear ( )
inlineoverridevirtual

Remove all child elements.

Reimplemented from HoverRace::Display::BaseContainer.

template<class T>
boost::optional<size_t> HoverRace::Display::PickList< T >::FindChildIndex ( const UiViewModel child) const
inlineoverrideprotectedvirtual

Search for the index of the given child widget.

Parameters
childThe child widget.
Returns
The found child index, if the widget was found.

Implements HoverRace::Display::BasePickList.

template<class T>
UiViewModel* HoverRace::Display::PickList< T >::GetFocusedChild ( ) const
inlineoverrideprotectedvirtual

Get the focused child widget.

Returns
The focused child, or nullptr if nothing is focused.

Implements HoverRace::Display::BasePickList.

template<class T>
boost::optional<const T&> HoverRace::Display::PickList< T >::GetValue ( ) const
inline

Get the value of the selected item.

Returns
The value.
template<class T>
void HoverRace::Display::PickList< T >::RemoveFilter ( )
inline

Undo any applied filter (so all items are visible).

template<class T>
void HoverRace::Display::PickList< T >::Reserve ( size_t  capacity)
inlineoverridevirtual

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

template<class T>
void HoverRace::Display::PickList< T >::SetSelectedItem ( DefaultItem sel)
inlineprivate
template<class T>
void HoverRace::Display::PickList< T >::SetSelection ( const boost::optional< size_t > &  newSel)
inlineoverrideprotectedvirtual

Set the selected item by index.

The implementation should update the child widget state and trigger the valueChanged signal.

Parameters
newSelThe new selected index.

Implements HoverRace::Display::BasePickList.

template<class T>
void HoverRace::Display::PickList< T >::SetValue ( const T &  val)
inline

Set the selected value.

If none of the items in this list match the value, then no item will be selected.

Parameters
valThe value.

Member Data Documentation

template<class T>
std::vector<ItemChild> HoverRace::Display::PickList< T >::items
private
template<class T>
Mode HoverRace::Display::PickList< T >::mode
private

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