UiLayoutHelpers.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <LyShine/Bus/UiLayoutBus.h>
  10. #include <LyShine/Bus/UiTransformBus.h>
  11. namespace UiLayoutHelpers
  12. {
  13. struct LayoutCellSize
  14. {
  15. LayoutCellSize();
  16. float m_minSize;
  17. float m_targetSize;
  18. float m_maxSize;
  19. float m_extraSizeRatio;
  20. };
  21. using LayoutCellSizes = AZStd::vector<LayoutCellSize>;
  22. ////////////////////////////////////////////////////////////////////////////////////////////////////
  23. //! Get a list of layout cell widths corresponding to the children of the layout element
  24. void GetLayoutCellWidths(AZ::EntityId elementId, bool ignoreDefaultLayoutCells, LayoutCellSizes& layoutCellsOut);
  25. ////////////////////////////////////////////////////////////////////////////////////////////////////
  26. //! Get a list of layout cell heights corresponding to the children of the layout element
  27. void GetLayoutCellHeights(AZ::EntityId elementId, bool ignoreDefaultLayoutCells, LayoutCellSizes& layoutCellsOut);
  28. ////////////////////////////////////////////////////////////////////////////////////////////////////
  29. //! Get a list of layout cell min widths corresponding to the children of the layout element
  30. AZStd::vector<float> GetLayoutCellMinWidths(AZ::EntityId elementId, bool ignoreDefaultLayoutCells);
  31. ////////////////////////////////////////////////////////////////////////////////////////////////////
  32. //! Get a list of layout cell target widths corresponding to the children of the layout element
  33. AZStd::vector<float> GetLayoutCellTargetWidths(AZ::EntityId elementId, bool ignoreDefaultLayoutCells);
  34. ////////////////////////////////////////////////////////////////////////////////////////////////////
  35. //! Get a list of layout cell min heights corresponding to the children of the layout element
  36. AZStd::vector<float> GetLayoutCellMinHeights(AZ::EntityId elementId, bool ignoreDefaultLayoutCells);
  37. ////////////////////////////////////////////////////////////////////////////////////////////////////
  38. //! Get a list of layout cell target heights corresponding to the children of the layout element
  39. AZStd::vector<float> GetLayoutCellTargetHeights(AZ::EntityId elementId, bool ignoreDefaultLayoutCells);
  40. ////////////////////////////////////////////////////////////////////////////////////////////////////
  41. //! Calculate the sizes of the elements that will occupy the available space
  42. void CalculateElementSizes(const LayoutCellSizes& layoutCells, float availableSize, float spacing, AZStd::vector<float>& sizesOut);
  43. ////////////////////////////////////////////////////////////////////////////////////////////////////
  44. //! Calculate the size of a single element that will occupy the available space
  45. float CalculateSingleElementSize(const LayoutCellSize& layoutCell, float availableSize);
  46. ////////////////////////////////////////////////////////////////////////////////////////////////////
  47. //! Calculate the horizontal offset for alignment
  48. float GetHorizontalAlignmentOffset(IDraw2d::HAlign hAlignment, float availableSpace, float occupiedSpace);
  49. ////////////////////////////////////////////////////////////////////////////////////////////////////
  50. //! Calculate the vertical offset for alignment
  51. float GetVerticalAlignmentOffset(IDraw2d::VAlign vAlignment, float availableSpace, float occupiedSpace);
  52. ////////////////////////////////////////////////////////////////////////////////////////////////////
  53. //! Check whether a parent layout element is controlling a child element
  54. bool IsControllingChild(AZ::EntityId parentId, AZ::EntityId childId);
  55. ////////////////////////////////////////////////////////////////////////////////////////////////////
  56. //! Calculate the rectangle described by the padding inside the element's borders
  57. void GetSizeInsidePadding(AZ::EntityId elementId, const UiLayoutInterface::Padding& padding, AZ::Vector2& size);
  58. ////////////////////////////////////////////////////////////////////////////////////////////////////
  59. //! Get the width to apply to an element based on the layout cell properties on that element
  60. float GetLayoutElementTargetWidth(AZ::EntityId elementId);
  61. ////////////////////////////////////////////////////////////////////////////////////////////////////
  62. //! Get the height to apply to an element based on the layout cell properties on that element
  63. float GetLayoutElementTargetHeight(AZ::EntityId elementId);
  64. ////////////////////////////////////////////////////////////////////////////////////////////////////
  65. //! Called on a property change that has caused an element's layout to be invalid.
  66. //! Marks the element as needing to recompute its layout
  67. void InvalidateLayout(AZ::EntityId elementId);
  68. ////////////////////////////////////////////////////////////////////////////////////////////////////
  69. //! Called when a property that is used to calculate default layout cell values has changed.
  70. //! Marks the element's parent as needing to recompute its layout
  71. void InvalidateParentLayout(AZ::EntityId elementId);
  72. ////////////////////////////////////////////////////////////////////////////////////////////////////
  73. //! Check whether the element's width is being controlled by a layout fitter
  74. bool IsControlledByHorizontalFit(AZ::EntityId elementId);
  75. ////////////////////////////////////////////////////////////////////////////////////////////////////
  76. //! Check whether the element's height is being controlled by a layout fitter
  77. bool IsControlledByVerticalFit(AZ::EntityId elementId);
  78. ////////////////////////////////////////////////////////////////////////////////////////////////////
  79. //! Called on a property change in the UI editor that has caused an element's layout to be invalid.
  80. //! Sets up a refresh of the UI editor's transform properties in the properties pane if
  81. //! the transform is controlled by a layout fitter
  82. void CheckFitterAndRefreshEditorTransformProperties(AZ::EntityId elementId);
  83. } // namespace UiLayoutHelpers