From: agnelo vaz Date: Wed, 17 Oct 2018 14:58:10 +0000 (+0100) Subject: Layout removal support X-Git-Tag: dali_1.3.47~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=fd7b0b94254cb9eef6c411007f9fb10cca71f40c Layout removal support Change-Id: I1d840c366696d003b6aa32550d55e1a18a4daf00 --- diff --git a/automated-tests/src/dali-toolkit/CMakeLists.txt b/automated-tests/src/dali-toolkit/CMakeLists.txt index 6f1b55f..fe9102e 100755 --- a/automated-tests/src/dali-toolkit/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit/CMakeLists.txt @@ -28,8 +28,9 @@ SET(TC_SOURCES utc-Dali-KeyInputFocusManager.cpp utc-Dali-Layouting.cpp utc-Dali-LayoutingAnimation.cpp - utc-Dali-LayoutingResizePolicy.cpp utc-Dali-LayoutingNesting.cpp + utc-Dali-LayoutingResizePolicy.cpp + utc-Dali-LayoutingSettingAndRemoval.cpp utc-Dali-PageTurnView.cpp utc-Dali-Scene3dView.cpp utc-Dali-Script.cpp diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp index 46ba80b..23cc93a 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp @@ -2692,60 +2692,6 @@ int UtcDaliLayouting_HboxLayout_TargetSize(void) END_TEST; } -int UtcDaliLayouting_RemoveLayout01(void) -{ - ToolkitTestApplication application; - tet_infoline(" UtcDaliLayouting_RemoveLayout"); - - Stage stage = Stage::GetCurrent(); - - auto rootControl = Control::New(); - auto absoluteLayout = AbsoluteLayout::New(); - DevelControl::SetLayout( rootControl, absoluteLayout ); - rootControl.SetName( "AbsoluteLayout" ); - stage.Add( rootControl ); - - auto hbox = Control::New(); - auto hboxLayout = LinearLayout::New(); - hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL ); - DevelControl::SetLayout( hbox, hboxLayout ); - hbox.SetName( "HBox" ); - - std::vector< Control > controls; - controls.push_back( CreateLeafControl( 40, 40 ) ); - controls.push_back( CreateLeafControl( 60, 40 ) ); - - for( auto&& iter : controls ) - { - hbox.Add( iter ); - } - hbox.SetParentOrigin( ParentOrigin::CENTER ); - hbox.SetAnchorPoint( AnchorPoint::CENTER ); - rootControl.Add( hbox ); - - tet_infoline("Layout as normal"); - application.SendNotification(); - application.Render(); - - tet_infoline("Set an empty layout on hbox container"); - LinearLayout emptyLayout; - DevelControl::SetLayout( hbox, emptyLayout ); - - tet_infoline("Run another layout"); - application.SendNotification(); - application.Render(); - - tet_infoline("Check leaf controls haven't moved"); - - DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION ); - DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::POSITION ), Vector3( 40.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION ); - - DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); - DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::SIZE ), Vector3( 60.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); - - END_TEST; -} - int UtcDaliLayouting_LayoutChildren01(void) { ToolkitTestApplication application; @@ -2765,41 +2711,6 @@ int UtcDaliLayouting_LayoutChildren01(void) DALI_TEST_EQUALS( absoluteLayout.GetChildCount(), 1, TEST_LOCATION ); - tet_infoline("Test removal by setting empty layout to child container" ); - DevelControl::SetLayout( hbox, LayoutItem{} ); - - DALI_TEST_EQUALS( absoluteLayout.GetChildCount(), 0, TEST_LOCATION ); - - auto& hboxImpl = GetImplementation( hboxLayout ); - Handle empty; - DALI_TEST_EQUALS( hboxLayout.GetOwner(), empty, TEST_LOCATION ); - DALI_TEST_EQUALS( (void*)hboxImpl.GetParent(), (void*)nullptr, TEST_LOCATION ); - - // For coverage - hboxImpl.SetLayoutRequested(); - - END_TEST; -} - -int UtcDaliLayouting_LayoutChildren02(void) -{ - ToolkitTestApplication application; - tet_infoline(" UtcDaliLayouting_LayoutChildren02"); - - Stage stage = Stage::GetCurrent(); - - auto rootControl = Control::New(); - auto absoluteLayout = AbsoluteLayout::New(); - DevelControl::SetLayout( rootControl, absoluteLayout ); - stage.Add( rootControl ); - - auto hbox = Control::New(); - auto hboxLayout = LinearLayout::New(); - DevelControl::SetLayout( hbox, hboxLayout ); - rootControl.Add( hbox ); - - DALI_TEST_EQUALS( absoluteLayout.GetChildCount(), 1, TEST_LOCATION ); - tet_infoline("Test removal by removing child actor from parent container" ); hbox.Unparent(); @@ -2815,7 +2726,7 @@ int UtcDaliLayouting_LayoutChildren02(void) END_TEST; } -int UtcDaliLayouting_LayoutChildren03(void) +int UtcDaliLayouting_LayoutChildren02(void) { ToolkitTestApplication application; tet_infoline(" UtcDaliLayouting_LayoutChildren02"); @@ -2852,7 +2763,7 @@ int UtcDaliLayouting_LayoutChildren03(void) } -int UtcDaliLayouting_LayoutChildren04(void) +int UtcDaliLayouting_LayoutChildren03(void) { ToolkitTestApplication application; tet_infoline(" UtcDaliLayouting_LayoutChildren03"); @@ -2985,34 +2896,51 @@ int UtcDaliLayouting_SetLayoutOrder02(void) tet_infoline("SetLayout"); auto vboxLayout = LinearLayout::New(); - DevelControl::SetLayout( controls[0], vboxLayout ); + DevelControl::SetLayout( controls[0], vboxLayout ); // 1 2 0(vbox) TestLayoutItemOrder( controls, hboxLayout ); tet_infoline("Raise"); - controls[0].Raise(); // 1 2 0 + controls[0].Raise(); // 1 2 0(vbox) TestLayoutItemOrder( controls, hboxLayout ); tet_infoline("Lower"); - controls[2].Lower(); // 2 1 0 + controls[2].Lower(); // 2 1 0(vbox) TestLayoutItemOrder( controls, hboxLayout ); tet_infoline("SetLayout again"); auto vboxLayout1 = LinearLayout::New(); - DevelControl::SetLayout( controls[2], vboxLayout1 ); + DevelControl::SetLayout( controls[2], vboxLayout1 ); // 2 1(vbox1) 0(vbox) + + TestLayoutItemOrder( controls, hboxLayout ); + + tet_infoline("SetLayout with empty handle"); + + DevelControl::SetLayout( controls[0], LayoutItem{} ); // 2 1(vbox1) 0 TestLayoutItemOrder( controls, hboxLayout ); - DevelControl::SetLayout( controls[2], vboxLayout ); + tet_infoline("SetLayout to another control"); + + DevelControl::SetLayout( controls[2], vboxLayout1 ); // 2(vbox1) 1 0 + + TestLayoutItemOrder( controls, hboxLayout ); + + tet_infoline("SetLayout to change layout"); + + DevelControl::SetLayout( controls[2], vboxLayout1 ); // 2(vbox) 1 0 + + TestLayoutItemOrder( controls, hboxLayout ); END_TEST; } + int UtcDaliLayouting_LayoutGroup01(void) { ToolkitTestApplication application; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-LayoutingSettingAndRemoval.cpp b/automated-tests/src/dali-toolkit/utc-Dali-LayoutingSettingAndRemoval.cpp new file mode 100644 index 0000000..b55afd6 --- /dev/null +++ b/automated-tests/src/dali-toolkit/utc-Dali-LayoutingSettingAndRemoval.cpp @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + +#include + +using namespace Dali; +using namespace Toolkit; + +namespace +{ + +// Turns the given control into a Root layout control and adds it to the stage. +void SetupRootLayoutControl( Control& rootControl ) +{ + rootControl = Control::New(); + auto absoluteLayout = AbsoluteLayout::New(); + DevelControl::SetLayout( rootControl, absoluteLayout ); + rootControl.SetName( "RootAbsoluteLayout" ); + Stage stage = Stage::GetCurrent(); + stage.Add( rootControl ); +} + +} // unnamed namespace + +void utc_dali_toolkit_layouting_setting_and_removal_startup(void) +{ + test_return_value = TET_UNDEF; +} + +void utc_dali_toolkit_layouting_setting_and_removal_cleanup(void) +{ + test_return_value = TET_PASS; +} + +int UtcDaliLayoutingSettingAndRemoval_RemoveLayout(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliLayoutingSettingAndRemoval_RemoveLayout - Remove a layout from a control"); + + Stage stage = Stage::GetCurrent(); + + auto rootControl = Control::New(); + SetupRootLayoutControl( rootControl ); + + auto hbox = Control::New(); + auto hboxLayout = LinearLayout::New(); + DevelControl::SetLayout( hbox, hboxLayout ); + hbox.SetName( "HBox"); + rootControl.Add( hbox ); + + // Add child controls + std::vector< Control > controls; + controls.push_back( CreateLeafControl( 100, 100 ) ); // 0 + controls.push_back( CreateLeafControl( 100, 100 ) ); // 1 + controls.push_back( CreateLeafControl( 100, 100 ) ); // 2 + + for( auto&& iter : controls ) + { + hbox.Add( iter ); + } + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + tet_infoline("Get number of child in the rootControl layout"); + DALI_TEST_EQUALS( ( LayoutGroup::DownCast( DevelControl::GetLayout( rootControl ) ) ).GetChildCount(), 1 , TEST_LOCATION ); + + tet_infoline("SetLayout with empty Layout handle"); + + DevelControl::SetLayout( hbox, LayoutItem{} ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + tet_infoline("Get number of children in the rootControl layout"); + DALI_TEST_EQUALS( ( LayoutGroup::DownCast( DevelControl::GetLayout( rootControl ) ) ).GetChildCount(), 1 , TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliLayoutingSettingAndRemoval_RemoveLayoutFromChild(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliLayoutingSettingAndRemoval_RemoveLayoutFromChild - Remove a layout from a child of another layout"); + + /* + + Hbox + | | | + control0 control1 control2 + (vbox) (leaf) (leaf) + + Test removes layout from control0 but does not remove the control. + + */ + + Stage stage = Stage::GetCurrent(); + + auto rootControl = Control::New(); + SetupRootLayoutControl( rootControl ); + + auto hbox = Control::New(); + auto hboxLayout = LinearLayout::New(); + DevelControl::SetLayout( hbox, hboxLayout ); + hbox.SetName( "HBox"); + rootControl.Add( hbox ); + + // Add child controls + std::vector< Control > controls; + controls.push_back( CreateLeafControl( 100, 100 ) ); // 0 + controls.push_back( CreateLeafControl( 100, 100 ) ); // 1 + controls.push_back( CreateLeafControl( 100, 100 ) ); // 2 + + for( auto&& iter : controls ) + { + hbox.Add( iter ); + } + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + tet_infoline("Set LinearLayout to child control 0"); + + auto vboxLayout = LinearLayout::New(); + DevelControl::SetLayout( controls[0], vboxLayout ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + tet_infoline("Get number of children in the hbox layout"); + DALI_TEST_EQUALS( ( LayoutGroup::DownCast( DevelControl::GetLayout( hbox ) ) ).GetChildCount(), 3 , TEST_LOCATION ); + + tet_infoline("SetLayout with empty Layout handle"); + + DevelControl::SetLayout( controls[0], LayoutItem{} ); + + // If vbox control has no children then should get a LayoutItem. + // but if still has children then should be a LayoutGroup/BinContainer. + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + tet_infoline("Get number of child in the hbox layout"); + DALI_TEST_EQUALS( ( LayoutGroup::DownCast( DevelControl::GetLayout( hbox ) ) ).GetChildCount(), 3 , TEST_LOCATION ); + // Test should fail as the setting of an empty layout reduces the child count by 1 + + END_TEST; +} + +int UtcDaliLayoutingSettingAndRemoval_RemoveLayoutFromHbox(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliLayoutingSettingAndRemoval_RemoveLayoutFromHbox"); + + Stage stage = Stage::GetCurrent(); + + auto rootControl = Control::New(); + auto absoluteLayout = AbsoluteLayout::New(); + DevelControl::SetLayout( rootControl, absoluteLayout ); + rootControl.SetName( "AbsoluteLayout" ); + stage.Add( rootControl ); + + auto hbox = Control::New(); + auto hboxLayout = LinearLayout::New(); + hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL ); + DevelControl::SetLayout( hbox, hboxLayout ); + hbox.SetName( "Container" ); + + std::vector< Control > controls; + controls.push_back( CreateLeafControl( 40, 40 ) ); + controls.push_back( CreateLeafControl( 60, 40 ) ); + + for( auto&& iter : controls ) + { + hbox.Add( iter ); + } + hbox.SetParentOrigin( ParentOrigin::CENTER ); + hbox.SetAnchorPoint( AnchorPoint::CENTER ); + rootControl.Add( hbox ); + + tet_infoline("Layout as normal"); + application.SendNotification(); + application.Render(); + + tet_infoline("Set an empty layout on hbox container"); + LinearLayout emptyLayout; + DevelControl::SetLayout( hbox, emptyLayout ); + + tet_infoline("Run another layout"); + application.SendNotification(); + application.Render(); + + tet_infoline("Check leaf controls size and position"); + + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + tet_infoline("Child keeps position from last layout"); + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::POSITION ), Vector3( 40.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::SIZE ), Vector3( 60.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} \ No newline at end of file diff --git a/dali-toolkit/devel-api/controls/control-devel.h b/dali-toolkit/devel-api/controls/control-devel.h index e2fcc86..52a0d4a 100755 --- a/dali-toolkit/devel-api/controls/control-devel.h +++ b/dali-toolkit/devel-api/controls/control-devel.h @@ -289,6 +289,8 @@ DALI_TOOLKIT_API Toolkit::LayoutItem GetLayout( Control control ); * * @param[in] control The internal Control to set the layout on * @param[in] layout Pointer to the layout + * @note Providing an empty layout will remove the current layout and + * replace it with a BinLayout. */ DALI_TOOLKIT_API void SetLayout( Internal::Control& control, Toolkit::LayoutItem layout ); @@ -297,6 +299,8 @@ DALI_TOOLKIT_API void SetLayout( Internal::Control& control, Toolkit::LayoutItem * * @param[in] control The Control to set the layout on * @param[in] layout Pointer to the layout + * @note Providing an empty layout will remove the current layout and + * replace it with a BinLayout. */ DALI_TOOLKIT_API void SetLayout( Control control, Toolkit::LayoutItem layout ); diff --git a/dali-toolkit/internal/controls/control/control-data-impl.cpp b/dali-toolkit/internal/controls/control/control-data-impl.cpp index fcfb147..c5af35e 100755 --- a/dali-toolkit/internal/controls/control/control-data-impl.cpp +++ b/dali-toolkit/internal/controls/control/control-data-impl.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -1457,12 +1458,11 @@ void Control::Impl::SetLayout( Toolkit::Internal::LayoutItem& layout ) void Control::Impl::RemoveLayout() { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::Impl::RemoveLayout\n"); - if( mLayout ) - { - mLayout->Unparent(); - mLayout.Reset(); - } + DALI_LOG_INFO( gLogFilterLayout, Debug::Verbose, "Control::Impl::RemoveLayout\n"); + + Toolkit::BinLayout binLayout = Toolkit::BinLayout::New(); + + mControlImpl.mImpl->SetLayout( GetImplementation( binLayout ) ) ; } void Control::Impl::SetLayoutingRequired( bool layoutingRequired )