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-title-bar.h"
28 //ToDo: use const variables instead of magic numbers
30 NavigationTitleBar::NavigationTitleBar(NavigationControl& naviControl,
31 Toolkit::NaviTitleBarStyle titleBarStylePortrait,
32 Toolkit::NaviTitleBarStyle titleBarStyleLandscape )
33 : NavigationBar(naviControl, titleBarStylePortrait, titleBarStyleLandscape ),
34 mStylePortrait( titleBarStylePortrait ),
35 mStyleLandscape( titleBarStyleLandscape ),
36 mCurrentStyle( &mStylePortrait )
38 // title bar is located at the top of the frame
39 mLayout.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
40 mLayout.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
43 mBackground.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
44 mBackground.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
47 // button layout: three rows, controls will be put in the middle row, the top and bottom rows are just for margins
48 mButtonLayout = Toolkit::TableView::New(3, 1);
49 // title layout: fours rows, the top and bottom rows are just for margins
50 // if subtitle exists, title in the second row and subtitle in the third row
51 // if no subtitle, title will occupy both second and third row
52 mTitleLayout= Toolkit::TableView::New( 4,1 );
53 // title icon layout: the top row, the bottom row and the left column are all for margins
54 mTitleIconLayout= Toolkit::TableView::New( 3,2 );
57 mTitle = Toolkit::TextView::New();
58 mTitle.SetTextAlignment( Toolkit::Alignment::HorizontalLeft );
59 mTitle.SetWidthExceedPolicy(Toolkit::TextView::ShrinkToFit);
60 mSubTitle = Toolkit::TextView::New();
61 mSubTitle.SetTextAlignment( Toolkit::Alignment::HorizontalLeft );
62 mSubTitle.SetWidthExceedPolicy(Toolkit::TextView::ShrinkToFit);
65 void NavigationTitleBar::Update( Toolkit::Page page )
67 const std::vector<Actor>& controls = page.GetControlsOnTitleBar();
69 // if there is no control to place on the bar ano no title is set, hide the bar
70 if(controls.empty() && page.GetTitle().empty())
73 mLayout.SetVisible(false);
74 mBackground.SetVisible(false);
78 if(mLayout.GetColumns() == 4)// | leftMargin | titleLayout(may have icon and subtitle) | buttonLayout | rightMargin |
81 mLayout.DeleteColumn(2);
84 mLayout.RemoveChildAt( Toolkit::TableView::CellPosition(0,1) );
85 //Remove the controls in the buttonLayout
86 mButtonLayout.Resize(3,1);
88 if(mTitleLayout.GetColumns() == 2)
90 mTitleLayout.DeleteColumn( 0 );
92 // remove title and subtitle
93 mTitleLayout.RemoveChildAt( Toolkit::TableView::CellPosition(2,0) );
94 mTitleLayout.RemoveChildAt( Toolkit::TableView::CellPosition(1,0) );
96 // add controls at the right part of the bar(if exist)
99 int numControls = controls.size();
101 for( int index = 0; index < numControls; index++)
103 mButtonLayout.AddChild( controls[index], Toolkit::TableView::CellPosition(1, 2*index + 1) );
104 mButtonLayout.SetFixedWidth (2*index, mCurrentStyle->gapBetweenButtons);
105 mButtonLayout.SetFixedWidth (2*index+1, mCurrentStyle->buttonSize);
108 mLayout.InsertColumn(2);
109 mLayout.SetFixedWidth(2, numControls * ( mCurrentStyle->buttonSize + mCurrentStyle->gapBetweenButtons) );
110 mLayout.AddChild(mButtonLayout, Toolkit::TableView::CellPosition(0,2));
113 // add title and subtitle(if exist)
114 mTitle.SetText( page.GetTitle() );
115 mTitle.SetStyleToCurrentText(mCurrentStyle->titleTextStyle);
116 if( page.GetSubTitle().empty() ) //display title
118 mTitleLayout.SetFixedHeight( 1,mCurrentStyle->titleHeightWithoutSubtitle - mCurrentStyle->subtitleHeight );
119 mTitleLayout.AddChild( mTitle, Toolkit::TableView::CellPosition(1,0,2,1) );
121 else //display title and subtitle
123 mTitleLayout.SetFixedHeight( 1, mCurrentStyle->titleHeightWithSubtitle );
124 mTitleLayout.AddChild( mTitle, Toolkit::TableView::CellPosition(1,0) );
125 mSubTitle.SetText( page.GetSubTitle() );
126 mSubTitle.SetStyleToCurrentText(mCurrentStyle->subtitleTextStyle);
127 mTitleLayout.AddChild( mSubTitle, Toolkit::TableView::CellPosition(2,0) );
130 // insert title icon to the left of the title(if exist)
131 if( page.GetTitleIcon() )
133 mTitleIconLayout.RemoveChildAt(Toolkit::TableView::CellPosition(1,0) );
134 mTitleIconLayout.AddChild( page.GetTitleIcon(), Toolkit::TableView::CellPosition(1,0) );
135 mTitleLayout.InsertColumn( 0 );
136 mTitleLayout.SetFixedWidth( 0, mCurrentStyle->titleLeftMargin + mCurrentStyle->titleIconSize);
137 mTitleLayout.AddChild( mTitleIconLayout, Toolkit::TableView::CellPosition(1,0,2,1) );
140 mLayout.AddChild( mTitleLayout, Toolkit::TableView::CellPosition(0,1) );
143 mLayout.SetVisible(true);
144 mBackground.SetVisible(true);
147 void NavigationTitleBar::OrientationUpdate( bool isPortrait )
149 mCurrentStyle = isPortrait ? &mStylePortrait : &mStyleLandscape;
151 Update( mCurrentItem );
154 void NavigationTitleBar::SetFixedSizes()
156 mLayout.SetFixedWidth(0, mCurrentStyle->titleLeftMargin);
157 mLayout.SetFixedWidth(2, mCurrentStyle->buttonRightMargin);
159 mButtonLayout.SetFixedHeight(2, mCurrentStyle->buttonBottomMargin);
160 mButtonLayout.SetFixedHeight(1, mCurrentStyle->buttonSize);
162 mTitleLayout.SetFixedHeight( 3,mCurrentStyle->titleBottomMargin );
163 mTitleLayout.SetFixedHeight( 2,mCurrentStyle->subtitleHeight );
165 mTitleIconLayout.SetFixedWidth( 0, mCurrentStyle->titleIconSize );
166 mTitleIconLayout.SetFixedHeight( 1, mCurrentStyle->titleIconSize );
169 } // namespace Internal
171 } // namespace Toolkit