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.
18 #include "navigation-tool-bar.h"
28 //ToDo: use const variables instead of magic numbers
30 NavigationToolBar::NavigationToolBar( NavigationControl& naviControl,
31 Toolkit::NaviToolBarStyle toolBarStylePortrait,
32 Toolkit::NaviToolBarStyle toolBarStyleLandscape )
33 : NavigationBar(naviControl, toolBarStylePortrait, toolBarStyleLandscape),
34 mStylePortrait( toolBarStylePortrait ),
35 mStyleLandscape( toolBarStyleLandscape ),
36 mCurrentStyle( &mStylePortrait),
39 // tool bar is located at the bottom of the frame
40 mLayout.SetParentOrigin( Dali::ParentOrigin::BOTTOM_CENTER );
41 mLayout.SetAnchorPoint( Dali::AnchorPoint::BOTTOM_CENTER );
44 mBackground.SetParentOrigin( Dali::ParentOrigin::BOTTOM_CENTER );
45 mBackground.SetAnchorPoint( Dali::AnchorPoint::BOTTOM_CENTER );
48 // layout of the left part, which contains only one control at CellPosition(1,1)
49 mLeftLayout = Toolkit::TableView::New(3,3);
50 mLayout.AddChild(mLeftLayout, Toolkit::TableView::CellPosition(0,0));
52 // layout of the right part, which contains only one control at CellPosition(1,1)
53 mRightLayout = Toolkit::TableView::New(3,3);
54 mLayout.AddChild(mRightLayout, Toolkit::TableView::CellPosition(0,2));
56 // layout of the central part, which contains multiples control, will add cells dynamically
57 mCentralLayout = Toolkit::TableView::New(3,2);
58 mLayout.AddChild(mCentralLayout, Toolkit::TableView::CellPosition(0,1));
63 void NavigationToolBar::AddControl(Actor actor, Toolkit::Alignment::Type alignment)
67 case Toolkit::Alignment::HorizontalLeft: // can only have one control on the left side of the bar
69 mLeftLayout.RemoveChildAt(Toolkit::TableView::CellPosition(1,1));
70 mLeftLayout.AddChild(actor, Toolkit::TableView::CellPosition(1,1));
73 case Toolkit::Alignment::HorizontalRight: // can only have one control on the right side of the bar
75 mRightLayout.RemoveChildAt(Toolkit::TableView::CellPosition(1,1));
76 mRightLayout.AddChild(actor, Toolkit::TableView::CellPosition(1,1));
79 case Toolkit::Alignment::HorizontalCenter: // can only have multiple controls on the central part of the bar
81 // already have button in central part
82 if( mCentralLayout.GetChildAt(Toolkit::TableView::CellPosition(1,1)))
84 unsigned int columnIndex = mCentralLayout.GetColumns() ;
85 mCentralLayout.InsertColumn( columnIndex-1 );
86 mCentralLayout.SetFixedWidth( columnIndex-1, mCurrentStyle->centralButtonGap );
88 mCentralLayout.InsertColumn( columnIndex );
89 mCentralLayout.AddChild(actor, Toolkit::TableView::CellPosition( 1, columnIndex ) );
91 else // have no button in central part
93 mCentralLayout.InsertColumn( 1 );
94 mCentralLayout.AddChild(actor, Toolkit::TableView::CellPosition(1,1));
100 DALI_ASSERT_ALWAYS( false );
105 void NavigationToolBar::Update( Toolkit::Page page )
107 const Toolkit::Page::ControlOnBarContainer& controls = page.GetControlsOnToolBar();
109 // if there is no control to place on the bar, hide the bar
110 if( controls.empty() )
113 mLayout.SetVisible(false);
114 mBackground.SetVisible(false);
118 //clear central controls
119 unsigned int numColumns = mCentralLayout.GetColumns() ;
120 unsigned int idx = numColumns-2;
123 mCentralLayout.DeleteColumn(idx);
126 mNumCentralActor = 0;
127 mLeftLayout.RemoveChildAt(Toolkit::TableView::CellPosition(1,1));
128 mRightLayout.RemoveChildAt(Toolkit::TableView::CellPosition(1,1));
130 Toolkit::Page::ControlOnBarContainer::const_iterator iter;
132 for( iter = controls.begin(); iter != controls.end(); iter++ )
134 AddControl( (*iter)->control, (*iter)->alignment );
137 float buttonWidth = static_cast<float>( mCurrentStyle->centralMinimum );
138 int length = mNumCentralActor * (mCurrentStyle->centralMinimum + mCurrentStyle->centralButtonGap) - mCurrentStyle->centralButtonGap;
139 if( length > mCurrentStyle->centralMaximum ) // shrink the width to make sure all the controls can be fit in
141 buttonWidth = static_cast<float>( mCurrentStyle->centralMaximum - (mNumCentralActor - 1) * mCurrentStyle->centralButtonGap )
142 / static_cast<float>( mNumCentralActor );
144 numColumns = mCentralLayout.GetColumns();
146 while(idx < numColumns-1 )
148 mCentralLayout.SetFixedWidth( idx, buttonWidth );
152 mLayout.SetVisible(true);
153 mBackground.SetVisible(true);
156 void NavigationToolBar::OrientationUpdate( bool isPortrait )
158 mCurrentStyle = isPortrait ? &mStylePortrait : &mStyleLandscape;
160 Update( mCurrentItem );
163 void NavigationToolBar::SetFixedSizes()
165 mLayout.SetFixedWidth(1, mCurrentStyle->centralMaximum);
167 mLeftLayout.SetFixedWidth(0,mCurrentStyle->hotizontalMargin);
168 mLeftLayout.SetFixedWidth(1,mCurrentStyle->sideButtonSize );
169 mLeftLayout.SetFixedHeight(1,mCurrentStyle->sideButtonSize );
171 mRightLayout.SetFixedWidth(2,mCurrentStyle->hotizontalMargin);
172 mRightLayout.SetFixedWidth(1,mCurrentStyle->sideButtonSize );
173 mRightLayout.SetFixedHeight(1,mCurrentStyle->sideButtonSize );
175 mCentralLayout.SetFixedHeight(1,mCurrentStyle->centralButtonHeight );
178 } // namespace Internal
180 } // namespace Toolkit