UiLayoutFitterComponent.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/UiLayoutFitterBus.h>
  10. #include <LyShine/Bus/UiLayoutControllerBus.h>
  11. #include <LyShine/UiComponentTypes.h>
  12. #include <AzCore/Component/Component.h>
  13. #include <UiLayoutHelpers.h>
  14. namespace AZ
  15. {
  16. class ReflectContext;
  17. }
  18. ////////////////////////////////////////////////////////////////////////////////////////////////////
  19. //! This component resizes its element to fit its content. It uses cell sizing information given to
  20. //! it by other Layout components, Text component, or Image component (fixed type).
  21. class UiLayoutFitterComponent
  22. : public AZ::Component
  23. , public UiLayoutControllerBus::Handler
  24. , public UiLayoutFitterBus::Handler
  25. {
  26. public: // member functions
  27. AZ_COMPONENT(UiLayoutFitterComponent, LyShine::UiLayoutFitterComponentUuid, AZ::Component);
  28. UiLayoutFitterComponent();
  29. ~UiLayoutFitterComponent() override;
  30. // UiLayoutControllerInterface
  31. void ApplyLayoutWidth() override;
  32. void ApplyLayoutHeight() override;
  33. // ~UiLayoutControllerInterface
  34. // UiFitToComponentInterface
  35. bool GetHorizontalFit() override;
  36. void SetHorizontalFit(bool horizontalFit) override;
  37. bool GetVerticalFit() override;
  38. void SetVerticalFit(bool verticalFit) override;
  39. FitType GetFitType() override;
  40. // ~UiFitToComponentInterface
  41. public: // static member functions
  42. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  43. {
  44. provided.push_back(AZ_CRC("UiFitToContentService"));
  45. }
  46. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  47. {
  48. incompatible.push_back(AZ_CRC("UiFitToContentService"));
  49. }
  50. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  51. {
  52. required.push_back(AZ_CRC("UiElementService", 0x3dca7ad4));
  53. required.push_back(AZ_CRC("UiTransformService", 0x3a838e34));
  54. }
  55. static void Reflect(AZ::ReflectContext* context);
  56. protected: // member functions
  57. // AZ::Component
  58. void Activate() override;
  59. void Deactivate() override;
  60. // ~AZ::Component
  61. // UiLayoutControllerInterface
  62. unsigned int GetPriority() const override;
  63. // ~UiLayoutControllerInterface
  64. AZ_DISABLE_COPY_MOVE(UiLayoutFitterComponent);
  65. //! Called on a property change that has caused this element's layout to be invalid
  66. void CheckFitterAndInvalidateLayout();
  67. //! Called on a property change that has caused properties on Transform2d to get modified
  68. void RefreshEditorTransformProperties();
  69. protected: // data
  70. bool m_horizontalFit;
  71. bool m_verticalFit;
  72. };