@@ -59,6 +59,7 @@ void LinearHorizontalLayoutManager::doLayout(LayoutProtocol* layout)
5959 LinearLayoutParameter::LinearGravity childGravity = layoutParameter->getGravity ();
6060 Vec2 ap = child->getAnchorPoint ();
6161 Size cs = child->getBoundingBox ().size ;
62+ Margin mg = layoutParameter->getMargin ();
6263 float finalPosX = leftBoundary + (ap.x * cs.width );
6364 float finalPosY = layoutSize.height - (1 .0f - ap.y ) * cs.height ;
6465 switch (childGravity)
@@ -67,15 +68,14 @@ void LinearHorizontalLayoutManager::doLayout(LayoutProtocol* layout)
6768 case LinearLayoutParameter::LinearGravity::TOP:
6869 break ;
6970 case LinearLayoutParameter::LinearGravity::BOTTOM:
70- finalPosY = ap.y * cs.height ;
71+ finalPosY = ap.y * cs.height + mg. top ; // Add top margin to counter having it subtracted below from finalPosY
7172 break ;
7273 case LinearLayoutParameter::LinearGravity::CENTER_VERTICAL:
73- finalPosY = layoutSize.height / 2 .0f - cs.height * (0 .5f - ap.y );
74+ finalPosY = layoutSize.height / 2 .0f - cs.height * (0 .5f - ap.y ) + mg. top ; // Add top margin to counter having it subtracted below from finalPosY
7475 break ;
7576 default :
7677 break ;
7778 }
78- Margin mg = layoutParameter->getMargin ();
7979 finalPosX += mg.left ;
8080 finalPosY -= mg.top ;
8181 child->setPosition (Vec2 (finalPosX, finalPosY));
@@ -117,6 +117,7 @@ void LinearVerticalLayoutManager::doLayout(LayoutProtocol* layout)
117117 LinearLayoutParameter::LinearGravity childGravity = layoutParameter->getGravity ();
118118 Vec2 ap = subWidget->getAnchorPoint ();
119119 Size cs = subWidget->getBoundingBox ().size ;
120+ Margin mg = layoutParameter->getMargin ();
120121 float finalPosX = ap.x * cs.width ;
121122 float finalPosY = topBoundary - ((1 .0f -ap.y ) * cs.height );
122123 switch (childGravity)
@@ -125,15 +126,14 @@ void LinearVerticalLayoutManager::doLayout(LayoutProtocol* layout)
125126 case LinearLayoutParameter::LinearGravity::LEFT:
126127 break ;
127128 case LinearLayoutParameter::LinearGravity::RIGHT:
128- finalPosX = layoutSize.width - ((1 .0f - ap.x ) * cs.width );
129+ finalPosX = layoutSize.width - ((1 .0f - ap.x ) * cs.width ) - mg. left ; // Subtract left margin to counter having it added below to finalPosX
129130 break ;
130131 case LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL:
131- finalPosX = layoutSize.width / 2 .0f - cs.width * (0 .5f -ap.x );
132+ finalPosX = layoutSize.width / 2 .0f - cs.width * (0 .5f -ap.x ) - mg. left ; // Subtract left margin to counter having it added below to finalPosX
132133 break ;
133134 default :
134135 break ;
135136 }
136- Margin mg = layoutParameter->getMargin ();
137137 finalPosX += mg.left ;
138138 finalPosY -= mg.top ;
139139 subWidget->setPosition (finalPosX, finalPosY);
0 commit comments