2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "navigation-tool-bar.h"
29 //ToDo: use const variables instead of magic numbers
31 NavigationToolBar::NavigationToolBar( NavigationControl& naviControl,
32 Toolkit::NaviToolBarStyle toolBarStylePortrait,
33 Toolkit::NaviToolBarStyle toolBarStyleLandscape )
34 : NavigationBar(naviControl, toolBarStylePortrait, toolBarStyleLandscape),
35 mStylePortrait( toolBarStylePortrait ),
36 mStyleLandscape( toolBarStyleLandscape ),
37 mCurrentStyle( &mStylePortrait),
40 // tool bar is located at the bottom of the frame
41 mLayout.SetParentOrigin( Dali::ParentOrigin::BOTTOM_CENTER );
42 mLayout.SetAnchorPoint( Dali::AnchorPoint::BOTTOM_CENTER );
45 mBackground.SetParentOrigin( Dali::ParentOrigin::BOTTOM_CENTER );
46 mBackground.SetAnchorPoint( Dali::AnchorPoint::BOTTOM_CENTER );
49 // layout of the left part, which contains only one control at CellPosition(1,1)
50 mLeftLayout = Toolkit::TableView::New(3,3);
51 mLayout.AddChild(mLeftLayout, Toolkit::TableView::CellPosition(0,0));
53 // layout of the right part, which contains only one control at CellPosition(1,1)
54 mRightLayout = Toolkit::TableView::New(3,3);
55 mLayout.AddChild(mRightLayout, Toolkit::TableView::CellPosition(0,2));
57 // layout of the central part, which contains multiples control, will add cells dynamically
58 mCentralLayout = Toolkit::TableView::New(3,2);
59 mLayout.AddChild(mCentralLayout, Toolkit::TableView::CellPosition(0,1));
64 void NavigationToolBar::AddControl(Actor actor, Toolkit::Alignment::Type alignment)
68 case Toolkit::Alignment::HorizontalLeft: // can only have one control on the left side of the bar
70 mLeftLayout.RemoveChildAt(Toolkit::TableView::CellPosition(1,1));
71 mLeftLayout.AddChild(actor, Toolkit::TableView::CellPosition(1,1));
74 case Toolkit::Alignment::HorizontalRight: // can only have one control on the right side of the bar
76 mRightLayout.RemoveChildAt(Toolkit::TableView::CellPosition(1,1));
77 mRightLayout.AddChild(actor, Toolkit::TableView::CellPosition(1,1));
80 case Toolkit::Alignment::HorizontalCenter: // can only have multiple controls on the central part of the bar
82 // already have button in central part
83 if( mCentralLayout.GetChildAt(Toolkit::TableView::CellPosition(1,1)))
85 unsigned int columnIndex = mCentralLayout.GetColumns() ;
86 mCentralLayout.InsertColumn( columnIndex-1 );
87 mCentralLayout.SetFixedWidth( columnIndex-1, mCurrentStyle->centralButtonGap );
89 mCentralLayout.InsertColumn( columnIndex );
90 mCentralLayout.AddChild(actor, Toolkit::TableView::CellPosition( 1, columnIndex ) );
92 else // have no button in central part
94 mCentralLayout.InsertColumn( 1 );
95 mCentralLayout.AddChild(actor, Toolkit::TableView::CellPosition(1,1));
101 DALI_ASSERT_ALWAYS( false );
106 void NavigationToolBar::Update( Toolkit::Page page )
108 const Toolkit::Page::ControlOnBarContainer& controls = page.GetControlsOnToolBar();
110 // if there is no control to place on the bar, hide the bar
111 if( controls.empty() )
114 mLayout.SetVisible(false);
115 mBackground.SetVisible(false);
119 //clear central controls
120 unsigned int numColumns = mCentralLayout.GetColumns() ;
121 unsigned int idx = numColumns-2;
124 mCentralLayout.DeleteColumn(idx);
127 mNumCentralActor = 0;
128 mLeftLayout.RemoveChildAt(Toolkit::TableView::CellPosition(1,1));
129 mRightLayout.RemoveChildAt(Toolkit::TableView::CellPosition(1,1));
131 Toolkit::Page::ControlOnBarContainer::const_iterator iter;
133 for( iter = controls.begin(); iter != controls.end(); iter++ )
135 AddControl( (*iter)->control, (*iter)->alignment );
138 float buttonWidth = static_cast<float>( mCurrentStyle->centralMinimum );
139 int length = mNumCentralActor * (mCurrentStyle->centralMinimum + mCurrentStyle->centralButtonGap) - mCurrentStyle->centralButtonGap;
140 if( length > mCurrentStyle->centralMaximum ) // shrink the width to make sure all the controls can be fit in
142 buttonWidth = static_cast<float>( mCurrentStyle->centralMaximum - (mNumCentralActor - 1) * mCurrentStyle->centralButtonGap )
143 / static_cast<float>( mNumCentralActor );
145 numColumns = mCentralLayout.GetColumns();
147 while(idx < numColumns-1 )
149 mCentralLayout.SetFixedWidth( idx, buttonWidth );
153 mLayout.SetVisible(true);
154 mBackground.SetVisible(true);
157 void NavigationToolBar::OrientationUpdate( bool isPortrait )
159 mCurrentStyle = isPortrait ? &mStylePortrait : &mStyleLandscape;
161 Update( mCurrentItem );
164 void NavigationToolBar::SetFixedSizes()
166 mLayout.SetFixedWidth(1, mCurrentStyle->centralMaximum);
168 mLeftLayout.SetFixedWidth(0,mCurrentStyle->hotizontalMargin);
169 mLeftLayout.SetFixedWidth(1,mCurrentStyle->sideButtonSize );
170 mLeftLayout.SetFixedHeight(1,mCurrentStyle->sideButtonSize );
172 mRightLayout.SetFixedWidth(2,mCurrentStyle->hotizontalMargin);
173 mRightLayout.SetFixedWidth(1,mCurrentStyle->sideButtonSize );
174 mRightLayout.SetFixedHeight(1,mCurrentStyle->sideButtonSize );
176 mCentralLayout.SetFixedHeight(1,mCurrentStyle->centralButtonHeight );
179 } // namespace Internal
181 } // namespace Toolkit