From 03014a1c85094939862c1b59aa6ca0b25c967383 Mon Sep 17 00:00:00 2001 From: Eunki Hong Date: Wed, 24 Nov 2021 07:15:04 -0800 Subject: [PATCH 1/1] [Tizen] Fixed actor relayout dimension dependencies Height dimension dependency on child should now work properly. Retained old behaviour from before refactor - when no size negotiation, RelayoutDependentOnChildrenBase returned true This reverts commit 8d3b11969761eebc5dba8c07d7880c042a9212cc. Change-Id: I1cea17e24e4b9ff834b91578e5254bd281832639 Signed-off-by: Eunki Hong --- .../utc-Dali-Internal-ActorRelayout.cpp | 7 ++- automated-tests/src/dali/utc-Dali-CustomActor.cpp | 48 ++++++++++++++++-- dali/internal/event/actors/actor-relayouter.cpp | 36 ------------- dali/internal/event/actors/actor-relayouter.h | 6 --- dali/internal/event/actors/actor-sizer.cpp | 59 ++++++++++++++++------ 5 files changed, 93 insertions(+), 63 deletions(-) diff --git a/automated-tests/src/dali-internal/utc-Dali-Internal-ActorRelayout.cpp b/automated-tests/src/dali-internal/utc-Dali-Internal-ActorRelayout.cpp index 2e77750..1df40f0 100644 --- a/automated-tests/src/dali-internal/utc-Dali-Internal-ActorRelayout.cpp +++ b/automated-tests/src/dali-internal/utc-Dali-Internal-ActorRelayout.cpp @@ -49,7 +49,12 @@ int UtcDaliActorSizer_CalculateSize(void) auto& actorImpl = GetImplementation(actor); DALI_TEST_EQUALS(testActorImpl.IsRelayoutEnabled(), false, TEST_LOCATION); - DALI_TEST_CHECK(true); + + // With no relayouting, there are no default dependencies + DALI_TEST_EQUALS(actorImpl.RelayoutDependentOnParent(Dimension::ALL_DIMENSIONS), false, TEST_LOCATION); + + // But, current broken behaviour is to depend on children. Retain this behaviour for now. + DALI_TEST_EQUALS(testActorImpl.RelayoutDependentOnChildren(Dimension::ALL_DIMENSIONS), true, TEST_LOCATION); actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); actor[Dali::Actor::Property::SIZE] = Vector2(150.0f, 100.0f); // Should automatically set preferred size diff --git a/automated-tests/src/dali/utc-Dali-CustomActor.cpp b/automated-tests/src/dali/utc-Dali-CustomActor.cpp index a51242d..e33a738 100644 --- a/automated-tests/src/dali/utc-Dali-CustomActor.cpp +++ b/automated-tests/src/dali/utc-Dali-CustomActor.cpp @@ -1183,18 +1183,56 @@ int UtcDaliCustomActorImplCalculateChildSizeBase(void) int UtcDaliCustomActorImplRelayoutDependentOnChildrenBase(void) { TestApplication application; - Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize(); - custom.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS); + Test::TestCustomActor customNego = Test::TestCustomActor::NewNegoSize(); + Test::TestCustomActor customNotNego = Test::TestCustomActor::New(); + + // A custom actor with default flags has relayouting enabled on initialization, + // and the default resize policy is USE_NATURAL_SIZE. + bool v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::ALL_DIMENSIONS); + DALI_TEST_CHECK(v == true); - bool v = custom.TestRelayoutDependentOnChildrenBase(Dali::Dimension::ALL_DIMENSIONS); + // A custom actor with size negotiation explicitly switched off has no relayouting, + // and will not have any relayout dependencies. However, default resize policy when + // there is no relayouting is to return USE_NATURAL_SIZE, so this will actually return true, + // and is consistent. + v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::ALL_DIMENSIONS); DALI_TEST_CHECK(v == true); + customNego.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS); + customNotNego.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS); + + v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::ALL_DIMENSIONS); + DALI_TEST_CHECK(v == true); + v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::ALL_DIMENSIONS); + DALI_TEST_CHECK(v == true); + + application.SendNotification(); + application.Render(); + + customNego.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS); + customNotNego.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS); + v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::WIDTH); + DALI_TEST_CHECK(v == false); + v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::HEIGHT); + DALI_TEST_CHECK(v == false); + v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::WIDTH); + DALI_TEST_CHECK(v == false); + v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::HEIGHT); + DALI_TEST_CHECK(v == false); + application.SendNotification(); application.Render(); - custom.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS); - v = custom.TestRelayoutDependentOnChildrenBase(Dali::Dimension::WIDTH); + customNego.SetResizePolicy(Dali::ResizePolicy::USE_NATURAL_SIZE, Dali::Dimension::WIDTH); + customNotNego.SetResizePolicy(Dali::ResizePolicy::USE_NATURAL_SIZE, Dali::Dimension::HEIGHT); + v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::WIDTH); + DALI_TEST_CHECK(v == true); + v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::HEIGHT); DALI_TEST_CHECK(v == false); + v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::WIDTH); + DALI_TEST_CHECK(v == false); + v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::HEIGHT); + DALI_TEST_CHECK(v == true); END_TEST; } diff --git a/dali/internal/event/actors/actor-relayouter.cpp b/dali/internal/event/actors/actor-relayouter.cpp index cfebf86..696232d 100644 --- a/dali/internal/event/actors/actor-relayouter.cpp +++ b/dali/internal/event/actors/actor-relayouter.cpp @@ -287,42 +287,6 @@ void ActorSizer::Relayouter::SetResizePolicy(ResizePolicy::Type policy, Dimensio } } -bool ActorSizer::Relayouter::GetRelayoutDependentOnParent(Dimension::Type dimension) -{ - // Check if actor is dependent on parent - for(uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i) - { - if((dimension & (1 << i))) - { - const ResizePolicy::Type resizePolicy = GetResizePolicy(static_cast(1 << i)); - if(resizePolicy == ResizePolicy::FILL_TO_PARENT || resizePolicy == ResizePolicy::SIZE_RELATIVE_TO_PARENT || resizePolicy == ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT) - { - return true; - } - } - } - return false; -} - -bool ActorSizer::Relayouter::GetRelayoutDependentOnChildren(Dimension::Type dimension) -{ - // Check if actor is dependent on children - for(uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i) - { - if((dimension & (1 << i))) - { - const ResizePolicy::Type resizePolicy = GetResizePolicy(static_cast(1 << i)); - if(resizePolicy == ResizePolicy::FIT_TO_CHILDREN || resizePolicy == ResizePolicy::USE_NATURAL_SIZE) - { - return true; - } - break; - } - } - - return false; -} - bool ActorSizer::Relayouter::GetRelayoutDependentOnDimension(Dimension::Type dimension, Dimension::Type dependency) { // Check each possible dimension and see if it is dependent on the input one diff --git a/dali/internal/event/actors/actor-relayouter.h b/dali/internal/event/actors/actor-relayouter.h index f1ade33..73b1f55 100644 --- a/dali/internal/event/actors/actor-relayouter.h +++ b/dali/internal/event/actors/actor-relayouter.h @@ -72,12 +72,6 @@ struct ActorSizer::Relayouter /// @copydoc Actor::SetResizePolicy void SetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension, Vector3& targetSize); - /// @copydoc Actor::GetRelayoutDependentOnParent - bool GetRelayoutDependentOnParent(Dimension::Type dimension); - - /// @copydoc Actor::GetRelayoutDependentOnChildren - bool GetRelayoutDependentOnChildren(Dimension::Type dimension); - /// @copydoc Actor::GetRelayoutDependentOnDimension bool GetRelayoutDependentOnDimension(Dimension::Type dimension, Dimension::Type dependency); diff --git a/dali/internal/event/actors/actor-sizer.cpp b/dali/internal/event/actors/actor-sizer.cpp index 3953d4c..95c6de8 100644 --- a/dali/internal/event/actors/actor-sizer.cpp +++ b/dali/internal/event/actors/actor-sizer.cpp @@ -63,19 +63,6 @@ constexpr float GetDimensionValue(const Dali::Vector2& values, const Dali::Dimen return 0.0f; } -/** - * @brief Default relayout dependent on parent when relayout is not setuped before. - */ -static constexpr bool DEFAULT_RELAYOUT_DEPENDENT_ON_PARENT = ((Dali::ResizePolicy::DEFAULT == Dali::ResizePolicy::FILL_TO_PARENT) || - (Dali::ResizePolicy::DEFAULT == Dali::ResizePolicy::SIZE_RELATIVE_TO_PARENT) || - (Dali::ResizePolicy::DEFAULT == Dali::ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT)); - -/** - * @brief Default relayout dependent on child when relayout is not setuped before. - */ -static constexpr bool DEFAULT_RELAYOUT_DEPENDENT_ON_CHILD = ((Dali::ResizePolicy::DEFAULT == Dali::ResizePolicy::FIT_TO_CHILDREN) || - (Dali::ResizePolicy::DEFAULT == Dali::ResizePolicy::USE_NATURAL_SIZE)); - } // namespace namespace Dali::Internal @@ -336,12 +323,54 @@ ActorSizer::Relayouter& ActorSizer::EnsureRelayouter() bool ActorSizer::RelayoutDependentOnParent(Dimension::Type dimension) { - return mRelayoutData ? mRelayoutData->GetRelayoutDependentOnParent(dimension) : DEFAULT_RELAYOUT_DEPENDENT_ON_PARENT; + // If there is no relayouting, GetResizePolicy returns Default, which is USE_NATURAL_SIZE. This + // will keep the existing behaviour, and return false. + + // Check if actor is dependent on parent + for(uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i) + { + if((dimension & (1 << i))) + { + const ResizePolicy::Type resizePolicy = GetResizePolicy(static_cast(1 << i)); + if(resizePolicy == ResizePolicy::FILL_TO_PARENT || resizePolicy == ResizePolicy::SIZE_RELATIVE_TO_PARENT || resizePolicy == ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT) + { + return true; + } + } + } + + return false; } bool ActorSizer::RelayoutDependentOnChildrenBase(Dimension::Type dimension) { - return mRelayoutData ? mRelayoutData->GetRelayoutDependentOnChildren(dimension) : DEFAULT_RELAYOUT_DEPENDENT_ON_CHILD; + // If there is no relayouting, GetResizePolicy returns Default, which is USE_NATURAL_SIZE. + // This means this will return true when there is no relayouting, but that seems + // counter-intuitive. Will keep current behaviour for now, as it is consistent. + + // Check if actor is dependent on children + for(uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i) + { + if((dimension & (1 << i))) + { + const ResizePolicy::Type resizePolicy = GetResizePolicy(static_cast(1 << i)); + switch(resizePolicy) + { + case ResizePolicy::FIT_TO_CHILDREN: + case ResizePolicy::USE_NATURAL_SIZE: // i.e. For things that calculate their size based on children + { + return true; + } + + default: + { + break; + } + } + } + } + + return false; } bool ActorSizer::RelayoutDependentOnDimension(Dimension::Type dimension, Dimension::Type dependentDimension) -- 2.7.4