From: agnelo vaz Date: Wed, 17 Oct 2018 15:50:26 +0000 (+0100) Subject: BinLayout added X-Git-Tag: dali_1.3.47~6 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=71edd1925f5012bcbeb7a3c969372d36e5ca6227 BinLayout added This layout has children but does not explictly position them itself. If given a (legacy) container as a child it will check it for ResizePolicies and map them to a MeasureSpec so can be used by the Layout system. The BinLayout by default will take the size of the greatest child dimensions. (WRAP_CONTENT). Although can be set to MATCH_PARENT. PARENT_ORIGIN as always TOP_LEFT, may account for this in future if required. Change-Id: I2335ee465578d796e1025192ae0f8cdb95ecc60f --- diff --git a/automated-tests/src/dali-toolkit/CMakeLists.txt b/automated-tests/src/dali-toolkit/CMakeLists.txt index 7ad18b7..369f9b0 100755 --- a/automated-tests/src/dali-toolkit/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit/CMakeLists.txt @@ -10,6 +10,7 @@ SET(TC_SOURCES utc-Dali-AbsoluteLayout.cpp utc-Dali-Alignment.cpp utc-Dali-AnimatedImageVisual.cpp + utc-Dali-BinLayout.cpp utc-Dali-BloomView.cpp utc-Dali-BubbleEmitter.cpp utc-Dali-Builder.cpp diff --git a/automated-tests/src/dali-toolkit/utc-Dali-BinLayout.cpp b/automated-tests/src/dali-toolkit/utc-Dali-BinLayout.cpp new file mode 100644 index 0000000..3122c71 --- /dev/null +++ b/automated-tests/src/dali-toolkit/utc-Dali-BinLayout.cpp @@ -0,0 +1,495 @@ +/* + * 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 <../custom-layout.h> + +#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 ); +} + +void CreateDefaultBinContainer( Control& binContainer ) +{ + binContainer = Control::New(); + binContainer.SetName( "binContainer" ); + DevelControl::SetLayout( binContainer, BinLayout::New() ); + binContainer.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + binContainer.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); +} + +} // namespace + +void utc_dali_toolkit_bin_layouting_startup(void) +{ + test_return_value = TET_UNDEF; +} + +void utc_dali_toolkit_bin_layouting_cleanup(void) +{ + test_return_value = TET_PASS; +} + +int UtcDaliLayouting_BinLayoutDownCast(void) +{ + TestApplication application; + tet_infoline(" UtcDaliLayouting_BinLayoutDownCast - Testing Downcast"); + + BinLayout binLayout = BinLayout::New(); + + LayoutGroup layoutGroup( binLayout ); + + BinLayout binLayoutCandidate = BinLayout::DownCast( layoutGroup ); + DALI_TEST_CHECK( binLayoutCandidate ); + + END_TEST; +} + +int UtcDaliLayouting_BinLayoutAssignment(void) +{ + TestApplication application; + tet_infoline(" UtcDaliLayouting_BinLayoutAssignment - Testing operator="); + + BinLayout binLayout = BinLayout::New(); + BinLayout binLayout2; + + binLayout2 = binLayout; + + DALI_TEST_EQUALS( binLayout2, binLayout, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliLayouting_BinLayoutCopyConstructor(void) +{ + TestApplication application; + tet_infoline(" UtcDaliLayouting_BinLayoutCopyConstructor - Testing copy constructor"); + + BinLayout binLayout1 = BinLayout::New(); + BinLayout binLayout2( binLayout1 ); + + DALI_TEST_EQUALS( binLayout1, binLayout2, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliLayouting_BinLayout01(void) +{ + const auto NUMBER_OF_ITEMS = 4; + + ToolkitTestApplication application; + tet_infoline(" UtcDaliLayouting_BinLayout01 BinLayout WRAP_CONTENT"); + + Stage stage = Stage::GetCurrent(); + + auto rootControl = Control::New(); + auto absoluteLayout = AbsoluteLayout::New(); + DevelControl::SetLayout( rootControl, absoluteLayout ); + rootControl.SetName( "AbsoluteLayout" ); + stage.Add( rootControl ); + + auto binContainer = Control::New(); + auto binLayout = BinLayout::New(); + binContainer.SetName( "BinLayout"); + DevelControl::SetLayout( binContainer, binLayout ); + binContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT ); + binContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT ); + + std::vector< Control > controls; + for( auto i=0; i < NUMBER_OF_ITEMS; i++ ) + { + controls.push_back( CreateLeafControl( 100, 100 ) ); + } + + for( auto&& iter : controls ) + { + binContainer.Add( iter ); + } + + rootControl.Add( binContainer ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + // Items will be laid out at the same position + 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( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[3].GetProperty( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + // Item sizes will not be changed + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[3].GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + // BinLayout size to be that of greatest child dimensions + DALI_TEST_EQUALS( binContainer.GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliLayouting_BinLayout02(void) +{ + const auto NUMBER_OF_ITEMS = 4; + + ToolkitTestApplication application; + tet_infoline(" UtcDaliLayouting_BinLayout02 BinLayout MATCH_PARENT"); + + Stage stage = Stage::GetCurrent(); + + auto rootControl = Control::New(); + auto absoluteLayout = AbsoluteLayout::New(); + DevelControl::SetLayout( rootControl, absoluteLayout ); + rootControl.SetName( "AbsoluteLayout" ); + stage.Add( rootControl ); + + auto binContainer = Control::New(); + auto binLayout = BinLayout::New(); + binContainer.SetName( "BinLayout"); + DevelControl::SetLayout( binContainer, binLayout ); + binContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + binContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + + std::vector< Control > controls; + for( auto i=0; i < NUMBER_OF_ITEMS; i++ ) + { + controls.push_back( CreateLeafControl( 100, 100 ) ); + } + + for( auto&& iter : controls ) + { + binContainer.Add( iter ); + } + + rootControl.Add( binContainer ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + // Items will be laid out at the same position + 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( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[3].GetProperty( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + // Item sizes will not be changed + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[3].GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + // BinLayout size to be that of greatest child dimensions + DALI_TEST_EQUALS( binContainer.GetProperty( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliLayouting_BinLayout03(void) +{ + const auto NUMBER_OF_ITEMS = 4; + + ToolkitTestApplication application; + tet_infoline(" UtcDaliLayouting_BinLayout03 Explicit child Positioning when Bin layout MATCH_PARENT"); + + Stage stage = Stage::GetCurrent(); + + auto rootControl = Control::New(); + auto absoluteLayout = AbsoluteLayout::New(); + DevelControl::SetLayout( rootControl, absoluteLayout ); + rootControl.SetName( "AbsoluteLayout" ); + stage.Add( rootControl ); + + auto binContainer = Control::New(); + auto binLayout = BinLayout::New(); + binContainer.SetName( "BinLayout"); + DevelControl::SetLayout( binContainer, binLayout ); + binContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + binContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + + std::vector< Control > controls; + for( auto i=0; i < NUMBER_OF_ITEMS; i++ ) + { + controls.push_back( CreateLeafControl( 100, 100 ) ); + } + + for( auto&& iter : controls ) + { + binContainer.Add( iter ); + } + + tet_infoline("Position child explicitly from top left"); + controls[0].SetProperty(Actor::Property::POSITION_X, 50.0f ); + + tet_infoline("Position child explicitly from top left"); + controls[2].SetProperty(Actor::Property::POSITION_Y, 50.0f ); + + rootControl.Add( binContainer ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + // Items will be laid out at the same position + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::POSITION ), Vector3( 50.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::POSITION ), Vector3( 0.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[3].GetProperty( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + // Item sizes will not be changed + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[3].GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + // BinLayout size to be that of parent + DALI_TEST_EQUALS( binContainer.GetProperty( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliLayoutingBinLayoutResizePolicy_01(void) +{ + /* + Root + | + Control (LinearLayout Horizontal) + | + Control (BinLayout) + | + Control (ResizePolicy::FILL_TO_PARENT) + | + LeafControl + */ + + ToolkitTestApplication application; + tet_infoline("UtcDaliLayoutingBinLayoutResizePolicy_01 - Test ResizePolicy mapping with FILL_TO_PARENT on BinLayout child"); + + Stage stage = Stage::GetCurrent(); + + auto rootControl = Control::New(); + SetupRootLayoutControl( rootControl ); + + auto hbox = Control::New(); + auto hboxLayout = LinearLayout::New(); + hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL ); + DevelControl::SetLayout( hbox, hboxLayout ); + hbox.SetName( "hBox" ); + hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + + auto binContainer = Control::New(); + CreateDefaultBinContainer( binContainer ); + hbox.Add( binContainer ); + + auto control = Control::New(); + control.SetName( "fillToParentControl" ); + DevelControl::SetLayoutingRequired( control, true ); + control.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + binContainer.Add( control ); + + std::vector< Control > controls; + controls.push_back( CreateLeafControl( 40, 40 ) ); + + for( auto&& iter : controls ) + { + control.Add( iter ); + } + + rootControl.Add( hbox ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + tet_infoline("Testing child of BinLayout is size of parent"); + DALI_TEST_EQUALS( control.GetProperty( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + tet_infoline("Testing BinLayout's child control has not altered it's children's sizes "); + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + tet_infoline("Testing BinLayout is size of parent"); + DALI_TEST_EQUALS( binContainer.GetProperty( Actor::Property::SIZE ), hbox.GetProperty( Actor::Property::SIZE ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliLayoutingBinLayoutResizePolicy_02(void) +{ + /* + Root + | + Control (LinearLayout Horizontal) + | + Control (BinLayout) + | + Control (ResizePolicy::SIZE_RELATIVE_TO_PARENT) + | + LeafControl + */ + + ToolkitTestApplication application; + tet_infoline("UtcDaliLayoutingBinLayoutResizePolicy_02 - Set ResizePolicy SIZE_RELATIVE_TO_PARENT on BinLayout child"); + + const auto NUMBER_OF_ITEMS = 4; + + Stage stage = Stage::GetCurrent(); + + auto rootControl = Control::New(); + SetupRootLayoutControl( rootControl ); + + auto hbox = Control::New(); + auto hboxLayout = LinearLayout::New(); + hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL ); + DevelControl::SetLayout( hbox, hboxLayout ); + hbox.SetName( "hBox" ); + hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + + auto binContainer = Control::New(); + CreateDefaultBinContainer( binContainer ); + hbox.Add( binContainer ); + + auto control = Control::New(); + control.SetName( "fitToChildrenControl" ); + DevelControl::SetLayoutingRequired( control, true ); + control.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); + control.SetSizeModeFactor( Vector3( 0.50f, 1.0f, 1.0f ) ); + binContainer.Add( control ); + + std::vector< Control > controls; + for( auto i=0; i < NUMBER_OF_ITEMS; i++ ) + { + controls.push_back( CreateLeafControl( 40, 40 ) ); + } + + for( auto&& iter : controls ) + { + control.Add( iter ); + } + + rootControl.Add( hbox ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + tet_infoline("Testing child of BinLayout is the defined relative size of parent"); + DALI_TEST_EQUALS( control.GetProperty( Actor::Property::SIZE ), Vector3( 240.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + tet_infoline("Testing BinLayout's child control has not altered it's children's sizes "); + 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( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[3].GetProperty( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + tet_infoline("Testing BinLayout is size of parent"); + DALI_TEST_EQUALS( binContainer.GetProperty( Actor::Property::SIZE ), hbox.GetProperty( Actor::Property::SIZE ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliBinLayoutResizePolicy_03(void) +{ + /* + Root + | + Control (LinearLayout Horizontal) + | + Control (LayoutingRequired) + | + Control (ResizePolicy::SIZE_RELATIVE_TO_PARENT) + | + LeafControl + */ + + ToolkitTestApplication application; + tet_infoline("UtcDaliBinLayoutResizePolicy_03 - Set ResizePolicy SIZE_FIXED_OFFSET_FROM_PARENT on BinLayout child"); + + Stage stage = Stage::GetCurrent(); + + auto rootControl = Control::New(); + SetupRootLayoutControl( rootControl ); + + auto hbox = Control::New(); + auto hboxLayout = LinearLayout::New(); + hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL ); + DevelControl::SetLayout( hbox, hboxLayout ); + hbox.SetName( "hBox" ); + hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + + auto binContainer = Control::New(); + CreateDefaultBinContainer( binContainer ); + hbox.Add( binContainer ); + + hbox.Add( binContainer ); + + auto control = Control::New(); + control.SetName( "fitToChildrenControl" ); + DevelControl::SetLayoutingRequired( control, true ); + control.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS ); + control.SetSizeModeFactor( Vector3( -100.0f, 10.0f, 0.0f ) ); + binContainer.Add( control ); + + std::vector< Control > controls; + controls.push_back( CreateLeafControl( 40, 40 ) ); + + for( auto&& iter : controls ) + { + control.Add( iter ); + } + + rootControl.Add( hbox ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( DevelControl::IsLayoutingRequired( control ), true , 0.0001f, TEST_LOCATION ); + + DALI_TEST_EQUALS( control.GetProperty( Actor::Property::SIZE ), Vector3( 380.0f, 810.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 ); + + END_TEST; +} \ No newline at end of file diff --git a/dali-toolkit/devel-api/file.list b/dali-toolkit/devel-api/file.list index 3627396..c3f68aa 100755 --- a/dali-toolkit/devel-api/file.list +++ b/dali-toolkit/devel-api/file.list @@ -34,15 +34,16 @@ devel_api_src_files = \ $(devel_api_src_dir)/image-loader/atlas-upload-observer.cpp \ $(devel_api_src_dir)/image-loader/image-atlas.cpp \ $(devel_api_src_dir)/image-loader/texture-manager.cpp \ - $(devel_api_src_dir)/layouting/flex-layout.cpp \ $(devel_api_src_dir)/layouting/absolute-layout.cpp \ - $(devel_api_src_dir)/layouting/linear-layout.cpp \ + $(devel_api_src_dir)/layouting/bin-layout.cpp \ + $(devel_api_src_dir)/layouting/flex-layout.cpp \ $(devel_api_src_dir)/layouting/grid.cpp \ $(devel_api_src_dir)/layouting/layout-item.cpp \ $(devel_api_src_dir)/layouting/layout-item-impl.cpp \ $(devel_api_src_dir)/layouting/layout-controller.cpp \ $(devel_api_src_dir)/layouting/layout-group.cpp \ $(devel_api_src_dir)/layouting/layout-group-impl.cpp \ + $(devel_api_src_dir)/layouting/linear-layout.cpp \ $(devel_api_src_dir)/scripting/script.cpp \ $(devel_api_src_dir)/styling/style-manager-devel.cpp \ $(devel_api_src_dir)/transition-effects/cube-transition-cross-effect.cpp \ diff --git a/dali-toolkit/devel-api/layouting/bin-layout.cpp b/dali-toolkit/devel-api/layouting/bin-layout.cpp new file mode 100644 index 0000000..59d0b19 --- /dev/null +++ b/dali-toolkit/devel-api/layouting/bin-layout.cpp @@ -0,0 +1,63 @@ +/* + * 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. + */ + +//CLASS HEADER +#include + +//INTERNAL HEADERS +#include + +namespace Dali +{ +namespace Toolkit +{ + +BinLayout::BinLayout() +{ +} + +BinLayout BinLayout::New() +{ + Internal::BinLayoutPtr internal = Internal::BinLayout::New(); + return BinLayout( internal.Get() ); +} + +BinLayout BinLayout::DownCast( BaseHandle handle ) +{ + return BinLayout( dynamic_cast< Dali::Toolkit::Internal::BinLayout*>( handle.GetObjectPtr() ) ); +} + +BinLayout::BinLayout( const BinLayout& other ) +: LayoutGroup( other ) +{ +} + +BinLayout& BinLayout::operator=( const BinLayout& other ) +{ + if( &other != this ) + { + LayoutGroup::operator=( other ); + } + return *this; +} + +BinLayout::BinLayout( Dali::Toolkit::Internal::BinLayout* object ) +: LayoutGroup( object ) +{ +} + +} // namespace Toolkit +} // namespace Dali diff --git a/dali-toolkit/devel-api/layouting/bin-layout.h b/dali-toolkit/devel-api/layouting/bin-layout.h new file mode 100644 index 0000000..b61245c --- /dev/null +++ b/dali-toolkit/devel-api/layouting/bin-layout.h @@ -0,0 +1,104 @@ +#ifndef DALI_TOOLKIT_LAYOUTING_BIN_LAYOUT_H +#define DALI_TOOLKIT_LAYOUTING_BIN_LAYOUT_H + +/* + * 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 + +namespace Dali +{ +namespace Toolkit +{ + +namespace Internal DALI_INTERNAL +{ +class BinLayout; +} + +/** + * This class implements a bin layout, providing a simple layout to accept + * children and perform ResizePolicy mapping. + * + * Children will be positioned with their AnchorPoint and position if provided. + * If multiple children are added then they could overlap. + */ +class DALI_TOOLKIT_API BinLayout : public LayoutGroup +{ +public: + + /** + * @brief Creates an uninitialized BinLayout handle. + * + * Initialize it using BinLayout::New(). + * Calling member functions with an uninitialized handle is not allowed. + */ + BinLayout(); + + /** + * @brief Creates a BinLayout object. + */ + static BinLayout New(); + + /** + * @brief Downcasts a handle to a BinLayout handle. + * + * If handle points to a BinLayout, the downcast produces a valid handle. + * If not, the returned handle is left uninitialized. + + * @param[in] handle to an object + * @return Handle to a BinLayout or an uninitialized handle + */ + static BinLayout DownCast( BaseHandle handle ); + + /** + * @brief Copy constructor + */ + BinLayout( const BinLayout& other ); + + /** + * @brief Assignment operator + */ + BinLayout& operator=( const BinLayout& other ); + + /** + * @brief Default destructor. + * + * This is non-virtual, since derived Handle types must not contain data or virtual methods + */ + ~BinLayout()=default; + + +public: // Not intended for application developers + + /// @cond internal + /** + * @brief This constructor is used by BinLayout::New() methods. + * + * @param[in] actor A pointer to a newly allocated Dali resource + */ + explicit DALI_INTERNAL BinLayout( Internal::BinLayout* body ); + /// @endcond +}; + +} // namespace Toolkit +} // namespace Dali + +#endif // DALI_TOOLKIT_LAYOUTING_BIN_LAYOUT_H diff --git a/dali-toolkit/devel-api/layouting/layout-group-impl.cpp b/dali-toolkit/devel-api/layouting/layout-group-impl.cpp index cab70c3..35c682f 100644 --- a/dali-toolkit/devel-api/layouting/layout-group-impl.cpp +++ b/dali-toolkit/devel-api/layouting/layout-group-impl.cpp @@ -750,10 +750,9 @@ void LayoutGroup::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMea bool exactWidth ( false ); bool exactHeight ( false ); - // Default Layouting behaviour if not overridden + // Layouting behaviour // EXACT, width and height as provided. - // MATCH_PARENT, width and hewidthSpecSizeight that of parent - + // MATCH_PARENT, width and height that of parent // WRAP_CONTENT, take width of widest child and height size of longest child (within given limit) // UNSPECIFIED, take width of widest child and height size of longest child. diff --git a/dali-toolkit/internal/file.list b/dali-toolkit/internal/file.list index 11faf72..6df2e9f 100755 --- a/dali-toolkit/internal/file.list +++ b/dali-toolkit/internal/file.list @@ -11,15 +11,16 @@ toolkit_src_files = \ $(toolkit_src_dir)/builder/style.cpp \ $(toolkit_src_dir)/builder/tree-node-manipulator.cpp \ $(toolkit_src_dir)/builder/replacement.cpp \ - $(toolkit_src_dir)/layouting/flex-layout-impl.cpp \ $(toolkit_src_dir)/layouting/absolute-layout-impl.cpp \ - $(toolkit_src_dir)/layouting/linear-layout-impl.cpp \ + $(toolkit_src_dir)/layouting/bin-layout-impl.cpp \ + $(toolkit_src_dir)/layouting/flex-layout-impl.cpp \ $(toolkit_src_dir)/layouting/grid-locations.cpp \ $(toolkit_src_dir)/layouting/grid-impl.cpp \ $(toolkit_src_dir)/layouting/layout-item-data-impl.cpp \ $(toolkit_src_dir)/layouting/layout-group-data-impl.cpp \ $(toolkit_src_dir)/layouting/layout-controller-debug.cpp \ $(toolkit_src_dir)/layouting/layout-controller-impl.cpp \ + $(toolkit_src_dir)/layouting/linear-layout-impl.cpp \ $(toolkit_src_dir)/layouting/size-negotiation-mapper.cpp \ $(toolkit_src_dir)/visuals/animated-image/animated-image-visual.cpp \ $(toolkit_src_dir)/visuals/animated-image/image-cache.cpp \ diff --git a/dali-toolkit/internal/layouting/absolute-layout-impl.h b/dali-toolkit/internal/layouting/absolute-layout-impl.h index 99fb3c8..7b2d62b 100644 --- a/dali-toolkit/internal/layouting/absolute-layout-impl.h +++ b/dali-toolkit/internal/layouting/absolute-layout-impl.h @@ -63,8 +63,6 @@ private: AbsoluteLayout( const AbsoluteLayout& other ) = delete; AbsoluteLayout& operator=( const AbsoluteLayout& other ) = delete; - void ForceUniformHeight( int count, MeasureSpec widthMeasureSpec ); - }; } // namespace Internal diff --git a/dali-toolkit/internal/layouting/bin-layout-impl.cpp b/dali-toolkit/internal/layouting/bin-layout-impl.cpp new file mode 100644 index 0000000..567fc39 --- /dev/null +++ b/dali-toolkit/internal/layouting/bin-layout-impl.cpp @@ -0,0 +1,249 @@ +/* + * 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. + */ + +//CLASS HEADER +#include + +//INTERNAL HEADERS +#include +#include +#include +#include +#include +#include +#include + +namespace +{ +#if defined(DEBUG_ENABLED) +static Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_LAYOUT" ); +#endif +} + +namespace Dali +{ +namespace Toolkit +{ +namespace Internal +{ + +BinLayoutPtr BinLayout::New() +{ + BinLayoutPtr layout( new BinLayout() ); + return layout; +} + +BinLayout::BinLayout() +: LayoutGroup() +{ +} + +BinLayout::~BinLayout() +{ +} + +void BinLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec ) +{ +#if defined(DEBUG_ENABLED) + auto actor = Actor::DownCast(GetOwner()); + + std::ostringstream oss; + oss << "BinLayout::OnMeasure "; + if( actor ) + { + oss << "Actor Id:" << actor.GetId() << " Name:" << actor.GetName() << " "; + } + oss << "widthMeasureSpec:" << widthMeasureSpec << " heightMeasureSpec:" << heightMeasureSpec << std::endl; + DALI_LOG_INFO( gLogFilter, Debug::Concise, oss.str().c_str() ); +#endif + + auto childCount = GetChildCount(); + + DALI_LOG_STREAM( gLogFilter, Debug::Verbose, + "BinLayout::OnMeasure Actor Id:" << Actor::DownCast(GetOwner()).GetId() << + " Owner:" << Actor::DownCast(GetOwner()).GetName() << + " Child Count:" << childCount << + " MeasureSpecs( width:"< 0 ) + { + for( unsigned int i=0; iGetOwner()); + + // If child control has children check if a ResizePolicy is set on it. A LayoutItem could be a legacy container. + // A legacy container would need it's ResizePolicy to be applied as a MeasureSpec. + + // Check below will be true for legacy containers and for controls with the layout flag required set. + // Other layouts will have their own OnMeasure (a requirement) hence not execute BinLayout::OnMeasure. + // Controls which have set the layout required flag will not be legacy controls hence should not have a ResizePolicy set. + if( childControl.GetChildCount() > 0 ) + { + // First pass, Static mappings that are not dependant on parent + SizeNegotiationMapper::SetLayoutParametersUsingResizePolicy( childControl, childLayout, Dimension::WIDTH ); + SizeNegotiationMapper::SetLayoutParametersUsingResizePolicy( childControl, childLayout, Dimension::HEIGHT ); + } + + // Second pass, if any mappings were not possible due to parent size dependencies then calculate an exact desired size for child + if( true == childLayout->IsResizePolicyRequired() ) // No need to test child count as this flag would only be set if control had children. + { + // Get last stored width and height specifications for the child + LayoutLength desiredWidth = childControl.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); + LayoutLength desiredHeight = childControl.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); + + DALI_LOG_INFO( gLogFilter, Debug::General, "BinLayout::MeasureChild Initial desired size pre ResizePolicy(%f,%f)\n", desiredWidth.AsInteger(), desiredHeight.AsInteger() ); + + childLayout->SetResizePolicyRequired( false ); // clear flag incase in case of changes before next Measure + SizeNegotiationMapper::GetSizeofChildForParentDependentResizePolicy( childControl, widthMeasureSpec, heightMeasureSpec, desiredWidth, desiredHeight ); + + // Parent dependant ResizePolicies become exact sizes so are now set on the child before it's measured. + childControl.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, desiredWidth.AsInteger() ); + childControl.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, desiredHeight.AsInteger() ); + + DALI_LOG_INFO( gLogFilter, Debug::General, " BinLayout::OnMeasure ResizePolicy Required resulting size(%f,%f)\n", desiredWidth.AsInteger(), desiredHeight.AsInteger() ); + } + + // Get size of child + MeasureChild( childLayout, widthMeasureSpec, heightMeasureSpec ); + LayoutLength childWidth = childLayout->GetMeasuredWidth(); + LayoutLength childHeight = childLayout->GetMeasuredHeight(); + + Extents childMargin = childLayout->GetMargin(); + + // BinLayout width is that of it's widest child and it's height of the tallest child. + // MeasureSpec::Mode::UNSPECIFIED will use these sizes + layoutWidth = std::max( layoutWidth, childWidth + childMargin.start + childMargin.end ); + layoutHeight = std::max( layoutHeight, childHeight + childMargin.top + childMargin.bottom ); + DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "BinLayout::OnMeasure calculated current BinLayout width[" << layoutWidth << "] height[" << layoutHeight << "]\n" ); + } + else + { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "BinLayout::OnMeasure Not a layout\n" ); + } + } + + Extents padding = GetPadding(); + layoutWidth += padding.start + padding.end; + layoutHeight += padding.top + padding.bottom; + } + else + { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "BinLayout::OnMeasure Getting default size as a leaf\n" ); + // BinLayout does not contain any children so must be a leaf + layoutWidth = GetDefaultSize( GetSuggestedMinimumWidth(), widthMeasureSpec ); + layoutHeight = GetDefaultSize( GetSuggestedMinimumHeight(), heightMeasureSpec ); + } + + // Can't exceed specified width + if( widthMode == MeasureSpec::Mode::EXACTLY ) + { + exactWidth = true; + } + else if ( widthMode == MeasureSpec::Mode::AT_MOST ) + { + layoutWidth = std::min( layoutWidth, widthSpecSize ); + } + + // Can't exceed specified height + if( heightMode == MeasureSpec::Mode::EXACTLY ) + { + exactHeight = true; + } + else if ( heightMode == MeasureSpec::Mode::AT_MOST ) + { + layoutHeight = std::min( layoutHeight, heightSpecSize ); + } + + layoutWidth = std::max( layoutWidth, GetSuggestedMinimumWidth() ); + layoutHeight = std::max( layoutHeight, GetSuggestedMinimumHeight() ); + + if( exactWidth ) + { + layoutWidth = widthSpecSize; + } + + if( exactHeight ) + { + layoutHeight = heightSpecSize; + } + + DALI_LOG_STREAM( gLogFilter, Debug::General, "BinLayout::OnMeasure Measured size(" << layoutWidth << "," << layoutHeight << ") for : " << Actor::DownCast(GetOwner()).GetName() << " \n" ); + SetMeasuredDimensions( MeasuredSize( layoutWidth ), MeasuredSize( layoutHeight ) ); + +} + +void BinLayout::OnLayout( bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom ) +{ + auto count = GetChildCount(); + + DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "BinLayout OnLayout owner:" << ( ( Toolkit::Control::DownCast(GetOwner())) ? Toolkit::Control::DownCast(GetOwner()).GetName() : "invalid" ) << " childCount:" << count ); + + for( unsigned int childIndex = 0; childIndex < count; childIndex++) + { + LayoutItemPtr childLayout = GetChildAt( childIndex ); + if( childLayout != nullptr ) + { + + auto childOwner = childLayout->GetOwner(); + LayoutLength childWidth = childLayout->GetMeasuredWidth(); + LayoutLength childHeight = childLayout->GetMeasuredHeight(); + Extents childMargin = childLayout->GetMargin(); + auto control = Toolkit::Control::DownCast( childOwner ); + Extents padding = GetPadding(); + + auto childPosition = control.GetProperty< Vector3 >( Actor::Property::POSITION ); + auto anchorPoint = control.GetProperty< Vector3 >( Actor::Property::ANCHOR_POINT ); + + DALI_LOG_STREAM( gLogFilter, Debug::General, "BinLayout::OnLayout child[" << control.GetName() << + "] position(" << childPosition << ") child width[" << childWidth << "] height[" << childHeight << "]\n" ); + + // Margin and Padding only supported when child anchor point is TOP_LEFT. + int paddingAndMarginOffsetX = ( AnchorPoint::TOP_LEFT == anchorPoint ) ? ( padding.top + childMargin.top ) : 0; + int paddingAndMarginOffsetY = ( AnchorPoint::TOP_LEFT == anchorPoint ) ? ( padding.start + childMargin.start ) : 0; + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "BinLayout::OnLayout paddingMargin offset(%d,%d)\n", paddingAndMarginOffsetX, paddingAndMarginOffsetY ); + + LayoutLength childLeft = childPosition.x + paddingAndMarginOffsetX; + LayoutLength childTop = childPosition.y + paddingAndMarginOffsetY; + + childLayout->Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight ); + } + } +} + +} // namespace Internal +} // namespace Toolkit +} // namespace Dali diff --git a/dali-toolkit/internal/layouting/bin-layout-impl.h b/dali-toolkit/internal/layouting/bin-layout-impl.h new file mode 100644 index 0000000..d20ea64 --- /dev/null +++ b/dali-toolkit/internal/layouting/bin-layout-impl.h @@ -0,0 +1,87 @@ +#ifndef DALI_TOOLKIT_INTERNAL_BIN_LAYOUT_H +#define DALI_TOOLKIT_INTERNAL_BIN_LAYOUT_H + +/* + * 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 + +namespace Dali +{ +namespace Toolkit +{ +namespace Internal +{ + +class BinLayout; +using BinLayoutPtr = IntrusivePtr; + +class BinLayout final : public LayoutGroup +{ +public: + static BinLayoutPtr New(); + +protected: + + /** + * Constructor + */ + BinLayout(); + + /** + * Destructor + */ + virtual ~BinLayout(); + + /** + * @copydoc LayoutItem::OnMeasure + */ + virtual void OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec ) override; + + /** + * @copydoc LayoutItem::OnLayout + */ + virtual void OnLayout( bool changed, LayoutLength l, LayoutLength t, LayoutLength r, LayoutLength b ) override; + +private: + BinLayout( const BinLayout& other ) = delete; + BinLayout& operator=( const BinLayout& other ) = delete; + +}; + +} // namespace Internal + +inline Internal::BinLayout& GetImplementation( Dali::Toolkit::BinLayout& handle ) +{ + DALI_ASSERT_ALWAYS( handle && "BinLayout handle is empty" ); + BaseObject& object = handle.GetBaseObject(); + return static_cast( object ); +} + +inline const Internal::BinLayout& GetImplementation( const Dali::Toolkit::BinLayout& handle ) +{ + DALI_ASSERT_ALWAYS( handle && "BinLayout handle is empty" ); + const BaseObject& object = handle.GetBaseObject(); + return static_cast( object ); +} + +} // namespace Toolkit +} // namespace Dali + +#endif // DALI_TOOLKIT_INTERNAL_BIN_LAYOUT_H