2 * Copyright (c) 2015 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.
19 * @file text-fonts-example.cpp
20 * @brief Example of various TextLabel each with different font set ups,
21 * enables Testing of Font when the system font changes.
22 The first label is free, with no font family set, it could use the default system font and change as it changes.
23 The second label has it's font family set via the demo json file. It should not change when the system font changes.
24 The third label has it's font family set in code via SetProperty. It also should not change when the system font changes.
25 The forth label is not shown until the button along the bottom is pressed, it has no font set so the newly created label should use the system font,
26 Pressing the button again resets and unparents that button and then re-adds it.
30 #include <dali-toolkit/dali-toolkit.h>
34 #include "shared/multi-language-strings.h"
35 #include "shared/view.h"
38 using namespace Dali::Toolkit;
39 using namespace MultiLanguageStrings;
43 const char* const LABEL_TEXT = "A Quick Fox";
44 const char* const LABEL_TEXT_MIXED = "Fox 구미호";
45 const char* const LABEL_TEXT_KOREAN = "구미호";
49 * @brief The main class of the demo.
51 class TextFontsExample : public ConnectionTracker
55 TextFontsExample( Application& application )
56 : mApplication( application ),
59 // Connect to the Application's Init signal
60 mApplication.InitSignal().Connect( this, &TextFontsExample::Create );
65 // Nothing to do here.
68 void CreateTextLabel( TextLabel& textLabel, std::string textString, const Vector4& color, bool infoLabel=false )
70 textLabel = TextLabel::New( textString );
71 textLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT );
72 textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
73 textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
74 textLabel.SetProperty( TextLabel::Property::MULTI_LINE, true );
77 textLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE );
78 textLabel.SetProperty( TextLabel::Property::POINT_SIZE, 12.0f );
79 textLabel.SetProperty( TextLabel::Property::FONT_FAMILY, "SamsungOneUI" );
83 textLabel.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 0.3f, 0.3f ) );
84 textLabel.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::BLACK );
85 textLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE );
87 textLabel.SetBackgroundColor( color );
90 void CreateContainer( Control& container, const Vector2 size )
92 container = Control::New();
93 container.SetSize( size );
94 container.SetAnchorPoint( AnchorPoint::TOP_LEFT );
95 container.SetDrawMode( DrawMode::OVERLAY_2D );
98 void CreateFolderButton( PushButton& button )
100 button = PushButton::New();
101 button.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
102 button.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
103 button.SetSize( 50.0f, 50.0f );
106 bool OnButtonClicked( Toolkit::Button button )
110 UnparentAndReset( mLabel4 );
115 CreateContainer ( mContainer4 , mLayoutSize);
116 Stage stage = Stage::GetCurrent();
117 Vector2 stageSize = stage.GetSize();
118 mContainer4.SetPosition( 0, stageSize.height*0.25f*3 );
119 stage.Add( mContainer4 );
121 CreateContainer ( mContainer4Info , mLayoutSize );
122 mContainer4Info.SetParentOrigin( ParentOrigin::TOP_RIGHT );
123 mContainer4.Add( mContainer4Info );
124 CreateTextLabel ( mLabel4Info, "system free", Color::BLACK, true );
125 mContainer4Info.Add ( mLabel4Info );
130 CreateTextLabel ( mLabel4, LABEL_TEXT_KOREAN, Color::WHITE );
135 CreateTextLabel ( mLabel4, LABEL_TEXT_MIXED, Color::WHITE );
139 mContainer4.Add( mLabel4 );
145 * One-time setup in response to Application InitSignal.
147 void Create( Application& application )
149 Stage stage = Stage::GetCurrent();
150 Vector2 stageSize = stage.GetSize();
152 stage.KeyEventSignal().Connect(this, &TextFontsExample::OnKeyEvent);
154 CreateFolderButton ( mButton );
155 mButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
156 mButton.ClickedSignal().Connect( this, &TextFontsExample::OnButtonClicked );
157 stage.Add( mButton );
159 mLayoutSize = Vector2( stageSize.width*0.5f, stageSize.height*0.10f );
160 CreateContainer ( mContainer , mLayoutSize);
161 CreateContainer ( mContainer2 , mLayoutSize );
162 CreateContainer ( mContainer3 , mLayoutSize );
164 // Info about Text Label and if font should be fixed or free to change with system
165 CreateContainer ( mContainerInfo , mLayoutSize );
166 CreateContainer ( mContainer2Info , mLayoutSize );
167 CreateContainer ( mContainer3Info , mLayoutSize );
168 mContainerInfo.SetParentOrigin( ParentOrigin::TOP_RIGHT );
169 mContainer2Info.SetParentOrigin( ParentOrigin::TOP_RIGHT );
170 mContainer3Info.SetParentOrigin( ParentOrigin::TOP_RIGHT );
171 mContainer.Add( mContainerInfo );
172 mContainer2.Add( mContainer2Info );
173 mContainer3.Add( mContainer3Info );
174 CreateTextLabel ( mLabelInfo, "system free", Color::BLACK, true );
175 CreateTextLabel ( mLabel2Info, "json fixed", Color::BLACK, true );
176 CreateTextLabel ( mLabel3Info, "SetProp fixed", Color::BLACK, true );
177 mContainerInfo.Add( mLabelInfo );
178 mContainer2Info.Add( mLabel2Info );
179 mContainer3Info.Add( mLabel3Info );
181 stage.Add( mContainer );
182 stage.Add( mContainer2 );
183 stage.Add( mContainer3 );
185 CreateTextLabel ( mLabel, LABEL_TEXT, Color::WHITE );
187 CreateTextLabel ( mLabel2, LABEL_TEXT, Color::WHITE );
188 mLabel2.SetStyleName("textlabel-Rosemary");
190 CreateTextLabel ( mLabel3, LABEL_TEXT, Color::WHITE );
191 mLabel3.SetProperty( TextLabel::Property::FONT_FAMILY, "SamsungOneUI" );
193 mContainer.SetPosition( 0, 0 );
194 mContainer2.SetPosition( 0, stageSize.height*0.25f );
195 mContainer3.SetPosition( 0, stageSize.height*0.25f*2 );
197 mContainer.Add( mLabel );
198 mContainer2.Add( mLabel2 );
199 mContainer3.Add( mLabel3 );
203 * Main key event handler
205 void OnKeyEvent(const KeyEvent& event)
207 if(event.state == KeyEvent::Down)
209 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
218 Application& mApplication;
233 Control mContainerInfo;
234 Control mContainer2Info;
235 Control mContainer3Info;
236 Control mContainer4Info;
238 TextLabel mLabelInfo;
239 TextLabel mLabel2Info;
240 TextLabel mLabel3Info;
241 TextLabel mLabel4Info;
248 void RunTest( Application& application )
250 TextFontsExample test( application );
252 application.MainLoop();
255 /** Entry point for Linux & Tizen applications */
256 int DALI_EXPORT_API main( int argc, char **argv )
258 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
260 RunTest( application );