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 "../shared/view.h"
19 #include <dali/dali.h>
20 #include <dali-toolkit/dali-toolkit.h>
27 const char* const BACKGROUND_IMAGE = DALI_IMAGE_DIR "background-gradient.jpg";
28 const char* const TOOLBAR_IMAGE = DALI_IMAGE_DIR "top-bar.png";
30 const char* const TOOLBAR_TITLE = "Text View";
31 const int TOOLBAR_HEIGHT = 80;
33 const int NUM_TABLE_ROWS = 12;
34 const int NUM_TABLE_COLUMNS = 12;
46 unsigned int columnSpan;
52 std::string fontStyle;
54 Dali::TextStyle::Weight fontWeight;
59 Toolkit::Alignment::Type horizontalAlignment;
60 Toolkit::Alignment::Type verticalAlignment;
65 TableCell cellPosition;
70 // Font Font style Font point size Font weight Text colour Text Horizontal alignment Vertical alignment Padding Orientation Table cell position and span
71 const TableString TABLE_STRINGS[] = { { "HelveticaNue", "Regular", 8.0f, Dali::TextStyle::REGULAR, Vector4( 0.5f, 1.0f, 0.0f, 1.0f ), "Howdy", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 0, 0, 2, 4 } },
72 { "HelveticaNue", "Regular", 13.0f, Dali::TextStyle::EXTRABOLD, Vector4( 1.0f, 0.5f, 0.0f, 1.0f ), "Hello!", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 0.0f, { 0, 4, 1, 4 } },
73 { "HelveticaNue", "Regular", 18.0f, Dali::TextStyle::REGULAR, Vector4( 1.0f, 0.75f, 0.25f, 1.0f ), "שלום!", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 1, 4, 1, 4 } },
74 { "HelveticaNue", "Regular", 8.0f, Dali::TextStyle::REGULAR, Vector4( 0.5f, 0.0f, 1.0f, 1.0f ), "Hi there", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalBottom, 10.0f, 0.0f, { 0, 8, 2, 4 } },
75 { "HelveticaNue", "Regular", 12.0f, Dali::TextStyle::REGULAR, Vector4( 0.5f, 1.0f, 1.0f, 1.0f ), "Hola", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 90.0f, { 2, 0, 4, 2 } },
76 { "HelveticaNue", "Regular", 18.0f, Dali::TextStyle::BOLD, Vector4( 0.5f, 1.0f, 0.5f, 1.0f ), "Bonjour", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 2, 2, 2, 4 } },
77 { "HelveticaNue", "Regular", 12.0f, Dali::TextStyle::REGULAR, Vector4( 1.0f, 1.0f, 0.5f, 1.0f ), "Ciao", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 0.0f, { 2, 7, 2, 3 } },
78 { "HelveticaNue", "Regular", 26.0f, Dali::TextStyle::EXTRABLACK, Vector4( 0.5f, 0.0f, 0.0f, 1.0f ), "Hello", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 0.0f, { 4, 2, 1, 6 } },
79 { "HelveticaNue", "Regular", 8.0f, Dali::TextStyle::DEMIBOLD, Vector4( 0.0f, 0.5f, 0.0f, 1.0f ), "Top of the morning to you", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 90.0f, { 4, 10, 8, 2 } },
80 { "HelveticaNue", "Regular", 13.0f, Dali::TextStyle::DEMIBOLD, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ), "हैलो", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 6, 1, 1, 3 } },
81 { "HelveticaNue", "Regular", 8.0f, Dali::TextStyle::DEMIBOLD, Vector4( 1.0f, 1.0f, 0.0f, 1.0f ), "สวัสดี", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 90.0f, { 6, 5, 2, 1 } },
82 { "HelveticaNue", "Regular", 18.0f, Dali::TextStyle::REGULAR, Vector4( 0.0f, 1.0f, 1.0f, 1.0f ), "你好", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalBottom, 10.0f, 0.0f, { 6, 6, 1, 3 } },
83 { "HelveticaNue", "Regular", 34.0f, Dali::TextStyle::REGULAR, Vector4( 0.0f, 0.0f, 1.0f, 1.0f ), "G'day", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 0.0f, { 7, 0, 2, 10 } },
84 { "HelveticaNue", "Regular", 16.0f, Dali::TextStyle::EXTRABLACK, Vector4( 0.0f, 0.5f, 1.0f, 1.0f ), "مرحبا", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 9, 1, 2, 4 } },
85 { "HelveticaNue", "Regular", 10.0f, Dali::TextStyle::EXTRABLACK, Vector4( 1.0f, 0.0f, 0.0f, 1.0f ), "こんにちは", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 0.0f, { 10, 0, 2, 6 } },
86 { "HelveticaNue", "Regular", 14.0f, Dali::TextStyle::REGULAR, Vector4( 0.0f, 1.0f, 0.0f, 1.0f ), "aloha", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 10, 6, 2, 4 } }
89 const int NUM_TABLE_STRINGS = sizeof( TABLE_STRINGS ) / sizeof( TABLE_STRINGS[0] );
94 * This example shows the usage of TextView.
96 class TextViewController: public ConnectionTracker
100 TextViewController( Application& application )
101 : mApplication( application )
103 // Connect to the Application's Init signal
104 mApplication.InitSignal().Connect( this, &TextViewController::Create );
107 ~TextViewController()
109 // Nothing to do here
112 void Create( Application& application )
114 // The Init signal is received once (only) during the Application lifetime
116 Stage stage = Stage::GetCurrent();
118 // Respond to key events
119 stage.KeyEventSignal().Connect(this, &TextViewController::OnKeyEvent);
121 // Creates a default view with a default tool bar.
122 // The view is added to the stage.
123 mContentLayer = DemoHelper::CreateView( application,
130 // Create a table view the height of the stage
131 Toolkit::TableView textContainer = Toolkit::TableView::New( NUM_TABLE_ROWS, NUM_TABLE_COLUMNS );
132 textContainer.SetParentOrigin( ParentOrigin::TOP_LEFT );
133 textContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT );
134 textContainer.SetPosition( 0, TOOLBAR_HEIGHT );
135 textContainer.SetSize( stage.GetSize().width, stage.GetSize().height - TOOLBAR_HEIGHT );
137 mContentLayer.Add( textContainer );
140 for( int i = 0; i < NUM_TABLE_STRINGS; ++i )
142 const TableString& tableString = TABLE_STRINGS[ i ];
144 Dali::TextStyle textStyle;
145 textStyle.SetFontName( tableString.fontName );
146 textStyle.SetFontStyle( tableString.fontStyle );
147 textStyle.SetFontPointSize( Dali::PointSize( DemoHelper::ScalePointSize( tableString.fontSize ) ) );
148 textStyle.SetWeight( tableString.fontWeight );
149 textStyle.SetTextColor( tableString.fontColour );
151 Toolkit::TextView textView = Toolkit::TextView::New( tableString.text );
152 textView.SetStyleToCurrentText( textStyle );
153 textView.SetRotation( Dali::Degree( tableString.orientation ), Vector3( 0.0f, 0.0f, 1.0f ) );
155 Toolkit::Alignment alignmentContainer = Toolkit::Alignment::New( tableString.horizontalAlignment, tableString.verticalAlignment );
156 alignmentContainer.SetPadding( Toolkit::Alignment::Padding( tableString.padding, tableString.padding, tableString.padding, tableString.padding ) );
157 alignmentContainer.SetScaling( Toolkit::Alignment::ScaleToFill );
158 alignmentContainer.Add( textView );
160 textContainer.AddChild( alignmentContainer, Toolkit::TableView::CellPosition( tableString.cellPosition.row, tableString.cellPosition.column, tableString.cellPosition.rowSpan, tableString.cellPosition.columnSpan ) );
164 void OnKeyEvent( const KeyEvent& event )
166 if( event.state == KeyEvent::Down )
168 if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
170 // Exit application when click back or escape.
178 Application& mApplication;
179 Toolkit::View mView; ///< The View instance.
180 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
181 Layer mContentLayer; ///< Content layer
185 void RunTest( Application& application )
187 TextViewController test( application );
189 application.MainLoop();
192 // Entry point for Linux & SLP applications
194 int main( int argc, char **argv )
196 Application application = Application::New( &argc, &argv );
198 RunTest( application );