25#include <mxgui/misc_inst.h>
49 GridLayout(uint8_t numRows, uint8_t numCols,
short int spacing = 0)
50 :
View(), numRows(numRows), numCols(numCols), spacing(spacing)
58 uint8_t col = position % numCols;
59 uint8_t row = (position - col) / numCols;
66 if (row >= numRows || col >= numCols)
79 if (mapChilds.count(pos) > 0)
80 return mapChilds[pos];
87 uint8_t col = position % numCols;
88 uint8_t row = position - col / numRows;
95 for (
auto it = mapChilds.begin(); it != mapChilds.end(); it++)
97 if (it->second == child)
115 this->drawBorder = drawBorder;
128 virtual void draw(mxgui::DrawingContext& context)
override
132 for (uint8_t row = 0; row < numRows; ++row)
134 for (uint8_t col = 0; col < numCols; ++col)
138 bool childSelected =
false;
139 if (mapChilds.count(pos) > 0)
141 mapChilds[pos]->draw(context);
142 childSelected = mapChilds[pos]->isSelected();
145 if (drawBorder && !childSelected)
147 context.drawRectangle(mapChildBounds[pos].topLeft(),
148 mapChildBounds[pos].bottomRight(),
161 std::vector<View*> out;
162 for (
auto it = mapChilds.begin(); it != mapChilds.end(); it++)
163 out.push_back(it->second);
168 void updateChildBounds()
174 0, (bounds.
size.
width - (numCols + 1) * spacing) / numCols);
175 childBounds.size.height = std::max(
176 0, (bounds.
size.
height - (numRows + 1) * spacing) / numRows);
178 for (uint8_t row = 0; row < numRows; ++row)
180 for (uint8_t col = 0; col < numCols; ++col)
184 childBounds.pos.x = bounds.
pos.
x + (col + 1) * spacing +
185 col * childBounds.size.width;
186 childBounds.pos.y = bounds.
pos.
y + (row + 1) * spacing +
187 row * childBounds.size.height;
189 mapChildBounds[pos] = childBounds;
190 if (mapChilds.count(pos) > 0)
191 mapChilds[pos]->setBounds(childBounds);
200 bool drawBorder =
false;
201 mxgui::Color borderColor = mxgui::white;
203 std::map<GridPosition, View*> mapChilds;
204 std::map<GridPosition, Bounds> mapChildBounds;
Displays childs in a numRows*numCols grid.
void setCell(View *child, uint8_t row, uint8_t col)
GridLayout(uint8_t numRows, uint8_t numCols, short int spacing=0)
Creates a new GridLayout.
void setCell(View *child, unsigned int position)
std::pair< uint8_t, uint8_t > GridPosition
void setBounds(Bounds bounds) override
Sets the bounds in which the view will be drawn.
std::vector< View * > getChilds() override
Returns the list of childs.
View * getCell(uint8_t row, uint8_t col)
virtual void draw(mxgui::DrawingContext &context) override
Draw the view in its bounds.
View * getCell(unsigned int position)
void setDrawBorder(bool drawBorder, mxgui::Color color=mxgui::white)
Wether to draw the borders of each cell or not.
void clearCell(View *child)
Base class for anything that can be drawn on the screen and interacted with.
virtual void draw(mxgui::DrawingContext &dc)
Draw the view in its bounds.
void invalidate()
Signal that what has been previously drawn is now invalid and has to be redrawn.
virtual void setBounds(Bounds bounds)
Sets the bounds in which the view will be drawn.
This file includes all the types the logdecoder script will decode.