HoverRace
2.0
|
A container that arranges components into a grid that is automatically sized to the contents. More...
#include <FlexGrid.h>
Classes | |
class | BasicCell |
class | Cell |
class | CellProxy |
This is used to reference a cell of the grid without directly accessing it; useful for adding new widgets to the grid. More... | |
class | DefaultCell |
struct | Props |
Public Member Functions | |
FlexGrid (Display &display, uiLayoutFlags_t layoutFlags=0) | |
Constructor. More... | |
virtual | ~FlexGrid () |
CellProxy | At (size_t row, size_t col) |
Access a cell of the grid. More... | |
void | Clear () override |
Remove all child elements. More... | |
void | ClearFocusHint (const Control::Nav &nav) |
Clears the focus hint for a navigation direction. More... | |
void | DropFocus () override |
Force this widget to give up focus, if it is currently focused. More... | |
Cell & | GetColumnDefault (size_t col) |
Set the default cell settings for a column. More... | |
boost::optional< std::pair< size_t, size_t > > | GetFocusHint (const Control::Nav &nav) |
Get the focus hint for a given focus navigation direction. More... | |
const Vec2 & | GetMargin () const |
const Vec2 & | GetPadding () const |
bool | IsFixedHeight () const |
bool | IsFixedWidth () const |
Vec3 | Measure () override |
Calculate the size of the component. More... | |
bool | OnAction () override |
bool | OnNavigate (const Control::Nav &nav) override |
void | Reserve (size_t rows, size_t cols) |
Set a hint about how many rows and columns will be in the grid. More... | |
void | SetFixedHeight (double h) |
void | SetFixedSize (double w, double h) |
void | SetFixedWidth (double w) |
void | SetFocusHint (const Control::Nav &nav, size_t row, size_t col) |
Set a hint about what cell to focus when this grid is focused. More... | |
void | SetMargin (double width, double height) |
void | SetPadding (double width, double height) |
bool | TryFocus (const Control::Nav &nav=Control::Nav::NEUTRAL) override |
Attempts to give this widget focus. More... | |
![]() | |
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 Vec2 & | GetChildOffset () const |
Retrieve the offset to the position of the child widgets. More... | |
double | GetOpacity () const |
Retrieve the opacity. More... | |
const Vec2 & | GetSize () 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... | |
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... | |
![]() | |
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_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 |
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... | |
![]() | |
ViewModel () | |
virtual | ~ViewModel () |
View * | GetView () const |
void | PrepareRender () |
void | Render () |
void | SetView (std::unique_ptr< View > &&view) |
Static Public Member Functions | |
static Vec2 | AlignCellContents (double x, double y, double w, double h, Alignment alignment) |
Adjust the cell origin position to the position of the contents, based on the contents' alignment. More... | |
Static Public Attributes | |
static const double | AUTOSIZE = std::numeric_limits<double>::quiet_NaN() |
Indicator that the dimension of the column or table is automatic (instead of fixed). More... | |
static const size_t | BOTTOM = std::numeric_limits<size_t>::max() |
static const size_t | RIGHT = std::numeric_limits<size_t>::max() |
Protected Member Functions | |
boost::optional< std::pair< size_t, size_t > > | FindChild (UiViewModel *child) const |
Find the coordinates of a child widget. More... | |
void | Layout () override |
Adjust the size and position of any child elements. More... | |
template<class T , class... Args> | |
std::enable_if< std::is_base_of< UiViewModel, T >::value, std::shared_ptr< BasicCell< T > > >::type | NewGridCell (size_t row, size_t col, Args &&...args) |
void | OnChildRelinquishedFocus (UiViewModel &child, 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 | Reserve (size_t capacity) override |
Increase the capacity of the of this container. More... | |
![]() | |
children_t & | GetChildren () |
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... | |
![]() | |
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... | |
void | RequestLayout () |
Indicate that the current layout is out-of-date and needs to be adjusted. More... | |
Private Types | |
using | cells_t = std::vector< std::shared_ptr< Cell >> |
using | SUPER = BaseContainer |
Private Member Functions | |
bool | FocusDownFrom (size_t row, size_t col, const Control::Nav &nav) |
template<class Fn > | |
bool | FocusFrom (size_t row, size_t col, const Control::Nav &nav, Fn nextFn) |
Find the next focusable widget in a given direction. More... | |
bool | FocusLeftFrom (size_t row, size_t col, const Control::Nav &nav) |
bool | FocusNextFrom (size_t row, size_t col, const Control::Nav &nav) |
bool | FocusPrevFrom (size_t row, size_t col, const Control::Nav &nav) |
bool | FocusRightFrom (size_t row, size_t col, const Control::Nav &nav) |
bool | FocusUpFrom (size_t row, size_t col, const Control::Nav &nav) |
void | SetFocusedCell (size_t row, size_t col) |
Private Attributes | |
size_t | colReserve |
std::vector< DefaultCell > | defaultCols |
Vec2 | fixedSize |
boost::optional< std::pair< size_t, size_t > > | focusedCell |
std::map< Control::Nav::dir_t, std::pair< size_t, size_t > > | focusHints |
Vec2 | margin |
Vec2 | padding |
std::vector< cells_t > | rows |
Vec2 | size |
Additional Inherited Members | |
![]() | |
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 &)> |
![]() | |
using | children_t = std::vector< std::unique_ptr< Child >> |
![]() | |
Display & | display |
A container that arranges components into a grid that is automatically sized to the contents.
|
private |
|
private |
HoverRace::Display::FlexGrid::FlexGrid | ( | Display & | display, |
uiLayoutFlags_t | layoutFlags = 0 |
||
) |
Constructor.
display | The display child elements will be attached to. |
layoutFlags | Optional layout flags. |
|
inlinevirtual |
|
static |
Adjust the cell origin position to the position of the contents, based on the contents' alignment.
x | The upper-left corner of the cell, relative to the grid. |
y | The upper-left corner of the cell, relative to the grid. |
w | The width of the cell, not including padding. |
h | The height of the cell, not including padding. |
alignment | The alignment of the cell contents. |
|
inline |
Access a cell of the grid.
This is usually used to add new widgets to the grid, but can also be used to change attributes of the cell without accessing the contents. If adding new widgets, the row and column don't need to already exist.
row | The row index. |
col | The column index. |
|
overridevirtual |
Remove all child elements.
Reimplemented from HoverRace::Display::BaseContainer.
void HoverRace::Display::FlexGrid::ClearFocusHint | ( | const Control::Nav & | nav | ) |
Clears the focus hint for a navigation direction.
nav | The navigation. |
|
overridevirtual |
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 from HoverRace::Display::UiViewModel.
|
protected |
Find the coordinates of a child widget.
child | The widget to search for (may be nullptr ). |
|
private |
|
inlineprivate |
Find the next focusable widget in a given direction.
The starting coordinates are not focused; instead, the next widget in the direction nav
is the first to be focused.
The nextFn
callback function will take the row and column as references, so it can advance them to the next coordinate. It returns true
if it was successful, false
if we advanced off the edge of the grid.
row | The starting row. |
col | The starting column. |
nav | The navigation direction. |
nextFn | The function to advance the coordinates. |
true
if it succeeded in focusing a widget, false
if it failed (could not find a focusable widget).
|
private |
|
private |
|
private |
|
private |
|
private |
|
inline |
Set the default cell settings for a column.
This does not retro-actively set the defaults for cells already added.
col | The column coordinate (starting at zero). |
boost::optional< std::pair< size_t, size_t > > HoverRace::Display::FlexGrid::GetFocusHint | ( | const Control::Nav & | nav | ) |
Get the focus hint for a given focus navigation direction.
nav | The navigation direction. |
|
inline |
|
inline |
bool HoverRace::Display::FlexGrid::IsFixedHeight | ( | ) | const |
bool HoverRace::Display::FlexGrid::IsFixedWidth | ( | ) | const |
|
overrideprotectedvirtual |
Adjust the size and position of any child elements.
Subclasses with child elements should override this function.
This is called automatically during the PrepareRender() phase if RequestLayout() has been called. It is also called the first time PrepareRender() is invoked. After this function is called, it will not be called again until another call to RequestLayout().
Reimplemented from HoverRace::Display::ViewModel.
|
overridevirtual |
Calculate the size of the component.
For UI components, the return value is affected by layout flags.
Reimplemented from HoverRace::Display::BaseContainer.
|
inlineprotected |
|
inlineoverridevirtual |
Reimplemented from HoverRace::Display::UiViewModel.
|
overrideprotectedvirtual |
Called when a child widget passes input focus to another widget.
child | The child widget. |
nav | The navigation direction. |
Reimplemented from HoverRace::Display::BaseContainer.
|
overrideprotectedvirtual |
Called when a child widget requests input focus.
child | The child widget. |
Reimplemented from HoverRace::Display::BaseContainer.
|
inlineoverridevirtual |
Reimplemented from HoverRace::Display::UiViewModel.
|
inlineoverrideprotectedvirtual |
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.
capacity | The new capacity. |
Reimplemented from HoverRace::Display::BaseContainer.
void HoverRace::Display::FlexGrid::Reserve | ( | size_t | rowCapacity, |
size_t | colCapacity | ||
) |
Set a hint about how many rows and columns will be in the grid.
The internal capacity will be increased (never decreased). This is useful as a hint to prevent re-allocation due to resizing the internal storage.
This function assumes that every cell of the grid will be filled. If the grid is sparse, then it is better to not call this function and let the automatic resizing occur.
rowCapacity | The estimated number of rows. |
colCapacity | The estimated number of columns per row. |
void HoverRace::Display::FlexGrid::SetFixedHeight | ( | double | h | ) |
void HoverRace::Display::FlexGrid::SetFixedSize | ( | double | w, |
double | h | ||
) |
void HoverRace::Display::FlexGrid::SetFixedWidth | ( | double | w | ) |
|
private |
void HoverRace::Display::FlexGrid::SetFocusHint | ( | const Control::Nav & | nav, |
size_t | row, | ||
size_t | col | ||
) |
Set a hint about what cell to focus when this grid is focused.
When the grid takes focus, the grid searches for a focusable cell. This automatic search may not produce results which are "natural" for the grid position, so this provides a way to set a hint about what cell to start the search from.
Because the size of the grid can change, the constants BOTTOM and RIGHT can be used to refer to bottommost or rightmost row or column, respectively.
nav | The navigation direction. |
row | The row (may be BOTTOM to refer to the bottom row). |
col | The col. |
void HoverRace::Display::FlexGrid::SetMargin | ( | double | width, |
double | height | ||
) |
void HoverRace::Display::FlexGrid::SetPadding | ( | double | width, |
double | height | ||
) |
|
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.
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 from HoverRace::Display::UiViewModel.
|
static |
Indicator that the dimension of the column or table is automatic (instead of fixed).
|
static |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
static |
|
private |
|
private |