UIHorizontalStack.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include <TestFramework.h>
  5. #include <UI/UIHorizontalStack.h>
  6. JPH_IMPLEMENT_RTTI_VIRTUAL(UIHorizontalStack)
  7. {
  8. JPH_ADD_BASE_CLASS(UIHorizontalStack, UIElement)
  9. }
  10. void UIHorizontalStack::sUniformChildWidth(UIElement *inParent)
  11. {
  12. Array<int> sizes;
  13. sizes.resize(1);
  14. for (UIElement *e : inParent->GetChildren())
  15. {
  16. e->AutoLayout();
  17. UIHorizontalStack *horiz = DynamicCast<UIHorizontalStack>(e);
  18. if (horiz != nullptr)
  19. {
  20. if (horiz->GetNumChildren() > (int)sizes.size())
  21. sizes.resize(horiz->GetNumChildren());
  22. for (int i = 0; i < horiz->GetNumChildren(); ++i)
  23. sizes[i] = max(sizes[i], horiz->GetChild(i)->GetWidth());
  24. }
  25. else
  26. {
  27. sizes[0] = max(sizes[0], e->GetWidth());
  28. }
  29. }
  30. for (UIElement *e : inParent->GetChildren())
  31. {
  32. UIHorizontalStack *horiz = DynamicCast<UIHorizontalStack>(e);
  33. if (horiz != nullptr)
  34. {
  35. for (int i = 0; i < horiz->GetNumChildren(); ++i)
  36. horiz->GetChild(i)->SetWidth(sizes[i]);
  37. }
  38. else
  39. {
  40. e->SetWidth(sizes[0]);
  41. }
  42. }
  43. }
  44. void UIHorizontalStack::AutoLayout()
  45. {
  46. UIElement::AutoLayout();
  47. mWidth.Set(0, PIXELS);
  48. for (UIElement *e : mChildren)
  49. if (e->IsVisible() || mPlaceInvisibleChildren)
  50. {
  51. e->SetRelativeX(GetWidth());
  52. mWidth.Set(GetWidth() + e->GetWidth() + e->GetPaddingRight() + mDeltaX, PIXELS);
  53. }
  54. }