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
4namespace Chesto {
5
6Container::Container(int layout, int padding)
7{
8 // these values only affect adds into this container
9 this->layout = layout;
10 this->padding = padding;
11}
12
13Element* Container::add(std::unique_ptr<Element> elem)
14{
15 int newPosX = (layout == ROW_LAYOUT) ? this->width + padding : this->x;
16 int newPosY = (layout == COL_LAYOUT) ? this->height + padding : this->y;
17
18 Element* rawPtr = elem.get();
19 rawPtr->setPosition(newPosX, newPosY);
20 addNode(std::move(elem)); // transfers ownership
21
22 this->width = (layout == ROW_LAYOUT) ? this->width + rawPtr->width + padding : std::max(this->width, rawPtr->width);
23 this->height = (layout == COL_LAYOUT) ? this->height + rawPtr->height + padding : std::max(this->height, rawPtr->height);
24
25 return rawPtr;
26}
27
28} // namespace Chesto
int width
width and height of this element (must be manually set, isn't usually calculated (but is in some case...
Definition: Element.hpp:132