GUI2/Grid: added child getter by contained widget

This commit is contained in:
Charles Dang 2017-04-08 11:24:00 +11:00
parent 8c4e09e940
commit 2053362c97
2 changed files with 64 additions and 24 deletions

View file

@ -931,6 +931,21 @@ point grid::child::border_space() const
return result;
}
grid::child* grid::get_child(widget* w)
{
if(!w) {
return nullptr;
}
for(auto& child : children_) {
if(w == child.get_widget()) {
return &child;
}
}
return nullptr;
}
void grid::layout(const point& origin)
{
point orig = origin;

View file

@ -37,27 +37,25 @@ public:
virtual ~grid();
/***** ***** ***** ***** LAYOUT FLAGS ***** ***** ***** *****/
static const unsigned VERTICAL_SHIFT = 0;
static const unsigned VERTICAL_GROW_SEND_TO_CLIENT = 1 << VERTICAL_SHIFT;
static const unsigned VERTICAL_ALIGN_TOP = 2 << VERTICAL_SHIFT;
static const unsigned VERTICAL_ALIGN_CENTER = 3 << VERTICAL_SHIFT;
static const unsigned VERTICAL_ALIGN_BOTTOM = 4 << VERTICAL_SHIFT;
static const unsigned VERTICAL_MASK = 7 << VERTICAL_SHIFT;
static const unsigned VERTICAL_SHIFT = 0;
static const unsigned VERTICAL_GROW_SEND_TO_CLIENT = 1 << VERTICAL_SHIFT;
static const unsigned VERTICAL_ALIGN_TOP = 2 << VERTICAL_SHIFT;
static const unsigned VERTICAL_ALIGN_CENTER = 3 << VERTICAL_SHIFT;
static const unsigned VERTICAL_ALIGN_BOTTOM = 4 << VERTICAL_SHIFT;
static const unsigned VERTICAL_MASK = 7 << VERTICAL_SHIFT;
static const unsigned HORIZONTAL_SHIFT = 3;
static const unsigned HORIZONTAL_GROW_SEND_TO_CLIENT = 1
<< HORIZONTAL_SHIFT;
static const unsigned HORIZONTAL_ALIGN_LEFT = 2 << HORIZONTAL_SHIFT;
static const unsigned HORIZONTAL_ALIGN_CENTER = 3 << HORIZONTAL_SHIFT;
static const unsigned HORIZONTAL_ALIGN_RIGHT = 4 << HORIZONTAL_SHIFT;
static const unsigned HORIZONTAL_MASK = 7 << HORIZONTAL_SHIFT;
static const unsigned HORIZONTAL_SHIFT = 3;
static const unsigned HORIZONTAL_GROW_SEND_TO_CLIENT = 1 << HORIZONTAL_SHIFT;
static const unsigned HORIZONTAL_ALIGN_LEFT = 2 << HORIZONTAL_SHIFT;
static const unsigned HORIZONTAL_ALIGN_CENTER = 3 << HORIZONTAL_SHIFT;
static const unsigned HORIZONTAL_ALIGN_RIGHT = 4 << HORIZONTAL_SHIFT;
static const unsigned HORIZONTAL_MASK = 7 << HORIZONTAL_SHIFT;
static const unsigned BORDER_TOP = 1 << 6;
static const unsigned BORDER_BOTTOM = 1 << 7;
static const unsigned BORDER_LEFT = 1 << 8;
static const unsigned BORDER_RIGHT = 1 << 9;
static const unsigned BORDER_ALL = BORDER_TOP | BORDER_BOTTOM | BORDER_LEFT
| BORDER_RIGHT;
static const unsigned BORDER_TOP = 1 << 6;
static const unsigned BORDER_BOTTOM = 1 << 7;
static const unsigned BORDER_LEFT = 1 << 8;
static const unsigned BORDER_RIGHT = 1 << 9;
static const unsigned BORDER_ALL = BORDER_TOP | BORDER_BOTTOM | BORDER_LEFT | BORDER_RIGHT;
/***** ***** ***** ***** ROW COLUMN MANIPULATION ***** ***** ***** *****/
@ -112,7 +110,7 @@ public:
*
* @param widget The widget to put in the grid.
* @param row The row of the cell.
* @param col The columnof the cell.
* @param col The column of the cell.
* @param flags The flags for the widget in the cell.
* @param border_size The size of the border for the cell, how the
* border is applied depends on the flags.
@ -147,7 +145,7 @@ public:
* Removes and frees a widget in a cell.
*
* @param row The row of the cell.
* @param col The columnof the cell.
* @param col The column of the cell.
*/
void remove_child(const unsigned row, const unsigned col);
@ -171,7 +169,6 @@ public:
*/
void set_active(const bool active);
/** Returns the widget in the selected cell. */
const widget* get_widget(const unsigned row, const unsigned col) const
{
@ -479,15 +476,43 @@ private:
* is: rows_ * col + row. All other vectors use the same access formula.
*/
std::vector<child> children_;
const child& get_child(const unsigned row, const unsigned col) const
/**
* Gets the grid child in the specified cell.
*
* @param row The row of the cell.
* @param col The column of the cell.
*
* @returns A const reference to the specified grid child.
*/
const grid::child& get_child(const unsigned row, const unsigned col) const
{
return children_[rows_ * col + row];
}
child& get_child(const unsigned row, const unsigned col)
/**
* Gets the grid child in the specified cell.
*
* @param row The row of the cell.
* @param col The column of the cell.
*
* @returns A const reference to the specified grid child.
*/
grid::child& get_child(const unsigned row, const unsigned col)
{
return children_[rows_ * col + row];
}
/**
* Gets the grid child containing the specified widget.
*
* @param w The widget to search for.
*
* @returns A pointer to the relevant grid child, or nullptr
* if no grid cell 'owns' the given widget.
*/
grid::child* get_child(widget* w);
/** Layouts the children in the grid. */
void layout(const point& origin);