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>
29 enum ControlDepthIndexRanges
31 BACKGROUND_DEPTH_INDEX = -10000000,
32 CONTENT_DEPTH_INDEX = 0,
33 DECORATION_DEPTH_INDEX = 10000000
37 * Provide a style for the view and its tool bar.
41 ViewStyle( float toolBarButtonPercentage, float toolBarTitlePercentage, float toolBarHeight, float toolBarPadding )
42 : mToolBarButtonPercentage( toolBarButtonPercentage ),
43 mToolBarTitlePercentage( toolBarTitlePercentage ),
44 mToolBarHeight( toolBarHeight ),
45 mToolBarPadding( toolBarPadding )
48 float mToolBarButtonPercentage; ///< The tool bar button width is a percentage of the tool bar width.
49 float mToolBarTitlePercentage; ///< The tool bar title width is a percentage of the tool bar width.
50 float mToolBarHeight; ///< The tool bar height (in pixels).
51 float mToolBarPadding; ///< The tool bar padding (in pixels)..
54 const ViewStyle DEFAULT_VIEW_STYLE( 0.1f, 0.7f, 80.f, 4.f );
56 const char* DEFAULT_TEXT_STYLE_FONT_FAMILY("HelveticaNue");
57 const char* DEFAULT_TEXT_STYLE_FONT_STYLE("Regular");
58 const float DEFAULT_TEXT_STYLE_POINT_SIZE( 8.0f );
60 const Dali::Toolkit::Alignment::Padding DEFAULT_PLAY_PADDING(12.0f, 12.0f, 12.0f, 12.0f);
61 const Dali::Toolkit::Alignment::Padding DEFAULT_MODE_SWITCH_PADDING(8.0f, 8.0f, 8.0f, 8.0f);
63 float ScalePointSize(int pointSize)
65 Dali::Vector2 dpi = Dali::Stage::GetCurrent().GetDpi();
66 float meanDpi = (dpi.height + dpi.width) * 0.5f;
67 return pointSize * 220.0f / meanDpi; // 220 is the default horizontal DPI defined in adaptor Application
70 Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar,
71 const std::string& toolbarImagePath,
72 const std::string& title,
73 const ViewStyle& style )
75 Dali::Stage stage = Dali::Stage::GetCurrent();
77 Dali::Layer toolBarLayer = Dali::Layer::New();
78 toolBarLayer.SetName( "TOOLBAR_LAYER" );
79 toolBarLayer.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
80 toolBarLayer.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
81 toolBarLayer.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::WIDTH );
82 toolBarLayer.SetSize( 0.0f, style.mToolBarHeight );
84 // Raise tool bar layer to the top.
85 toolBarLayer.RaiseToTop();
88 Dali::Image image = Dali::ResourceImage::New( toolbarImagePath );
89 toolBar = Dali::Toolkit::ToolBar::New();
90 toolBar.SetName( "TOOLBAR" );
91 toolBar.SetBackgroundImage( image );
92 toolBar.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
93 toolBar.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
94 toolBar.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
96 // Add the tool bar to the too bar layer.
97 toolBarLayer.Add( toolBar );
102 Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New();
103 label.SetAnchorPoint( Dali::AnchorPoint::TOP_LEFT );
104 label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "toolbarlabel" );
105 label.SetProperty( Dali::Toolkit::TextLabel::Property::TEXT, title );
106 label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
107 label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
108 label.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT );
110 // Add title to the tool bar.
111 const float padding( style.mToolBarPadding );
112 toolBar.AddControl( label, style.mToolBarTitlePercentage, Dali::Toolkit::Alignment::HorizontalCenter, Dali::Toolkit::Alignment::Padding( padding, padding, padding, padding ) );
118 Dali::Layer CreateView( Dali::Application& application,
119 Dali::Toolkit::Control& view,
120 Dali::Toolkit::ToolBar& toolBar,
121 const std::string& backgroundImagePath,
122 const std::string& toolbarImagePath,
123 const std::string& title,
124 const ViewStyle& style = DEFAULT_VIEW_STYLE )
126 Dali::Stage stage = Dali::Stage::GetCurrent();
128 // Create default View.
129 view = Dali::Toolkit::Control::New();
130 view.SetAnchorPoint( Dali::AnchorPoint::CENTER );
131 view.SetParentOrigin( Dali::ParentOrigin::CENTER );
132 view.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
134 // Add the view to the stage before setting the background.
137 // Set background image, loading it at screen resolution:
138 if ( !backgroundImagePath.empty() )
140 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 );
141 view.SetBackgroundImage( backgroundImage );
145 // Connects the orientation signal with the View::OrientationChanged method.
146 //application.GetOrientation().ChangedSignal().Connect( &view, &Dali::Toolkit::View::OrientationChanged );
148 // Create default ToolBar
149 Dali::Layer toolBarLayer = CreateToolbar( toolBar, toolbarImagePath, title, style );
151 // Add tool bar layer to the view.
152 view.Add( toolBarLayer );
154 // Create a content layer.
155 Dali::Layer contentLayer = Dali::Layer::New();
156 contentLayer.SetAnchorPoint( Dali::AnchorPoint::CENTER );
157 contentLayer.SetParentOrigin( Dali::ParentOrigin::CENTER );
158 contentLayer.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
159 view.Add( contentLayer );
160 contentLayer.LowerBelow( toolBarLayer );
165 Dali::Toolkit::TextLabel CreateToolBarLabel( const std::string& text )
167 Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New( text );
168 label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "toolbarlabel" );
169 label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
170 label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
171 label.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT );
178 #endif // __DALI_DEMO_HELPER_VIEW_H__