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-title-bar.h"
30 //ToDo: use const variables instead of magic numbers
32 NavigationTitleBar::NavigationTitleBar(NavigationControl& naviControl,
33 Toolkit::NaviTitleBarStyle titleBarStylePortrait,
34 Toolkit::NaviTitleBarStyle titleBarStyleLandscape )
35 : NavigationBar(naviControl, titleBarStylePortrait, titleBarStyleLandscape ),
36 mStylePortrait( titleBarStylePortrait ),
37 mStyleLandscape( titleBarStyleLandscape ),
38 mCurrentStyle( &mStylePortrait )
40 // title bar is located at the top of the frame
41 mLayout.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
42 mLayout.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
45 mBackground.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
46 mBackground.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
49 // button layout: three rows, controls will be put in the middle row, the top and bottom rows are just for margins
50 mButtonLayout = Toolkit::TableView::New(3, 1);
51 // title layout: fours rows, the top and bottom rows are just for margins
52 // if subtitle exists, title in the second row and subtitle in the third row
53 // if no subtitle, title will occupy both second and third row
54 mTitleLayout= Toolkit::TableView::New( 4,1 );
55 // title icon layout: the top row, the bottom row and the left column are all for margins
56 mTitleIconLayout= Toolkit::TableView::New( 3,2 );
59 mTitle = Toolkit::TextLabel::New();
60 mSubTitle = Toolkit::TextLabel::New();
63 void NavigationTitleBar::Update( Toolkit::Page page )
65 const std::vector<Actor>& controls = page.GetControlsOnTitleBar();
67 // if there is no control to place on the bar ano no title is set, hide the bar
68 if(controls.empty() && page.GetTitle().empty())
71 mLayout.SetVisible(false);
72 mBackground.SetVisible(false);
76 if(mLayout.GetColumns() == 4)// | leftMargin | titleLayout(may have icon and subtitle) | buttonLayout | rightMargin |
79 mLayout.DeleteColumn(2);
82 mLayout.RemoveChildAt( Toolkit::TableView::CellPosition(0,1) );
83 //Remove the controls in the buttonLayout
84 mButtonLayout.Resize(3,1);
86 if(mTitleLayout.GetColumns() == 2)
88 mTitleLayout.DeleteColumn( 0 );
90 // remove title and subtitle
91 mTitleLayout.RemoveChildAt( Toolkit::TableView::CellPosition(2,0) );
92 mTitleLayout.RemoveChildAt( Toolkit::TableView::CellPosition(1,0) );
94 // add controls at the right part of the bar(if exist)
97 int numControls = controls.size();
99 for( int index = 0; index < numControls; index++)
101 mButtonLayout.AddChild( controls[index], Toolkit::TableView::CellPosition(1, 2*index + 1) );
102 mButtonLayout.SetFixedWidth (2*index, mCurrentStyle->gapBetweenButtons);
103 mButtonLayout.SetFixedWidth (2*index+1, mCurrentStyle->buttonSize);
106 mLayout.InsertColumn(2);
107 mLayout.SetFixedWidth(2, numControls * ( mCurrentStyle->buttonSize + mCurrentStyle->gapBetweenButtons) );
108 mLayout.AddChild(mButtonLayout, Toolkit::TableView::CellPosition(0,2));
111 // add title and subtitle(if exist)
112 mTitle.SetProperty( Toolkit::TextLabel::Property::TEXT, page.GetTitle() );
113 if( page.GetSubTitle().empty() ) //display title
115 mTitleLayout.SetFixedHeight( 1,mCurrentStyle->titleHeightWithoutSubtitle - mCurrentStyle->subtitleHeight );
116 mTitleLayout.AddChild( mTitle, Toolkit::TableView::CellPosition(1,0,2,1) );
118 else //display title and subtitle
120 mTitleLayout.SetFixedHeight( 1, mCurrentStyle->titleHeightWithSubtitle );
121 mTitleLayout.AddChild( mTitle, Toolkit::TableView::CellPosition(1,0) );
122 mSubTitle.SetProperty( Toolkit::TextLabel::Property::TEXT, page.GetSubTitle() );
123 mTitleLayout.AddChild( mSubTitle, Toolkit::TableView::CellPosition(2,0) );
126 // insert title icon to the left of the title(if exist)
127 if( page.GetTitleIcon() )
129 mTitleIconLayout.RemoveChildAt(Toolkit::TableView::CellPosition(1,0) );
130 mTitleIconLayout.AddChild( page.GetTitleIcon(), Toolkit::TableView::CellPosition(1,0) );
131 mTitleLayout.InsertColumn( 0 );
132 mTitleLayout.SetFixedWidth( 0, mCurrentStyle->titleLeftMargin + mCurrentStyle->titleIconSize);
133 mTitleLayout.AddChild( mTitleIconLayout, Toolkit::TableView::CellPosition(1,0,2,1) );
136 mLayout.AddChild( mTitleLayout, Toolkit::TableView::CellPosition(0,1) );
139 mLayout.SetVisible(true);
140 mBackground.SetVisible(true);
143 void NavigationTitleBar::OrientationUpdate( bool isPortrait )
145 mCurrentStyle = isPortrait ? &mStylePortrait : &mStyleLandscape;
147 Update( mCurrentItem );
150 void NavigationTitleBar::SetFixedSizes()
152 mLayout.SetFixedWidth(0, mCurrentStyle->titleLeftMargin);
153 mLayout.SetFixedWidth(2, mCurrentStyle->buttonRightMargin);
155 mButtonLayout.SetFixedHeight(2, mCurrentStyle->buttonBottomMargin);
156 mButtonLayout.SetFixedHeight(1, mCurrentStyle->buttonSize);
158 mTitleLayout.SetFixedHeight( 3,mCurrentStyle->titleBottomMargin );
159 mTitleLayout.SetFixedHeight( 2,mCurrentStyle->subtitleHeight );
161 mTitleIconLayout.SetFixedWidth( 0, mCurrentStyle->titleIconSize );
162 mTitleIconLayout.SetFixedHeight( 1, mCurrentStyle->titleIconSize );
165 } // namespace Internal
167 } // namespace Toolkit