UiDynamicLayoutComponent.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/UiDynamicLayoutBus.h>
  10. #include <LyShine/Bus/UiInitializationBus.h>
  11. #include <LyShine/Bus/UiTransformBus.h>
  12. #include <LyShine/Bus/UiElementBus.h>
  13. #include <LyShine/UiComponentTypes.h>
  14. #include <AzCore/Component/Component.h>
  15. ////////////////////////////////////////////////////////////////////////////////////////////////////
  16. //! This component supports dynamic creation of child elements
  17. class UiDynamicLayoutComponent
  18. : public AZ::Component
  19. , public UiDynamicLayoutBus::Handler
  20. , public UiInitializationBus::Handler
  21. , public UiTransformChangeNotificationBus::Handler
  22. , public UiElementNotificationBus::Handler
  23. {
  24. public: // member functions
  25. AZ_COMPONENT(UiDynamicLayoutComponent, LyShine::UiDynamicLayoutComponentUuid, AZ::Component);
  26. UiDynamicLayoutComponent();
  27. ~UiDynamicLayoutComponent() override;
  28. // UiDynamicLayoutInterface
  29. virtual void SetNumChildElements(int numChildren) override;
  30. // ~UiDynamicLayoutInterface
  31. // UiInitializationInterface
  32. void InGamePostActivate() override;
  33. // ~UiInitializationInterface
  34. // UiTransformChangeNotificationBus
  35. void OnCanvasSpaceRectChanged(AZ::EntityId entityId, const UiTransformInterface::Rect& oldRect, const UiTransformInterface::Rect& newRect) override;
  36. // ~UiTransformChangeNotificationBus
  37. // UiElementNotifications
  38. void OnUiElementBeingDestroyed() override;
  39. // ~UiElementNotifications
  40. public: // static member functions
  41. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  42. {
  43. provided.push_back(AZ_CRC("UiDynamicContentService", 0xc5af0b83));
  44. }
  45. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  46. {
  47. incompatible.push_back(AZ_CRC("UiDynamicContentService", 0xc5af0b83));
  48. }
  49. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  50. {
  51. required.push_back(AZ_CRC("UiElementService", 0x3dca7ad4));
  52. required.push_back(AZ_CRC("UiTransformService", 0x3a838e34));
  53. required.push_back(AZ_CRC("UiLayoutService", 0xac613bbc));
  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. AZ_DISABLE_COPY_MOVE(UiDynamicLayoutComponent);
  62. void SetPrototypeElementActive(bool active);
  63. //! Resize the parent to fit all cloned child elements
  64. void ResizeToFitChildElements();
  65. protected: // data
  66. //! The entity Id of the prototype element
  67. AZ::EntityId m_prototypeElement;
  68. //! Number of child elements to clone on initialization
  69. int m_numChildElementsToClone;
  70. //! Stores the size of the prototype element before it is removed from the child list. Used
  71. //! to calculate the element size
  72. AZ::Vector2 m_prototypeElementSize;
  73. };