Chesto 0.9
A declarative and element-based library for creating GUIs on homebrew'd consoles
Container.cpp
1#include <algorithm>
2#include "Container.hpp"
3
4Container::Container(int layout, int padding)
5{
6 // these values only affect adds into this container
7 this->layout = layout;
8 this->padding = padding;
9}
10
11Element* Container::add(Element* elem)
12{
13 int newPosX = (layout == ROW_LAYOUT) ? this->width + padding : this->x;
14 int newPosY = (layout == COL_LAYOUT) ? this->height + padding : this->y;
15
16 child(elem->setPosition(newPosX, newPosY));
17
18 this->width = (layout == ROW_LAYOUT) ? this->width + elem->width + padding : std::max(this->width, elem->width);
19 this->height = (layout == COL_LAYOUT) ? this->height + elem->height + padding : std::max(this->height, elem->height);
20
21 return elem;
22}
int width
width and height of this element (must be manually set, isn't usually calculated (but is in some case...
Definition: Element.hpp:118