24 #include "../Exception.h" 28 #if defined(_WIN32) && defined(HR_ENGINE_SHARED) 30 # define MR_DllDeclare __declspec( dllexport ) 32 # define MR_DllDeclare __declspec( dllimport ) 35 # define MR_DllDeclare 61 MARGIN = SUPER::Props::NEXT_,
75 return rows[focusedCell->first][focusedCell->second]->OnAction();
83 return rows[focusedCell->first][focusedCell->second]->
90 void OnChildRequestedFocus(
UiViewModel &child)
override;
95 void SetFocusedCell(
size_t row,
size_t col);
124 while (nextFn(row, col)) {
125 auto &cols = rows[
row];
126 if (col >= cols.size())
break;
128 auto &cell = cols[
col];
129 if (cell && cell->TryFocus(nav)) {
130 SetFocusedCell(row, col);
138 bool FocusUpFrom(
size_t row,
size_t col,
const Control::Nav &nav);
139 bool FocusDownFrom(
size_t row,
size_t col,
const Control::Nav &nav);
140 bool FocusLeftFrom(
size_t row,
size_t col,
const Control::Nav &nav);
141 bool FocusRightFrom(
size_t row,
size_t col,
const Control::Nav &nav);
142 bool FocusNextFrom(
size_t row,
size_t col,
const Control::Nav &nav);
143 bool FocusPrevFrom(
size_t row,
size_t col,
const Control::Nav &nav);
147 void DropFocus()
override;
151 void SetMargin(
double width,
double height);
154 void SetPadding(
double width,
double height);
158 bool IsFixedWidth()
const;
159 bool IsFixedHeight()
const;
160 void SetFixedSize(
double w,
double h);
161 void SetFixedWidth(
double w);
162 void SetFixedHeight(
double h);
167 boost::optional<std::pair<size_t, size_t>> GetFocusHint(
169 void SetFocusHint(
const Control::Nav &nav,
size_t row,
size_t col);
173 static Vec2 AlignCellContents(
double x,
double y,
double w,
double h,
189 virtual void SetAlignment(
Alignment alignment) = 0;
200 virtual void SetFill(
bool fill) = 0;
212 virtual void SetExtents(
double x,
double y,
213 double w,
double h,
double paddingX,
double paddingY) = 0;
219 virtual Vec3 Measure() = 0;
225 virtual void DropFocus() = 0;
228 virtual bool OnAction() = 0;
238 virtual bool Contains(
const UiViewModel *child)
const = 0;
250 alignment(o.alignment), fill(o.fill) { }
265 this->alignment = alignment;
277 double,
double)
override { }
297 std::shared_ptr<T> contents) :
298 SUPER(), parent(parent), contents(
std::move(contents)),
299 fill(defaultCell.IsFill())
306 parent->RemoveChild(contents);
315 if (alignment != contents->GetAlignment()) {
316 contents->SetAlignment(alignment);
317 parent->RequestLayout();
334 double paddingX,
double paddingY)
override 337 w - (paddingX * 2), h - (paddingY * 2),
338 contents->GetAlignment());
339 contents->SetPos(pos.
x + paddingX, pos.
y + paddingY);
347 return contents->Measure();
352 return contents->TryFocus(nav);
357 contents->DropFocus();
362 return contents->OnAction();
367 return contents->OnNavigate(nav);
372 return contents.get() == child;
395 SUPER(), row(row), col(col), grid(grid), cell(cell) { }
408 std::ostringstream oss;
409 oss <<
"Cell at row=" << row <<
", col=" << col <<
421 CheckCell()->SetAlignment(alignment);
426 CheckCell()->SetFill(fill);
432 double paddingX,
double paddingY)
override 434 CheckCell()->SetExtents(x, y, w, h, paddingX, paddingY);
439 return CheckCell()->Measure();
444 return CheckCell()->TryFocus(nav);
449 CheckCell()->DropFocus();
454 return CheckCell()->OnAction();
459 return CheckCell()->OnNavigate(nav);
464 return CheckCell()->Contains(child);
479 template<
class T,
class... Args>
480 typename std::enable_if<
481 std::is_base_of<UiViewModel, T>::value,
482 std::shared_ptr<BasicCell<T>>
486 return grid.NewGridCell<T>(
row,
col, std::forward<Args>(args)...);
510 Cell *cell =
nullptr;
511 if (row < rows.size()) {
512 if (col < rows[row].size()) {
513 cell = rows[
row][
col].get();
516 return {
row,
col, *
this, cell };
530 if (col >= defaultCols.size()) {
531 defaultCols.resize(col + 1);
534 return defaultCols[
col];
538 template<
class T,
class... Args>
539 typename std::enable_if<
540 std::is_base_of<UiViewModel, T>::value,
541 std::shared_ptr<BasicCell<T>>
545 auto sharedChild = NewChild<T>(std::forward<Args>(args)...);
548 if (row >= rows.size()) {
549 size_t oldSize = rows.size();
550 rows.resize(row + 1);
551 if (colReserve > 0) {
552 auto iter = rows.begin();
553 std::advance(iter, oldSize);
554 for (; iter != rows.end(); ++iter) {
555 iter->reserve(colReserve);
559 auto &cols = rows[
row];
560 if (col >= cols.size()) {
561 cols.resize(col + 1);
562 if (col >= defaultCols.size()) {
563 defaultCols.resize(col + 1);
567 std::shared_ptr<BasicCell<T>> cell =
568 std::make_shared<BasicCell<T>>(
this, defaultCols[
col],
579 boost::optional<std::pair<size_t, size_t>> FindChild(
583 void Clear()
override;
588 void Reserve(
size_t capacity)
override { SUPER::Reserve(capacity); }
590 void Reserve(
size_t rows,
size_t cols);
593 void Layout()
override;
596 Vec3 Measure()
override;
604 std::map<Control::Nav::dir_t, std::pair<size_t, size_t>>
focusHints;
605 using cells_t = std::vector<std::shared_ptr<Cell>>;
size_t col
Definition: FlexGrid.h:491
bool fill
Definition: FlexGrid.h:287
bool fill
Definition: FlexGrid.h:381
Vec2 margin
Definition: FlexGrid.h:599
std::vector< cells_t > rows
Definition: FlexGrid.h:607
void Reserve(size_t capacity) override
Increase the capacity of the of this container.
Definition: FlexGrid.h:588
bool FocusFrom(size_t row, size_t col, const Control::Nav &nav, Fn nextFn)
Find the next focusable widget in a given direction.
Definition: FlexGrid.h:122
std::shared_ptr< T > & GetContents()
Definition: FlexGrid.h:376
bool Contains(const UiViewModel *child) const override
Check if this contains the specified widget.
Definition: FlexGrid.h:370
void SetAlignment(Alignment alignment) override
Set the how the widget is aligned inside the cell when the cell is larger than the widget...
Definition: FlexGrid.h:419
static const double AUTOSIZE
Indicator that the dimension of the column or table is automatic (instead of fixed).
Definition: FlexGrid.h:156
static const size_t RIGHT
Definition: FlexGrid.h:165
FlexGrid & grid
Definition: FlexGrid.h:492
Vec2 fixedSize
Definition: FlexGrid.h:602
Vec3 Measure() override
Measure the size of the cell contents.
Definition: FlexGrid.h:278
std::enable_if< MPL::HasSetSize< T >::value, void >::type SetSize(T &widget, double w, double h)
Definition: MPL.h:60
std::enable_if< std::is_base_of< UiViewModel, T >::value, std::shared_ptr< BasicCell< T > > >::type NewChild(Args &&...args)
Creates a new child widget in this cell.
Definition: FlexGrid.h:484
double y
Definition: Vec.h:45
Base class for UI (2D) components.
Definition: UiViewModel.h:56
bool OnNavigate(const Control::Nav &nav) override
Trigger OnNavigate() on the contents.
Definition: FlexGrid.h:457
const Vec2 & GetPadding() const
Definition: FlexGrid.h:153
FlexGrid * parent
Definition: FlexGrid.h:379
Alignment
Imagine the component pinned to the container with a thumbtack.
Definition: UiViewModel.h:77
size_t row
Definition: FlexGrid.h:490
BasicCell(FlexGrid *parent, const DefaultCell &defaultCell, std::shared_ptr< T > contents)
Definition: FlexGrid.h:296
Definition: FlexGrid.h:242
Cell * CheckCell() const
Definition: FlexGrid.h:405
Definition: FlexGrid.h:176
void SetFill(bool fill) override
Set whether the widget is resized to fill the space of the cell.
Definition: FlexGrid.h:321
bool TryFocus(const Control::Nav &nav) override
Trigger TryFocus() on the contents.
Definition: FlexGrid.h:350
Definition: FlexGrid.h:57
std::vector< std::shared_ptr< Cell >> cells_t
Definition: FlexGrid.h:605
bool OnAction() override
Trigger OnAction() on the contents.
Definition: FlexGrid.h:281
std::map< Control::Nav::dir_t, std::pair< size_t, size_t > > focusHints
Definition: FlexGrid.h:604
CellProxy At(size_t row, size_t col)
Access a cell of the grid.
Definition: FlexGrid.h:508
Alignment alignment
Definition: FlexGrid.h:286
void SetAlignment(Alignment alignment) override
Set the how the widget is aligned inside the cell when the cell is larger than the widget...
Definition: FlexGrid.h:310
CellProxy(size_t row, size_t col, FlexGrid &grid, Cell *cell)
Definition: FlexGrid.h:394
Base class for widgets that contain other widgets.
Definition: BaseContainer.h:63
void DropFocus() override
Trigger DropFocus() on the contents.
Definition: FlexGrid.h:447
virtual ~DefaultCell()
Definition: FlexGrid.h:251
void SetAlignment(Alignment alignment) override
Set the how the widget is aligned inside the cell when the cell is larger than the widget...
Definition: FlexGrid.h:263
size_t colReserve
Definition: FlexGrid.h:603
double x
Definition: Vec.h:44
MR_UInt32 uiLayoutFlags_t
Definition: UiLayoutFlags.h:53
void SetFill(bool fill) override
Set whether the widget is resized to fill the space of the cell.
Definition: FlexGrid.h:270
void SetExtents(double, double, double, double, double, double) override
Set the position and size of the cell.
Definition: FlexGrid.h:276
Vec3 Measure() override
Measure the size of the cell contents.
Definition: FlexGrid.h:437
void DropFocus() override
Trigger DropFocus() on the contents.
Definition: FlexGrid.h:280
virtual ~FlexGrid()
Definition: FlexGrid.h:69
bool Contains(const UiViewModel *child) const override
Check if this contains the specified widget.
Definition: FlexGrid.h:462
Cell()
Definition: FlexGrid.h:180
Cell & GetColumnDefault(size_t col)
Set the default cell settings for a column.
Definition: FlexGrid.h:528
Base class for display managers.
Definition: Display.h:73
void SetExtents(double x, double y, double w, double h, double paddingX, double paddingY) override
Set the position and size of the cell.
Definition: FlexGrid.h:332
std::vector< DefaultCell > defaultCols
Definition: FlexGrid.h:606
size_t row
Definition: TestLabScene.cpp:163
Vec2 size
Definition: FlexGrid.h:601
bool OnNavigate(const Control::Nav &nav) override
Definition: FlexGrid.h:80
This is used to reference a cell of the grid without directly accessing it; useful for adding new wid...
Definition: FlexGrid.h:389
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)
Definition: FlexGrid.h:543
bool OnNavigate(const Control::Nav &nav) override
Trigger OnNavigate() on the contents.
Definition: FlexGrid.h:365
bool OnAction() override
Trigger OnAction() on the contents.
Definition: FlexGrid.h:452
virtual ~Cell()
Definition: FlexGrid.h:181
virtual ~BasicCell()
Definition: FlexGrid.h:304
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...
Definition: FlexGrid.cpp:430
boost::optional< std::pair< size_t, size_t > > focusedCell
Definition: FlexGrid.h:608
Definition: FlexGrid.h:62
void SetSize(double w, double h)
Definition: FlexGrid.h:327
A navigation direction.
Definition: Nav.h:45
#define MR_DllDeclare
Definition: FlexGrid.h:35
A container that arranges components into a grid that is automatically sized to the contents...
Definition: FlexGrid.h:52
Cell * cell
Definition: FlexGrid.h:493
DefaultCell(DefaultCell &&o)
Definition: FlexGrid.h:249
DefaultCell()
Definition: FlexGrid.h:247
bool TryFocus(const Control::Nav &nav) override
Trigger TryFocus() on the contents.
Definition: FlexGrid.h:442
bool IsFill() const
Definition: FlexGrid.h:268
void DropFocus() override
Trigger DropFocus() on the contents.
Definition: FlexGrid.h:355
bool OnNavigate(const Control::Nav &) override
Trigger OnNavigate() on the contents.
Definition: FlexGrid.h:282
Definition: FlexGrid.h:291
std::shared_ptr< T > contents
Definition: FlexGrid.h:380
Definition: Announcement.h:24
Alignment GetAlignment() const
Definition: FlexGrid.h:261
void SetFill(bool fill) override
Set whether the widget is resized to fill the space of the cell.
Definition: FlexGrid.h:424
void SetExtents(double x, double y, double w, double h, double paddingX, double paddingY) override
Set the position and size of the cell.
Definition: FlexGrid.h:430
bool Contains(const UiViewModel *) const override
Check if this contains the specified widget.
Definition: FlexGrid.h:283
bool OnAction() override
Trigger OnAction() on the contents.
Definition: FlexGrid.h:360
DefaultCell & operator=(DefaultCell &&o)
Definition: FlexGrid.h:254
Base exception, providing constructors for setting the message.
Definition: Exception.h:42
virtual ~CellProxy()
Definition: FlexGrid.h:398
Vec2 padding
Definition: FlexGrid.h:600
bool OnAction() override
Definition: FlexGrid.h:72
static const size_t BOTTOM
Definition: FlexGrid.h:164
const Vec2 & GetMargin() const
Definition: FlexGrid.h:150
Vec3 Measure() override
Measure the size of the cell contents.
Definition: FlexGrid.h:345
bool TryFocus(const Control::Nav &) override
Trigger TryFocus() on the contents.
Definition: FlexGrid.h:279
First index for subclasses.
Definition: FlexGrid.h:63
size_t col
Definition: ProfileEditScene.cpp:151