2 * Copyright (c) 2017 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 Property::Map shadowMap;
84 shadowMap.Insert( "color", Color::BLACK );
85 shadowMap.Insert( "offset", Vector2( 0.3f, 0.3f ) );
86 textLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap );
87 textLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE );
89 textLabel.SetBackgroundColor( color );
92 void CreateContainer( Control& container, const Vector2 size )
94 container = Control::New();
95 container.SetSize( size );
96 container.SetAnchorPoint( AnchorPoint::TOP_LEFT );
97 container.SetDrawMode( DrawMode::OVERLAY_2D );
100 void CreateFolderButton( PushButton& button )
102 button = PushButton::New();
103 button.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
104 button.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
105 button.SetSize( 50.0f, 50.0f );
108 bool OnButtonClicked( Toolkit::Button button )
112 UnparentAndReset( mLabel4 );
117 CreateContainer ( mContainer4 , mLayoutSize);
118 Stage stage = Stage::GetCurrent();
119 Vector2 stageSize = stage.GetSize();
120 mContainer4.SetPosition( 0, stageSize.height*0.25f*3 );
121 stage.Add( mContainer4 );
123 CreateContainer ( mContainer4Info , mLayoutSize );
124 mContainer4Info.SetParentOrigin( ParentOrigin::TOP_RIGHT );
125 mContainer4.Add( mContainer4Info );
126 CreateTextLabel ( mLabel4Info, "system free", Color::BLACK, true );
127 mContainer4Info.Add ( mLabel4Info );
132 CreateTextLabel ( mLabel4, LABEL_TEXT_KOREAN, Color::WHITE );
137 CreateTextLabel ( mLabel4, LABEL_TEXT_MIXED, Color::WHITE );
141 mContainer4.Add( mLabel4 );
147 * One-time setup in response to Application InitSignal.
149 void Create( Application& application )
151 Stage stage = Stage::GetCurrent();
152 Vector2 stageSize = stage.GetSize();
154 stage.KeyEventSignal().Connect(this, &TextFontsExample::OnKeyEvent);
156 CreateFolderButton ( mButton );
157 mButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
158 mButton.ClickedSignal().Connect( this, &TextFontsExample::OnButtonClicked );
159 stage.Add( mButton );
161 mLayoutSize = Vector2( stageSize.width*0.5f, stageSize.height*0.10f );
162 CreateContainer ( mContainer , mLayoutSize);
163 CreateContainer ( mContainer2 , mLayoutSize );
164 CreateContainer ( mContainer3 , mLayoutSize );
166 // Info about Text Label and if font should be fixed or free to change with system
167 CreateContainer ( mContainerInfo , mLayoutSize );
168 CreateContainer ( mContainer2Info , mLayoutSize );
169 CreateContainer ( mContainer3Info , mLayoutSize );
170 mContainerInfo.SetParentOrigin( ParentOrigin::TOP_RIGHT );
171 mContainer2Info.SetParentOrigin( ParentOrigin::TOP_RIGHT );
172 mContainer3Info.SetParentOrigin( ParentOrigin::TOP_RIGHT );
173 mContainer.Add( mContainerInfo );
174 mContainer2.Add( mContainer2Info );
175 mContainer3.Add( mContainer3Info );
176 CreateTextLabel ( mLabelInfo, "system free", Color::BLACK, true );
177 CreateTextLabel ( mLabel2Info, "json fixed", Color::BLACK, true );
178 CreateTextLabel ( mLabel3Info, "SetProp fixed", Color::BLACK, true );
179 mContainerInfo.Add( mLabelInfo );
180 mContainer2Info.Add( mLabel2Info );
181 mContainer3Info.Add( mLabel3Info );
183 stage.Add( mContainer );
184 stage.Add( mContainer2 );
185 stage.Add( mContainer3 );
187 CreateTextLabel ( mLabel, LABEL_TEXT, Color::WHITE );
189 CreateTextLabel ( mLabel2, LABEL_TEXT, Color::WHITE );
190 mLabel2.SetStyleName("TextLabelRosemary");
192 CreateTextLabel ( mLabel3, LABEL_TEXT, Color::WHITE );
193 mLabel3.SetProperty( TextLabel::Property::FONT_FAMILY, "SamsungOneUI" );
195 mContainer.SetPosition( 0, 0 );
196 mContainer2.SetPosition( 0, stageSize.height*0.25f );
197 mContainer3.SetPosition( 0, stageSize.height*0.25f*2 );
199 mContainer.Add( mLabel );
200 mContainer2.Add( mLabel2 );
201 mContainer3.Add( mLabel3 );
205 * Main key event handler
207 void OnKeyEvent(const KeyEvent& event)
209 if(event.state == KeyEvent::Down)
211 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
220 Application& mApplication;
235 Control mContainerInfo;
236 Control mContainer2Info;
237 Control mContainer3Info;
238 Control mContainer4Info;
240 TextLabel mLabelInfo;
241 TextLabel mLabel2Info;
242 TextLabel mLabel3Info;
243 TextLabel mLabel4Info;
250 int DALI_EXPORT_API main( int argc, char **argv )
252 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
253 TextFontsExample test( application );
254 application.MainLoop();