Add 'ExclusiveArch: armv7l' limit build to arm architecture
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / navigation-frame / navigation-title-bar.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 #include "navigation-title-bar.h"
18
19 namespace Dali
20 {
21
22 namespace Toolkit
23 {
24
25 namespace Internal
26 {
27
28 //ToDo: use const variables instead of magic numbers
29
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 )
37 {
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 );
41   if(mBackground)
42   {
43     mBackground.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
44     mBackground.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
45   }
46
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 );
55   SetFixedSizes();
56
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);
63 }
64
65 void NavigationTitleBar::Update( Toolkit::Page page )
66 {
67   const std::vector<Actor>& controls = page.GetControlsOnTitleBar();
68
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())
71   {
72     mVisible = false;
73     mLayout.SetVisible(false);
74     mBackground.SetVisible(false);
75     return;
76   }
77
78   if(mLayout.GetColumns() == 4)// | leftMargin | titleLayout(may have icon and subtitle) | buttonLayout | rightMargin |
79   {
80     //remove buttonLayout
81     mLayout.DeleteColumn(2);
82   }
83   // remove titleLayout
84   mLayout.RemoveChildAt( Toolkit::TableView::CellPosition(0,1) );
85   //Remove the controls in the buttonLayout
86   mButtonLayout.Resize(3,1);
87   //remove titleIcon
88   if(mTitleLayout.GetColumns() == 2)
89   {
90     mTitleLayout.DeleteColumn( 0 );
91   }
92   // remove title and subtitle
93   mTitleLayout.RemoveChildAt( Toolkit::TableView::CellPosition(2,0) );
94   mTitleLayout.RemoveChildAt( Toolkit::TableView::CellPosition(1,0) );
95
96   // add controls at the right part of the bar(if exist)
97   if(!controls.empty())
98   {
99     int numControls = controls.size();
100
101     for( int index = 0; index < numControls; index++)
102     {
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);
106     }
107
108     mLayout.InsertColumn(2);
109     mLayout.SetFixedWidth(2, numControls * ( mCurrentStyle->buttonSize + mCurrentStyle->gapBetweenButtons) );
110     mLayout.AddChild(mButtonLayout, Toolkit::TableView::CellPosition(0,2));
111   }
112
113   // add title and subtitle(if exist)
114   mTitle.SetText( page.GetTitle() );
115   mTitle.SetStyleToCurrentText(mCurrentStyle->titleTextStyle);
116   if( page.GetSubTitle().empty() )  //display title
117   {
118     mTitleLayout.SetFixedHeight( 1,mCurrentStyle->titleHeightWithoutSubtitle - mCurrentStyle->subtitleHeight );
119     mTitleLayout.AddChild( mTitle, Toolkit::TableView::CellPosition(1,0,2,1) );
120   }
121   else //display title and subtitle
122   {
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) );
128   }
129
130   // insert title icon to the left of the title(if exist)
131   if( page.GetTitleIcon() )
132   {
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) );
138   }
139
140   mLayout.AddChild( mTitleLayout, Toolkit::TableView::CellPosition(0,1) );
141
142   mVisible = true;
143   mLayout.SetVisible(true);
144   mBackground.SetVisible(true);
145 }
146
147 void NavigationTitleBar::OrientationUpdate( bool isPortrait )
148 {
149   mCurrentStyle = isPortrait ? &mStylePortrait : &mStyleLandscape;
150   SetFixedSizes();
151   Update( mCurrentItem );
152 }
153
154 void NavigationTitleBar::SetFixedSizes()
155 {
156   mLayout.SetFixedWidth(0, mCurrentStyle->titleLeftMargin);
157   mLayout.SetFixedWidth(2, mCurrentStyle->buttonRightMargin);
158
159   mButtonLayout.SetFixedHeight(2, mCurrentStyle->buttonBottomMargin);
160   mButtonLayout.SetFixedHeight(1, mCurrentStyle->buttonSize);
161
162   mTitleLayout.SetFixedHeight( 3,mCurrentStyle->titleBottomMargin );
163   mTitleLayout.SetFixedHeight( 2,mCurrentStyle->subtitleHeight );
164
165   mTitleIconLayout.SetFixedWidth( 0, mCurrentStyle->titleIconSize );
166   mTitleIconLayout.SetFixedHeight( 1, mCurrentStyle->titleIconSize );
167 }
168
169 } // namespace Internal
170
171 } // namespace Toolkit
172
173 } // namespace Dali