Commit 4a48b0f0e3d8b9e4e0f4f868d07b0091b332ae25

Authored by Agnelo Vaz
1 parent 20196d2d

Text-Font example added

* Added to test Font setting via Property system and system font changes.
* 3 Initial TextLabels;
    first has no font set,
    second is set via the demo json style sheet,
    third is set via the SetProperty in code.
  Only the first should change when the system font changes to a different font
* Pressing button creates a new TextLabel with the system font

Change-Id: I9291797ba357979d9b3d85ab0d3a30a3fbd6c497
Signed-off-by: Agnelo Vaz <agnelo.vaz@samsung.com>
com.samsung.dali-demo.xml
... ... @@ -88,6 +88,9 @@
88 88 <ui-application appid="text-field.example" exec="/usr/apps/com.samsung.dali-demo/bin/text-field.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
89 89 <label>Text Field</label>
90 90 </ui-application>
  91 + <ui-application appid="text-fonts.example" exec="/usr/apps/com.samsung.dali-demo/bin/text-fonts.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
  92 + <label>Text Fonts</label>
  93 + </ui-application>
91 94 <ui-application appid="text-message-field.example" exec="/usr/apps/com.samsung.dali-demo/bin/text-message-field.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
92 95 <label>Text Label</label>
93 96 </ui-application>
... ...
examples/text-fonts/text-fonts-example.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015 Samsung Electronics Co., Ltd.
  3 + *
  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
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  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.
  15 + *
  16 + */
  17 +
  18 +/**
  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.
  27 + */
  28 +
  29 +// EXTERNAL INCLUDES
  30 +#include <dali-toolkit/dali-toolkit.h>
  31 +#include <iostream>
  32 +
  33 +// INTERNAL INCLUDES
  34 +#include "shared/multi-language-strings.h"
  35 +#include "shared/view.h"
  36 +
  37 +using namespace Dali;
  38 +using namespace Dali::Toolkit;
  39 +using namespace MultiLanguageStrings;
  40 +
  41 +namespace
  42 +{
  43 + const char* const LABEL_TEXT = "A Quick Fox";
  44 + const char* const LABEL_TEXT_MIXED = "Fox 구미호";
  45 + const char* const LABEL_TEXT_KOREAN = "구미호";
  46 +}
  47 +
  48 +/**
  49 + * @brief The main class of the demo.
  50 + */
  51 +class TextFontsExample : public ConnectionTracker
  52 +{
  53 +public:
  54 +
  55 + TextFontsExample( Application& application )
  56 + : mApplication( application ),
  57 + mToggle(true)
  58 + {
  59 + // Connect to the Application's Init signal
  60 + mApplication.InitSignal().Connect( this, &TextFontsExample::Create );
  61 + }
  62 +
  63 + ~TextFontsExample()
  64 + {
  65 + // Nothing to do here.
  66 + }
  67 +
  68 + void CreateTextLabel( TextLabel& textLabel, std::string textString, const Vector4& color, bool infoLabel=false )
  69 + {
  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 );
  75 + if ( infoLabel )
  76 + {
  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" );
  80 + }
  81 + else
  82 + {
  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 );
  86 + }
  87 + textLabel.SetBackgroundColor( color );
  88 + }
  89 +
  90 + void CreateContainer( Control& container, const Vector2 size )
  91 + {
  92 + container = Control::New();
  93 + container.SetSize( size );
  94 + container.SetAnchorPoint( AnchorPoint::TOP_LEFT );
  95 + container.SetDrawMode( DrawMode::OVERLAY_2D );
  96 + }
  97 +
  98 + void CreateFolderButton( PushButton& button )
  99 + {
  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 );
  104 + }
  105 +
  106 + bool OnButtonClicked( Toolkit::Button button )
  107 + {
  108 + if ( mLabel4 )
  109 + {
  110 + UnparentAndReset( mLabel4 );
  111 + }
  112 +
  113 + if ( !mContainer4 )
  114 + {
  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 );
  120 + // Info
  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 );
  126 + }
  127 +
  128 + if ( mToggle )
  129 + {
  130 + CreateTextLabel ( mLabel4, LABEL_TEXT_KOREAN, Color::WHITE );
  131 + mToggle = false;
  132 + }
  133 + else
  134 + {
  135 + CreateTextLabel ( mLabel4, LABEL_TEXT_MIXED, Color::WHITE );
  136 + mToggle = true;
  137 + }
  138 +
  139 + mContainer4.Add( mLabel4 );
  140 +
  141 + return true;
  142 + }
  143 +
  144 + /**
  145 + * One-time setup in response to Application InitSignal.
  146 + */
  147 + void Create( Application& application )
  148 + {
  149 + Stage stage = Stage::GetCurrent();
  150 + Vector2 stageSize = stage.GetSize();
  151 +
  152 + stage.KeyEventSignal().Connect(this, &TextFontsExample::OnKeyEvent);
  153 +
  154 + CreateFolderButton ( mButton );
  155 + mButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
  156 + mButton.ClickedSignal().Connect( this, &TextFontsExample::OnButtonClicked );
  157 + stage.Add( mButton );
  158 +
  159 + mLayoutSize = Vector2( stageSize.width*0.5f, stageSize.height*0.10f );
  160 + CreateContainer ( mContainer , mLayoutSize);
  161 + CreateContainer ( mContainer2 , mLayoutSize );
  162 + CreateContainer ( mContainer3 , mLayoutSize );
  163 +
  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 );
  180 +
  181 + stage.Add( mContainer );
  182 + stage.Add( mContainer2 );
  183 + stage.Add( mContainer3 );
  184 +
  185 + CreateTextLabel ( mLabel, LABEL_TEXT, Color::WHITE );
  186 +
  187 + CreateTextLabel ( mLabel2, LABEL_TEXT, Color::WHITE );
  188 + mLabel2.SetStyleName("textlabel-Rosemary");
  189 +
  190 + CreateTextLabel ( mLabel3, LABEL_TEXT, Color::WHITE );
  191 + mLabel3.SetProperty( TextLabel::Property::FONT_FAMILY, "SamsungOneUI" );
  192 +
  193 + mContainer.SetPosition( 0, 0 );
  194 + mContainer2.SetPosition( 0, stageSize.height*0.25f );
  195 + mContainer3.SetPosition( 0, stageSize.height*0.25f*2 );
  196 +
  197 + mContainer.Add( mLabel );
  198 + mContainer2.Add( mLabel2 );
  199 + mContainer3.Add( mLabel3 );
  200 + }
  201 +
  202 + /**
  203 + * Main key event handler
  204 + */
  205 + void OnKeyEvent(const KeyEvent& event)
  206 + {
  207 + if(event.state == KeyEvent::Down)
  208 + {
  209 + if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
  210 + {
  211 + mApplication.Quit();
  212 + }
  213 + }
  214 + }
  215 +
  216 +private:
  217 +
  218 + Application& mApplication;
  219 +
  220 + PushButton mButton;
  221 +
  222 + TextLabel mLabel;
  223 + TextLabel mLabel2;
  224 + TextLabel mLabel3;
  225 +
  226 + TextLabel mLabel4;
  227 +
  228 + Control mContainer;
  229 + Control mContainer2;
  230 + Control mContainer3;
  231 + Control mContainer4;
  232 +
  233 + Control mContainerInfo;
  234 + Control mContainer2Info;
  235 + Control mContainer3Info;
  236 + Control mContainer4Info;
  237 +
  238 + TextLabel mLabelInfo;
  239 + TextLabel mLabel2Info;
  240 + TextLabel mLabel3Info;
  241 + TextLabel mLabel4Info;
  242 +
  243 + Vector2 mLayoutSize;
  244 +
  245 + bool mToggle;
  246 +};
  247 +
  248 +void RunTest( Application& application )
  249 +{
  250 + TextFontsExample test( application );
  251 +
  252 + application.MainLoop();
  253 +}
  254 +
  255 +/** Entry point for Linux & Tizen applications */
  256 +int main( int argc, char **argv )
  257 +{
  258 + Application application = Application::New( &argc, &argv, DALI_DEMO_THEME_PATH );
  259 +
  260 + RunTest( application );
  261 +
  262 + return 0;
  263 +}
... ...
resources/style/demo-theme.json
... ... @@ -22,13 +22,15 @@ distributing this software or its derivatives.
22 22 {
23 23 "styles":
24 24 {
  25 + "textlabel-Rosemary":
  26 + {
  27 + "font-family":"Rosemary"
  28 + },
25 29 "textlabel":
26 30 {
27   - "font-family":"HelveticaNeue",
28 31 "font-style":"Regular",
29 32 "point-size":18
30 33 },
31   -
32 34 "launcherlabel":
33 35 {
34 36 "point-size":18
... ...
resources/style/mobile/demo-theme.json
... ... @@ -22,13 +22,15 @@ distributing this software or its derivatives.
22 22 {
23 23 "styles":
24 24 {
  25 + "textlabel-Rosemary":
  26 + {
  27 + "font-family":"Rosemary"
  28 + },
25 29 "textlabel":
26 30 {
27   - "font-family":"SamsungSans",
28 31 "font-style":"Regular",
29 32 "point-size":18
30 33 },
31   -
32 34 "textlabel-font-size-0":
33 35 {
34 36 "point-size":8
... ...