21 #include <ListLayout.h> 22 #include <Dimension.h> 28 #include <IHudDrawable.h> 33 this->orientation = orientation;
37 float layoutHeight, map<string,IHudDrawable*>* list){
42 float unitsLeft = orientation == HORIZONTAL ? layoutWidth : layoutHeight;
43 for(
Layout* child : children) {
44 Dimension dimension = orientation == HORIZONTAL ? child->getWidth() : child->getHeight();
45 if (dimension.
getUnit() == Dimension::FILL)
47 else if(dimension.
getUnit() == Dimension::PERCENTAGE || dimension.
getUnit() == Dimension::PIXELS)
48 unitsLeft -= dimension.
getSize(orientation == HORIZONTAL ? layoutWidth : layoutHeight);
51 float xpos = layoutXPos, ypos = layoutYPos, width,height, calculatedPos;
52 for(
Layout* child : children){
53 Dimension dimension = orientation == HORIZONTAL ? child->getWidth() : child->getHeight();
54 if (dimension.
getUnit() == Dimension::FILL)
55 calculatedPos = unitsLeft/(
float)weights*(float)dimension.
getWeight();
57 calculatedPos = dimension.
getSize(orientation == HORIZONTAL ? layoutWidth : layoutHeight);
59 if(orientation == HORIZONTAL){
60 width = calculatedPos;
62 height = heightDim.
getUnit() == Dimension::FILL ? layoutHeight : heightDim.
getSize(layoutHeight);
65 width = widthDim.
getUnit() == Dimension::FILL ? layoutWidth : widthDim.
getSize(layoutHeight);
66 height = calculatedPos;
68 child->getGLSquares(xpos,ypos,width,height,list);
69 if(orientation == HORIZONTAL){
78 if(width.
getUnit() != Dimension::WRAP)
85 if(height.
getUnit() != Dimension::WRAP)
91 unsigned int ListLayout::wrapSize(Orientation parentOrientation) {
92 unsigned int wrapSize = 0;
93 for(
Layout* child : children){
94 Dimension childDim = parentOrientation == HORIZONTAL ? child->getWidth() : child->getHeight();
97 if(parentOrientation == orientation)
100 wrapSize = max(wrapSize,(
unsigned int)childDim.
getPixels());
106 checkChildCompatibility(child);
107 Layout::addChild(child);
110 void ListLayout::checkChildCompatibility(
Layout *child) {
111 Dimension thisDim = orientation == HORIZONTAL ? width : height;
112 Dimension childDim = orientation == HORIZONTAL ? child->getWidth() : child->getHeight();
113 if(thisDim.
getUnit() == Dimension::WRAP &&
114 !(childDim.
getUnit() == Dimension::WRAP || childDim.
getUnit() == Dimension::PIXELS)){
115 string err = string(
"The child of a wrapping layout can only use Dimension::WRAP or Dimension::PIXELS ") +
116 "in the same orientation as the parent as these aren't dependent on the parent size.";
117 throw invalid_argument(err.c_str());
virtual std::map< std::string, IHudDrawable * > getGLSquares(float layoutXPos, float layoutYPos, float layoutWidth, float layoutHeight)
virtual void addChild(Layout *child)
ListLayout(Orientation orientation, Dimension width, Dimension height)
float getSize(float room)
static Dimension fromPixels(int pixels)
virtual void getGLSquares(float layoutXPos, float layoutYPos, float layoutWidth, float layoutHeight, std::map< std::string, IHudDrawable * > *map)