2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 #include "navigation-tool-bar.h"
27 //ToDo: use const variables instead of magic numbers
29 NavigationToolBar::NavigationToolBar( NavigationControl& naviControl,
30 Toolkit::NaviToolBarStyle toolBarStylePortrait,
31 Toolkit::NaviToolBarStyle toolBarStyleLandscape )
32 : NavigationBar(naviControl, toolBarStylePortrait, toolBarStyleLandscape),
33 mStylePortrait( toolBarStylePortrait ),
34 mStyleLandscape( toolBarStyleLandscape ),
35 mCurrentStyle( &mStylePortrait),
38 // tool bar is located at the bottom of the frame
39 mLayout.SetParentOrigin( Dali::ParentOrigin::BOTTOM_CENTER );
40 mLayout.SetAnchorPoint( Dali::AnchorPoint::BOTTOM_CENTER );
43 mBackground.SetParentOrigin( Dali::ParentOrigin::BOTTOM_CENTER );
44 mBackground.SetAnchorPoint( Dali::AnchorPoint::BOTTOM_CENTER );
47 // layout of the left part, which contains only one control at CellPosition(1,1)
48 mLeftLayout = Toolkit::TableView::New(3,3);
49 mLayout.AddChild(mLeftLayout, Toolkit::TableView::CellPosition(0,0));
51 // layout of the right part, which contains only one control at CellPosition(1,1)
52 mRightLayout = Toolkit::TableView::New(3,3);
53 mLayout.AddChild(mRightLayout, Toolkit::TableView::CellPosition(0,2));
55 // layout of the central part, which contains multiples control, will add cells dynamically
56 mCentralLayout = Toolkit::TableView::New(3,2);
57 mLayout.AddChild(mCentralLayout, Toolkit::TableView::CellPosition(0,1));
62 void NavigationToolBar::AddControl(Actor actor, Toolkit::Alignment::Type alignment)
66 case Toolkit::Alignment::HorizontalLeft: // can only have one control on the left side of the bar
68 mLeftLayout.RemoveChildAt(Toolkit::TableView::CellPosition(1,1));
69 mLeftLayout.AddChild(actor, Toolkit::TableView::CellPosition(1,1));
72 case Toolkit::Alignment::HorizontalRight: // can only have one control on the right side of the bar
74 mRightLayout.RemoveChildAt(Toolkit::TableView::CellPosition(1,1));
75 mRightLayout.AddChild(actor, Toolkit::TableView::CellPosition(1,1));
78 case Toolkit::Alignment::HorizontalCenter: // can only have multiple controls on the central part of the bar
80 // already have button in central part
81 if( mCentralLayout.GetChildAt(Toolkit::TableView::CellPosition(1,1)))
83 unsigned int columnIndex = mCentralLayout.GetColumns() ;
84 mCentralLayout.InsertColumn( columnIndex-1 );
85 mCentralLayout.SetFixedWidth( columnIndex-1, mCurrentStyle->centralButtonGap );
87 mCentralLayout.InsertColumn( columnIndex );
88 mCentralLayout.AddChild(actor, Toolkit::TableView::CellPosition( 1, columnIndex ) );
90 else // have no button in central part
92 mCentralLayout.InsertColumn( 1 );
93 mCentralLayout.AddChild(actor, Toolkit::TableView::CellPosition(1,1));
99 DALI_ASSERT_ALWAYS( false );
104 void NavigationToolBar::Update( Toolkit::Page page )
106 const Toolkit::Page::ControlOnBarContainer& controls = page.GetControlsOnToolBar();
108 // if there is no control to place on the bar, hide the bar
109 if( controls.empty() )
112 mLayout.SetVisible(false);
113 mBackground.SetVisible(false);
117 //clear central controls
118 unsigned int numColumns = mCentralLayout.GetColumns() ;
119 unsigned int idx = numColumns-2;
122 mCentralLayout.DeleteColumn(idx);
125 mNumCentralActor = 0;
126 mLeftLayout.RemoveChildAt(Toolkit::TableView::CellPosition(1,1));
127 mRightLayout.RemoveChildAt(Toolkit::TableView::CellPosition(1,1));
129 Toolkit::Page::ControlOnBarContainer::const_iterator iter;
131 for( iter = controls.begin(); iter != controls.end(); iter++ )
133 AddControl( (*iter)->control, (*iter)->alignment );
136 float buttonWidth = static_cast<float>( mCurrentStyle->centralMinimum );
137 int length = mNumCentralActor * (mCurrentStyle->centralMinimum + mCurrentStyle->centralButtonGap) - mCurrentStyle->centralButtonGap;
138 if( length > mCurrentStyle->centralMaximum ) // shrink the width to make sure all the controls can be fit in
140 buttonWidth = static_cast<float>( mCurrentStyle->centralMaximum - (mNumCentralActor - 1) * mCurrentStyle->centralButtonGap )
141 / static_cast<float>( mNumCentralActor );
143 numColumns = mCentralLayout.GetColumns();
145 while(idx < numColumns-1 )
147 mCentralLayout.SetFixedWidth( idx, buttonWidth );
151 mLayout.SetVisible(true);
152 mBackground.SetVisible(true);
155 void NavigationToolBar::OrientationUpdate( bool isPortrait )
157 mCurrentStyle = isPortrait ? &mStylePortrait : &mStyleLandscape;
159 Update( mCurrentItem );
162 void NavigationToolBar::SetFixedSizes()
164 mLayout.SetFixedWidth(1, mCurrentStyle->centralMaximum);
166 mLeftLayout.SetFixedWidth(0,mCurrentStyle->hotizontalMargin);
167 mLeftLayout.SetFixedWidth(1,mCurrentStyle->sideButtonSize );
168 mLeftLayout.SetFixedHeight(1,mCurrentStyle->sideButtonSize );
170 mRightLayout.SetFixedWidth(2,mCurrentStyle->hotizontalMargin);
171 mRightLayout.SetFixedWidth(1,mCurrentStyle->sideButtonSize );
172 mRightLayout.SetFixedHeight(1,mCurrentStyle->sideButtonSize );
174 mCentralLayout.SetFixedHeight(1,mCurrentStyle->centralButtonHeight );
177 } // namespace Internal
179 } // namespace Toolkit