123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #pragma once
- #include <LyShine/Bus/UiLayoutBus.h>
- #include <LyShine/Bus/UiLayoutControllerBus.h>
- #include <LyShine/Bus/UiLayoutColumnBus.h>
- #include <LyShine/Bus/UiLayoutCellDefaultBus.h>
- #include <LyShine/UiComponentTypes.h>
- #include <AzCore/Component/Component.h>
- #include <AzCore/Serialization/SerializeContext.h>
- #include <UiLayoutHelpers.h>
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- //! This component overrides the transforms of immediate children to organize them into a horizontal row
- class UiLayoutColumnComponent
- : public AZ::Component
- , public UiLayoutControllerBus::Handler
- , public UiLayoutBus::Handler
- , public UiLayoutColumnBus::Handler
- , public UiLayoutCellDefaultBus::Handler
- , public UiTransformChangeNotificationBus::Handler
- {
- public: // member functions
- AZ_COMPONENT(UiLayoutColumnComponent, LyShine::UiLayoutColumnComponentUuid, AZ::Component);
- UiLayoutColumnComponent();
- ~UiLayoutColumnComponent() override;
- // UiLayoutControllerInterface
- virtual void ApplyLayoutWidth() override;
- virtual void ApplyLayoutHeight() override;
- // ~UiLayoutControllerInterface
- // UiLayoutInterface
- virtual bool IsUsingLayoutCellsToCalculateLayout() override;
- virtual bool GetIgnoreDefaultLayoutCells() override;
- virtual void SetIgnoreDefaultLayoutCells(bool ignoreDefaultLayoutCells) override;
- virtual IDraw2d::HAlign GetHorizontalChildAlignment() override;
- virtual void SetHorizontalChildAlignment(IDraw2d::HAlign alignment) override;
- virtual IDraw2d::VAlign GetVerticalChildAlignment() override;
- virtual void SetVerticalChildAlignment(IDraw2d::VAlign alignment) override;
- virtual bool IsControllingChild(AZ::EntityId childId) override;
- virtual AZ::Vector2 GetSizeToFitChildElements(const AZ::Vector2& childElementSize, int numChildElements) override;
- // ~UiLayoutInterface
- // UiLayoutColumnInterface
- virtual UiLayoutInterface::Padding GetPadding() override;
- virtual void SetPadding(UiLayoutInterface::Padding padding) override;
- virtual float GetSpacing() override;
- virtual void SetSpacing(float spacing) override;
- virtual UiLayoutInterface::VerticalOrder GetOrder() override;
- virtual void SetOrder(UiLayoutInterface::VerticalOrder order) override;
- // ~UiLayoutColumnInterface
- // UiLayoutCellDefaultInterface
- float GetMinWidth() override;
- float GetMinHeight() override;
- float GetTargetWidth(float maxWidth) override;
- float GetTargetHeight(float maxHeight) override;
- float GetExtraWidthRatio() override;
- float GetExtraHeightRatio() override;
- // ~UiLayoutCellDefaultInterface
- // UiTransformChangeNotificationBus
- void OnCanvasSpaceRectChanged(AZ::EntityId entityId, const UiTransformInterface::Rect& oldRect, const UiTransformInterface::Rect& newRect) override;
- // ~UiTransformChangeNotificationBus
- public: // static member functions
- static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
- {
- provided.push_back(AZ_CRC("UiLayoutService", 0xac613bbc));
- }
- static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
- {
- incompatible.push_back(AZ_CRC("UiLayoutService", 0xac613bbc));
- }
- static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
- {
- required.push_back(AZ_CRC("UiElementService", 0x3dca7ad4));
- required.push_back(AZ_CRC("UiTransformService", 0x3a838e34));
- }
- static void Reflect(AZ::ReflectContext* context);
- protected: // member functions
- // AZ::Component
- void Activate() override;
- void Deactivate() override;
- // ~AZ::Component
- AZ_DISABLE_COPY_MOVE(UiLayoutColumnComponent);
- //! Called on a property change that has caused this element's layout to be invalid
- void InvalidateLayout();
- //! Called when a property that is used to calculate default layout cell values has changed
- void InvalidateParentLayout();
- //! Refresh the transform properties in the editor's properties pane
- void CheckLayoutFitterAndRefreshEditorTransformProperties() const;
- //! Helper functions to set the child elements' transform properties.
- //! Element widths are calculated first since layout cell height
- //! properties can depend on element widths
- void ApplyLayoutWidth(float availableWidth);
- void ApplyLayoutHeight(float availableHeight);
- protected: // data
- //! the padding (in pixels) inside the edges of this element
- UiLayoutInterface::Padding m_padding;
- //! the spacing (in pixels) between child elements
- float m_spacing;
- //! the order that the child elements are placed in
- UiLayoutInterface::VerticalOrder m_order;
- //! Child alignment
- IDraw2d::HAlign m_childHAlignment;
- IDraw2d::VAlign m_childVAlignment;
- //! Whether the layout is to ignore the children's default layout cell values
- bool m_ignoreDefaultLayoutCells;
- private: // static member functions
- static bool VersionConverter(AZ::SerializeContext& context,
- AZ::SerializeContext::DataElementNode& classElement);
- };
|