1 #ifndef __DALI_DEMO_HELPER_VIEW_H__
2 #define __DALI_DEMO_HELPER_VIEW_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali-toolkit/devel-api/controls/tool-bar/tool-bar.h>
23 #include <dali-toolkit/devel-api/styling/style-manager.h>
30 * Provide a style for the view and its tool bar.
34 ViewStyle( float toolBarButtonPercentage, float toolBarTitlePercentage, float toolBarHeight, float toolBarPadding )
35 : mToolBarButtonPercentage( toolBarButtonPercentage ),
36 mToolBarTitlePercentage( toolBarTitlePercentage ),
37 mToolBarHeight( toolBarHeight ),
38 mToolBarPadding( toolBarPadding )
41 float mToolBarButtonPercentage; ///< The tool bar button width is a percentage of the tool bar width.
42 float mToolBarTitlePercentage; ///< The tool bar title width is a percentage of the tool bar width.
43 float mToolBarHeight; ///< The tool bar height (in pixels).
44 float mToolBarPadding; ///< The tool bar padding (in pixels)..
47 const ViewStyle DEFAULT_VIEW_STYLE( 0.1f, 0.7f, 80.f, 4.f );
49 const char* DEFAULT_TEXT_STYLE_FONT_FAMILY("HelveticaNue");
50 const char* DEFAULT_TEXT_STYLE_FONT_STYLE("Regular");
51 const float DEFAULT_TEXT_STYLE_POINT_SIZE( 8.0f );
53 const Dali::Toolkit::Alignment::Padding DEFAULT_PLAY_PADDING(12.0f, 12.0f, 12.0f, 12.0f);
54 const Dali::Toolkit::Alignment::Padding DEFAULT_MODE_SWITCH_PADDING(8.0f, 8.0f, 8.0f, 8.0f);
56 float ScalePointSize(int pointSize)
58 Dali::Vector2 dpi = Dali::Stage::GetCurrent().GetDpi();
59 float meanDpi = (dpi.height + dpi.width) * 0.5f;
60 return pointSize * 220.0f / meanDpi; // 220 is the default horizontal DPI defined in adaptor Application
63 Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar,
64 const std::string& toolbarImagePath,
65 const std::string& title,
66 const ViewStyle& style )
68 Dali::Stage stage = Dali::Stage::GetCurrent();
70 Dali::Layer toolBarLayer = Dali::Layer::New();
71 toolBarLayer.SetName( "TOOLBAR_LAYER" );
72 toolBarLayer.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
73 toolBarLayer.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
74 toolBarLayer.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::WIDTH );
75 toolBarLayer.SetSize( 0.0f, style.mToolBarHeight );
77 // Raise tool bar layer to the top.
78 toolBarLayer.RaiseToTop();
81 Dali::Image image = Dali::ResourceImage::New( toolbarImagePath );
82 toolBar = Dali::Toolkit::ToolBar::New();
83 toolBar.SetName( "TOOLBAR" );
84 toolBar.SetBackgroundImage( image );
85 toolBar.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
86 toolBar.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
87 toolBar.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
89 // Add the tool bar to the too bar layer.
90 toolBarLayer.Add( toolBar );
95 Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New();
96 label.SetAnchorPoint( Dali::AnchorPoint::TOP_LEFT );
97 label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "toolbarlabel" );
98 label.SetProperty( Dali::Toolkit::TextLabel::Property::TEXT, title );
99 label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
100 label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
101 label.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT );
103 // Add title to the tool bar.
104 const float padding( style.mToolBarPadding );
105 toolBar.AddControl( label, style.mToolBarTitlePercentage, Dali::Toolkit::Alignment::HorizontalCenter, Dali::Toolkit::Alignment::Padding( padding, padding, padding, padding ) );
111 Dali::Layer CreateView( Dali::Application& application,
112 Dali::Toolkit::Control& view,
113 Dali::Toolkit::ToolBar& toolBar,
114 const std::string& backgroundImagePath,
115 const std::string& toolbarImagePath,
116 const std::string& title,
117 const ViewStyle& style = DEFAULT_VIEW_STYLE )
119 Dali::Stage stage = Dali::Stage::GetCurrent();
121 // Create default View.
122 view = Dali::Toolkit::Control::New();
123 view.SetAnchorPoint( Dali::AnchorPoint::CENTER );
124 view.SetParentOrigin( Dali::ParentOrigin::CENTER );
125 view.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
127 // Add the view to the stage before setting the background.
130 // Set background image, loading it at screen resolution:
131 if ( !backgroundImagePath.empty() )
133 Dali::Image backgroundImage = Dali::ResourceImage::New( backgroundImagePath, Dali::ImageDimensions( stage.GetSize().x, stage.GetSize().y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR );
134 view.SetBackgroundImage( backgroundImage );
138 // Connects the orientation signal with the View::OrientationChanged method.
139 //application.GetOrientation().ChangedSignal().Connect( &view, &Dali::Toolkit::View::OrientationChanged );
141 // Create default ToolBar
142 Dali::Layer toolBarLayer = CreateToolbar( toolBar, toolbarImagePath, title, style );
144 // Add tool bar layer to the view.
145 view.Add( toolBarLayer );
147 // Create a content layer.
148 Dali::Layer contentLayer = Dali::Layer::New();
149 contentLayer.SetAnchorPoint( Dali::AnchorPoint::CENTER );
150 contentLayer.SetParentOrigin( Dali::ParentOrigin::CENTER );
151 contentLayer.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
152 view.Add( contentLayer );
153 contentLayer.LowerBelow( toolBarLayer );
158 Dali::Toolkit::TextLabel CreateToolBarLabel( const std::string& text )
160 Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New( text );
161 label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "toolbarlabel" );
162 label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
163 label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
164 label.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT );
171 #endif // __DALI_DEMO_HELPER_VIEW_H__