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-title-bar.h"
29 //ToDo: use const variables instead of magic numbers
31 NavigationTitleBar::NavigationTitleBar(NavigationControl& naviControl,
32 Toolkit::NaviTitleBarStyle titleBarStylePortrait,
33 Toolkit::NaviTitleBarStyle titleBarStyleLandscape )
34 : NavigationBar(naviControl, titleBarStylePortrait, titleBarStyleLandscape ),
35 mStylePortrait( titleBarStylePortrait ),
36 mStyleLandscape( titleBarStyleLandscape ),
37 mCurrentStyle( &mStylePortrait )
39 // title bar is located at the top of the frame
40 mLayout.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
41 mLayout.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
44 mBackground.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
45 mBackground.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
48 // button layout: three rows, controls will be put in the middle row, the top and bottom rows are just for margins
49 mButtonLayout = Toolkit::TableView::New(3, 1);
50 // title layout: fours rows, the top and bottom rows are just for margins
51 // if subtitle exists, title in the second row and subtitle in the third row
52 // if no subtitle, title will occupy both second and third row
53 mTitleLayout= Toolkit::TableView::New( 4,1 );
54 // title icon layout: the top row, the bottom row and the left column are all for margins
55 mTitleIconLayout= Toolkit::TableView::New( 3,2 );
58 mTitle = Toolkit::TextView::New();
59 mTitle.SetTextAlignment( Toolkit::Alignment::HorizontalLeft );
60 mTitle.SetWidthExceedPolicy(Toolkit::TextView::ShrinkToFit);
61 mSubTitle = Toolkit::TextView::New();
62 mSubTitle.SetTextAlignment( Toolkit::Alignment::HorizontalLeft );
63 mSubTitle.SetWidthExceedPolicy(Toolkit::TextView::ShrinkToFit);
66 void NavigationTitleBar::Update( Toolkit::Page page )
68 const std::vector<Actor>& controls = page.GetControlsOnTitleBar();
70 // if there is no control to place on the bar ano no title is set, hide the bar
71 if(controls.empty() && page.GetTitle().empty())
74 mLayout.SetVisible(false);
75 mBackground.SetVisible(false);
79 if(mLayout.GetColumns() == 4)// | leftMargin | titleLayout(may have icon and subtitle) | buttonLayout | rightMargin |
82 mLayout.DeleteColumn(2);
85 mLayout.RemoveChildAt( Toolkit::TableView::CellPosition(0,1) );
86 //Remove the controls in the buttonLayout
87 mButtonLayout.Resize(3,1);
89 if(mTitleLayout.GetColumns() == 2)
91 mTitleLayout.DeleteColumn( 0 );
93 // remove title and subtitle
94 mTitleLayout.RemoveChildAt( Toolkit::TableView::CellPosition(2,0) );
95 mTitleLayout.RemoveChildAt( Toolkit::TableView::CellPosition(1,0) );
97 // add controls at the right part of the bar(if exist)
100 int numControls = controls.size();
102 for( int index = 0; index < numControls; index++)
104 mButtonLayout.AddChild( controls[index], Toolkit::TableView::CellPosition(1, 2*index + 1) );
105 mButtonLayout.SetFixedWidth (2*index, mCurrentStyle->gapBetweenButtons);
106 mButtonLayout.SetFixedWidth (2*index+1, mCurrentStyle->buttonSize);
109 mLayout.InsertColumn(2);
110 mLayout.SetFixedWidth(2, numControls * ( mCurrentStyle->buttonSize + mCurrentStyle->gapBetweenButtons) );
111 mLayout.AddChild(mButtonLayout, Toolkit::TableView::CellPosition(0,2));
114 // add title and subtitle(if exist)
115 mTitle.SetText( page.GetTitle() );
116 mTitle.SetStyleToCurrentText(mCurrentStyle->titleTextStyle);
117 if( page.GetSubTitle().empty() ) //display title
119 mTitleLayout.SetFixedHeight( 1,mCurrentStyle->titleHeightWithoutSubtitle - mCurrentStyle->subtitleHeight );
120 mTitleLayout.AddChild( mTitle, Toolkit::TableView::CellPosition(1,0,2,1) );
122 else //display title and subtitle
124 mTitleLayout.SetFixedHeight( 1, mCurrentStyle->titleHeightWithSubtitle );
125 mTitleLayout.AddChild( mTitle, Toolkit::TableView::CellPosition(1,0) );
126 mSubTitle.SetText( page.GetSubTitle() );
127 mSubTitle.SetStyleToCurrentText(mCurrentStyle->subtitleTextStyle);
128 mTitleLayout.AddChild( mSubTitle, Toolkit::TableView::CellPosition(2,0) );
131 // insert title icon to the left of the title(if exist)
132 if( page.GetTitleIcon() )
134 mTitleIconLayout.RemoveChildAt(Toolkit::TableView::CellPosition(1,0) );
135 mTitleIconLayout.AddChild( page.GetTitleIcon(), Toolkit::TableView::CellPosition(1,0) );
136 mTitleLayout.InsertColumn( 0 );
137 mTitleLayout.SetFixedWidth( 0, mCurrentStyle->titleLeftMargin + mCurrentStyle->titleIconSize);
138 mTitleLayout.AddChild( mTitleIconLayout, Toolkit::TableView::CellPosition(1,0,2,1) );
141 mLayout.AddChild( mTitleLayout, Toolkit::TableView::CellPosition(0,1) );
144 mLayout.SetVisible(true);
145 mBackground.SetVisible(true);
148 void NavigationTitleBar::OrientationUpdate( bool isPortrait )
150 mCurrentStyle = isPortrait ? &mStylePortrait : &mStyleLandscape;
152 Update( mCurrentItem );
155 void NavigationTitleBar::SetFixedSizes()
157 mLayout.SetFixedWidth(0, mCurrentStyle->titleLeftMargin);
158 mLayout.SetFixedWidth(2, mCurrentStyle->buttonRightMargin);
160 mButtonLayout.SetFixedHeight(2, mCurrentStyle->buttonBottomMargin);
161 mButtonLayout.SetFixedHeight(1, mCurrentStyle->buttonSize);
163 mTitleLayout.SetFixedHeight( 3,mCurrentStyle->titleBottomMargin );
164 mTitleLayout.SetFixedHeight( 2,mCurrentStyle->subtitleHeight );
166 mTitleIconLayout.SetFixedWidth( 0, mCurrentStyle->titleIconSize );
167 mTitleIconLayout.SetFixedHeight( 1, mCurrentStyle->titleIconSize );
170 } // namespace Internal
172 } // namespace Toolkit