| 175 | } |
| 176 | |
| 177 | void HBox::align() |
| 178 | { |
| 179 | const size_t count = getChildCount(); |
| 180 | int hStretchedCount = 0; |
| 181 | int totalWidth = 0; |
| 182 | int totalHeight = 0; |
| 183 | std::vector<std::pair<MyGUI::IntSize, bool>> sizes; |
| 184 | sizes.resize(count); |
| 185 | |
| 186 | for (size_t i = 0; i < count; ++i) |
| 187 | { |
| 188 | MyGUI::Widget* w = getChildAt(i); |
| 189 | bool hstretch = w->getUserString("HStretch") == "true"; |
| 190 | bool hidden = w->getUserString("Hidden") == "true"; |
| 191 | if (hidden) |
| 192 | continue; |
| 193 | hStretchedCount += hstretch; |
| 194 | AutoSizedWidget* aw = dynamic_cast<AutoSizedWidget*>(w); |
| 195 | if (aw) |
| 196 | { |
| 197 | sizes[i] = std::make_pair(aw->getRequestedSize(), hstretch); |
| 198 | totalWidth += aw->getRequestedSize().width; |
| 199 | totalHeight = std::max(totalHeight, aw->getRequestedSize().height); |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | sizes[i] = std::make_pair(w->getSize(), hstretch); |
| 204 | totalWidth += w->getSize().width; |
| 205 | if (!(w->getUserString("VStretch") == "true")) |
| 206 | totalHeight = std::max(totalHeight, w->getSize().height); |
| 207 | } |
| 208 | |
| 209 | if (i != count - 1) |
| 210 | totalWidth += mSpacing; |
| 211 | } |
| 212 | |
| 213 | if (mAutoResize |
| 214 | && (totalWidth + mPadding * 2 != getClientCoord().width |
| 215 | || totalHeight + mPadding * 2 != getClientCoord().height)) |
| 216 | { |
| 217 | int xmargin = getSize().width - getClientCoord().width; |
| 218 | int ymargin = getSize().height - getClientCoord().height; |
| 219 | setSize(MyGUI::IntSize(totalWidth + mPadding * 2 + xmargin, totalHeight + mPadding * 2 + ymargin)); |
| 220 | return; |
| 221 | } |
| 222 | |
| 223 | int curX = 0; |
| 224 | for (size_t i = 0; i < count; ++i) |
| 225 | { |
| 226 | if (i == 0) |
| 227 | curX += mPadding; |
| 228 | |
| 229 | MyGUI::Widget* w = getChildAt(i); |
| 230 | |
| 231 | bool hidden = w->getUserString("Hidden") == "true"; |
| 232 | if (hidden) |
| 233 | continue; |
| 234 | |