From: Seoyeon Kim Date: Wed, 25 Jul 2018 11:25:27 +0000 (+0900) Subject: Fix LinearLayout Padding bug X-Git-Tag: dali_1.3.35~3 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=0ef77c739edd21d230e5501d03e01ab37eb70257;ds=sidebyside Fix LinearLayout Padding bug - Consider padding.start to child left when layouting the children vertically. - Consider padding.top to child top at first on Layout passes. Change-Id: I75236f8c85a4b5e91edc5868da2250bdc9bf3f19 Signed-off-by: Seoyeon Kim --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp index 76f9cf4..29e3726 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp @@ -1521,6 +1521,95 @@ int UtcDaliLayouting_VboxLayout03(void) END_TEST; } +int UtcDaliLayouting_VboxLayout_Padding(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliLayouting_VboxLayout_Padding - Adding Padding to the vbox"); + + // Adding padding to the layout should offset the positioning of the children. + + const Extents LAYOUT_PADDING = Extents(5, 10, 20, 2 ); + const Size CONTROL_SIZE = Size( 40, 40 ); + + Stage stage = Stage::GetCurrent(); + // Create a root layout, ideally Dali would have a default layout in the root layer. + // Without this root layer the LinearLayout (or any other layout) will not + // honour WIDTH_SPECIFICATION or HEIGHT_SPECIFICATION settings. + // It uses the default stage size and ideally should have a layout added to it. + auto rootLayoutControl = Control::New(); + rootLayoutControl.SetName( "AbsoluteLayout"); + auto rootLayout = AbsoluteLayout::New(); + DevelControl::SetLayout( rootLayoutControl, rootLayout ); + rootLayoutControl.SetAnchorPoint( AnchorPoint::CENTER ); + rootLayoutControl.SetParentOrigin( ParentOrigin::CENTER ); + stage.Add( rootLayoutControl ); + + auto vbox = Control::New(); + auto vboxLayout = LinearLayout::New(); + vboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL ); + DevelControl::SetLayout( vbox, vboxLayout ); + vbox.SetName( "VBox"); + vbox.SetProperty( Toolkit::Control::Property::PADDING, LAYOUT_PADDING ); + vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT ); + vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT ); + + std::vector< Control > controls; + controls.push_back( CreateLeafControl( CONTROL_SIZE.width, CONTROL_SIZE.height ) ); + controls.push_back( CreateLeafControl( CONTROL_SIZE.width, CONTROL_SIZE.height ) ); + controls.push_back( CreateLeafControl( CONTROL_SIZE.width, CONTROL_SIZE.height ) ); + controls.push_back( CreateLeafControl( CONTROL_SIZE.width, CONTROL_SIZE.height ) ); + + for( auto&& iter : controls ) + { + vbox.Add( iter ); + } + + vbox.SetParentOrigin( ParentOrigin::CENTER ); + vbox.SetAnchorPoint( AnchorPoint::CENTER ); + rootLayoutControl.Add( vbox ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + // Extra update needed to Relayout one more time. Catches any position updates, false positive without this seen. + application.SendNotification(); + + // vbox centers elements horizontally, it fills test harness stage, which is 480x800. + tet_infoline("Test Child Actor Position"); + + auto controlYPosition = 0.0f; + + controlYPosition = LAYOUT_PADDING.top; // First child positioned at offset defined by the padding + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::POSITION ), Vector3( LAYOUT_PADDING.start, + LAYOUT_PADDING.top, + 0.0f ), 0.0001f, TEST_LOCATION ); + + controlYPosition += CONTROL_SIZE.height; // Second child positioned is the position of the first child + the first child's height. + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::POSITION ), Vector3( LAYOUT_PADDING.start, + controlYPosition, + 0.0f ), + 0.0001f, TEST_LOCATION ); + + controlYPosition += CONTROL_SIZE.height; // Third child positioned adjacent to second + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::POSITION ), Vector3( LAYOUT_PADDING.start, + controlYPosition, + 0.0f ), 0.0001f, TEST_LOCATION ); + + controlYPosition += CONTROL_SIZE.height; // Forth passed adjacent to the third + DALI_TEST_EQUALS( controls[3].GetProperty( Actor::Property::POSITION ), Vector3( LAYOUT_PADDING.start, + controlYPosition, + 0.0f ), 0.0001f, TEST_LOCATION ); + + auto totalControlsWidth = CONTROL_SIZE.width; + auto totalControlsHeight = CONTROL_SIZE.height * controls.size(); + + DALI_TEST_EQUALS( vbox.GetProperty( Actor::Property::SIZE ), Vector3( totalControlsWidth + LAYOUT_PADDING.start + LAYOUT_PADDING.end, + totalControlsHeight + LAYOUT_PADDING.top + LAYOUT_PADDING.bottom, + 0.0f ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} int UtcDaliLayouting_RelayoutOnChildOrderChanged(void) diff --git a/dali-toolkit/internal/layouting/linear-layout-impl.cpp b/dali-toolkit/internal/layouting/linear-layout-impl.cpp index 7b3720c..f989a54 100644 --- a/dali-toolkit/internal/layouting/linear-layout-impl.cpp +++ b/dali-toolkit/internal/layouting/linear-layout-impl.cpp @@ -273,7 +273,7 @@ void LinearLayout::LayoutHorizontal( LayoutLength left, LayoutLength top, Layout Extents padding = GetPadding(); - LayoutLength childTop( 0 ); + LayoutLength childTop( padding.top ); LayoutLength childLeft( padding.start ); // Where bottom of child should go @@ -433,7 +433,7 @@ void LinearLayout::LayoutVertical( LayoutLength left, LayoutLength top, LayoutLe { Extents padding = GetPadding(); - LayoutLength childTop( 0 ); + LayoutLength childTop( padding.top ); LayoutLength childLeft( padding.start ); // Where bottom of child should go @@ -453,7 +453,7 @@ void LinearLayout::LayoutVertical( LayoutLength left, LayoutLength top, LayoutLe auto childMargin = childLayout->GetMargin(); childTop += childMargin.top; - childLeft = ( childSpace - childWidth ) / 2 + childMargin.start - childMargin.end; + childLeft = LayoutLength( padding.start ) + ( childSpace - childWidth ) / 2 + childMargin.start - childMargin.end; childLayout->Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight ); childTop += childHeight + childMargin.bottom + mCellPadding.height;