2 * Copyright (c) 2018 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-label-example.cpp
20 * @brief Usage of TextLabel control with style application.
24 #include <dali/devel-api/object/handle-devel.h>
25 #include <dali/devel-api/actors/actor-devel.h>
26 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
27 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
28 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
29 #include <dali-toolkit/dali-toolkit.h>
33 #include "shared/multi-language-strings.h"
34 #include "shared/view.h"
35 #include "expanding-buttons.h"
38 using namespace Dali::Toolkit;
39 using namespace MultiLanguageStrings;
43 const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "grab-handle.png";
44 const char* const STYLE_SELECTED_IMAGE = DEMO_IMAGE_DIR "FontStyleButton_OK_03.png";
46 const char* BUTTON_IMAGES[] =
48 DEMO_IMAGE_DIR "FontStyleButton_Colour.png",
49 DEMO_IMAGE_DIR "FontStyleButton_Outline.png",
50 DEMO_IMAGE_DIR "FontStyleButton_Shadow.png",
51 DEMO_IMAGE_DIR "FontStyleButton_Background.png"
54 const unsigned int KEY_ZERO = 10;
55 const unsigned int KEY_ONE = 11;
56 const unsigned int KEY_A = 38;
57 const unsigned int KEY_F = 41;
58 const unsigned int KEY_H = 43;
59 const unsigned int KEY_U = 30;
60 const unsigned int KEY_V = 55;
61 const unsigned int KEY_M = 58;
62 const unsigned int KEY_L = 46;
63 const unsigned int KEY_S = 39;
64 const unsigned int KEY_PLUS = 21;
65 const unsigned int KEY_MINUS = 20;
67 const char* H_ALIGNMENT_STRING_TABLE[] =
74 const unsigned int H_ALIGNMENT_STRING_COUNT = sizeof( H_ALIGNMENT_STRING_TABLE ) / sizeof( H_ALIGNMENT_STRING_TABLE[0u] );
76 const char* V_ALIGNMENT_STRING_TABLE[] =
83 const unsigned int V_ALIGNMENT_STRING_COUNT = sizeof( V_ALIGNMENT_STRING_TABLE ) / sizeof( V_ALIGNMENT_STRING_TABLE[0u] );
94 const Vector4 AVAILABLE_COLORS[] =
100 Color::WHITE // Used as clear
103 const unsigned int NUMBER_OF_COLORS = sizeof( AVAILABLE_COLORS ) / sizeof( AVAILABLE_COLORS[0u] );
105 int ConvertToEven(int value)
107 return (value % 2 == 0) ? value : (value + 1);
110 struct HSVColorConstraint
112 HSVColorConstraint(float hue, float saturation, float value)
114 saturation(saturation),
119 void operator()(Vector3& current, const PropertyInputContainer& inputs )
121 current = hsv2rgb(Vector3(inputs[0]->GetFloat(), saturation, value));
124 Vector3 hsv2rgb(Vector3 colorHSV)
126 float r=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x)-1));
127 float g=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x-2.09439)-1));
128 float b=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x+2.09439)-1));
129 return Vector3(r, g, b);
136 const float STYLE_BUTTON_POSTION_RELATIVE_TO_STAGE = 0.9f;
137 const float BUTTON_SIZE_RATIO_TO_STAGE = 0.1f;
138 const float OUTLINE_WIDTH = 2.0f;
139 const Vector2 SHADOW_OFFSET = Vector2( 2.0f, 2.0f );
140 const int GAP_BETWEEN_BUTTONS = 3;
143 } // anonymous namespace
146 * @brief The main class of the demo.
148 class TextLabelExample : public ConnectionTracker
152 TextLabelExample( Application& application )
153 : mApplication( application ),
155 mSelectedColor(AVAILABLE_COLORS[0]),
156 mStyleActivatedForColor( NUMBER_OF_STYLES ),
160 mPanGestureDetector(),
164 mHueAngleIndex( Property::INVALID_INDEX ),
165 mOverrideMixColorIndex( Property::INVALID_INDEX ),
166 mColorButtonsHidden( true ),
167 mCollapseColorsAndStyles( false )
169 // Connect to the Application's Init signal
170 mApplication.InitSignal().Connect( this, &TextLabelExample::Create );
172 // Set Style flags to inactive
173 for ( unsigned int i = TEXT_COLOR; i < NUMBER_OF_STYLES; i++ )
175 mStyleActiveState[ i ] = false;
176 mCurrentStyleColor[i] = AVAILABLE_COLORS[ NUMBER_OF_COLORS - 1 ];
182 // Nothing to do here.
185 // Clicking the expanding button shows the registered style buttons.
186 void SetUpExpandingStyleButtons( Vector2 position )
188 mExpandingButtons = Demo::ExpandingButtons::New();
189 mExpandingButtons.SetPosition( mButtonSize.width, mStageSize.height * STYLE_BUTTON_POSTION_RELATIVE_TO_STAGE );
190 mExpandingButtons.CollapsingSignal().Connect( this, &TextLabelExample::OnExpandingButtonCollapsing );
191 mExpandingButtons.SetSize( mButtonSize );
192 // Creates the buttons to be expanded
193 CreateStyleButtons();
195 // Register the created buttons with the ExpandingButtons.
196 for ( unsigned int index = 0; index < NUMBER_OF_STYLES; index++ )
198 mExpandingButtons.RegisterButton( mStyleButtons[index] );
203 * One-time setup in response to Application InitSignal.
205 void Create( Application& application )
207 Stage stage = Stage::GetCurrent();
209 stage.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent);
210 mStageSize = stage.GetSize();
211 mButtonSize = Size( mStageSize.height * 0.1, mStageSize.height * 0.1 ); // Button size 1/10 of stage height
213 mContainer = Control::New();
214 mContainer.SetName( "Container" );
215 mContainer.SetParentOrigin( ParentOrigin::CENTER );
216 mLayoutSize = Vector2(mStageSize.width*0.6f, mStageSize.width*0.6f);
217 mContainer.SetSize( mLayoutSize );
218 stage.Add( mContainer );
220 // Resize the center layout when the corner is grabbed
221 mGrabCorner = ImageView::New( BACKGROUND_IMAGE );
222 mGrabCorner.SetName( "GrabCorner" );
223 mGrabCorner.SetAnchorPoint( AnchorPoint::TOP_CENTER );
224 mGrabCorner.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT );
225 mGrabCorner.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
226 mContainer.Add( mGrabCorner );
228 mPanGestureDetector = PanGestureDetector::New();
229 mPanGestureDetector.Attach( mGrabCorner );
230 mPanGestureDetector.DetectedSignal().Connect( this, &TextLabelExample::OnPan );
232 mLabel = TextLabel::New( "\xF0\x9F\x98\x89 A Quick Brown Fox Jumps Over The Lazy Dog" );
234 mLabel.SetName( "TextLabel" );
235 mLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT );
236 mLabel.SetSize(mLayoutSize);
237 mLabel.SetProperty( TextLabel::Property::MULTI_LINE, true );
238 mLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::GREEN );
239 mLabel.SetBackgroundColor( Color::WHITE );
240 mContainer.Add( mLabel );
242 // Clicking ExpandingButton shows the Registered Style buttons, clicking again hides them.
243 Vector2 expandingButtonPosition( mButtonSize.width, mStageSize.height * STYLE_BUTTON_POSTION_RELATIVE_TO_STAGE );
244 SetUpExpandingStyleButtons( expandingButtonPosition );
245 stage.Add( mExpandingButtons );
247 // Add a border for the container so you can see the container is being resized while grabbing the handle.
248 mBorder = Control::New();
249 mBorder.SetAnchorPoint( AnchorPoint::TOP_LEFT );
250 mBorder.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
251 mBorder.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
253 Dali::Property::Map border;
254 border.Insert( Toolkit::Visual::Property::TYPE, Visual::BORDER );
255 border.Insert( BorderVisual::Property::COLOR, Color::WHITE );
256 border.Insert( BorderVisual::Property::SIZE, 3.f );
257 mBorder.SetProperty( Control::Property::BACKGROUND, border );
258 mContainer.Add( mBorder );
259 mBorder.SetVisible(false);
260 mGrabCorner.RaiseToTop();
262 mHueAngleIndex = mLabel.RegisterProperty( "hue", 0.0f );
263 Renderer bgRenderer = mLabel.GetRendererAt(0);
264 mOverrideMixColorIndex = DevelHandle::GetPropertyIndex( bgRenderer, ColorVisual::Property::MIX_COLOR );
266 Constraint constraint = Constraint::New<Vector3>( bgRenderer, mOverrideMixColorIndex, HSVColorConstraint(0.0f, 0.5f, 0.8f));
267 constraint.AddSource( Source( mLabel, mHueAngleIndex ) );
268 constraint.SetRemoveAction( Constraint::Discard );
271 Animation anim = Animation::New(50.0f);
272 anim.AnimateTo(Property(mLabel, mHueAngleIndex), 6.28318f);
273 anim.SetLooping(true);
276 mContainer.RaiseToTop();
277 mGrabCorner.RaiseToTop();
279 Property::Value labelText = mLabel.GetProperty( TextLabel::Property::TEXT );
280 std::cout << "Displaying text: \"" << labelText.Get< std::string >() << "\"" << std::endl;
283 // If the styling buttons should colapse (hide) then the color buttons should also hide.
284 bool OnExpandingButtonCollapsing( Demo::ExpandingButtons button )
286 mCollapseColorsAndStyles = true;
291 // Get the style type from the given button
292 StyleType GetStyleTypeFromButton( Toolkit::Button button )
294 StyleType style = StyleType::TEXT_COLOR;
296 if( button == mStyleButtons[ StyleType::OUTLINE ] )
298 style = StyleType::OUTLINE;
300 else if( button == mStyleButtons[ StyleType::SHADOW ] )
302 style = StyleType::SHADOW;
304 else if( button == mStyleButtons[ StyleType::BACKGROUND ] )
306 style = StyleType::BACKGROUND;
311 // Style selected, show color buttons
312 bool OnStyleButtonClicked( Toolkit::Button button )
314 StyleType selectedStyle = GetStyleTypeFromButton( button );
315 if ( mStyleActivatedForColor == selectedStyle )
321 ResetColorButtons( mColorButtons, NUMBER_OF_COLORS );
322 ShowColorButtons( selectedStyle);
327 // Set style to selected color
328 bool OnColorSelected( Toolkit::Button button )
330 for( unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
332 if ( mColorButtons[index] == button )
334 mSelectedColor = AVAILABLE_COLORS[ index ];
338 switch ( mStyleActivatedForColor )
342 Animation animation = Animation::New( 1.f );
343 animation.AnimateTo( Property( mLabel, TextLabel::Property::TEXT_COLOR ), mSelectedColor, AlphaFunction::LINEAR );
344 mCurrentStyleColor[ TEXT_COLOR ] = mSelectedColor;
350 Property::Map outlineMap;
351 float outlineWidth = OUTLINE_WIDTH;
353 if( mStyleActiveState[ OUTLINE ] )
355 outlineWidth = ( Color::WHITE == mSelectedColor ) ? 0.0f : OUTLINE_WIDTH ; // toggles outline on/off
357 mStyleActiveState[ OUTLINE ] = ( outlineWidth > 0.0f ) ? true : false;
359 outlineMap["color"] = mSelectedColor;
360 outlineMap["width"] = outlineWidth;
361 mCurrentStyleColor[ OUTLINE ] = mSelectedColor;
362 mLabel.SetProperty( TextLabel::Property::OUTLINE, outlineMap );
367 Vector2 shadowOffset( SHADOW_OFFSET ); // Will be set to zeros if color already set
368 Property::Value value = mLabel.GetProperty( TextLabel::Property::SHADOW );
369 Vector4 currentShadowColor;
370 value.Get( currentShadowColor );
372 if ( mStyleActiveState[ SHADOW ] )
374 // toggle shadow off ( zero offset ) if color is already set
375 shadowOffset = ( Color::WHITE == mSelectedColor ) ? Vector2::ZERO : Vector2( SHADOW_OFFSET );
378 mStyleActiveState[ SHADOW ] = ( shadowOffset == Vector2::ZERO ) ? false : true;
379 mCurrentStyleColor[ SHADOW ] = mSelectedColor;
381 Property::Map shadowMap;
382 shadowMap.Insert( "offset", shadowOffset );
383 shadowMap.Insert( "color", mSelectedColor );
384 mLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap );
390 Property::Map backgroundMap;
391 auto backgroundEnabled(true);
393 if( mStyleActiveState[ BACKGROUND ] )
395 backgroundEnabled = ( Color::WHITE != mSelectedColor ); // toggles background on/off
397 mStyleActiveState[ BACKGROUND ] = backgroundEnabled;
399 backgroundMap["color"] = mSelectedColor;
400 backgroundMap["enable"] = backgroundEnabled;
401 mCurrentStyleColor[ BACKGROUND ] = mSelectedColor;
402 mLabel.SetProperty( DevelTextLabel::Property::BACKGROUND, backgroundMap );
413 // Set the inital color button that should be be selected.
414 // If the style already has a color set then that should be used
415 void SetInitialSelectedColorButton( StyleType styleButtonIndex )
417 Vector4 selectedColor = mCurrentStyleColor[ styleButtonIndex ];
419 for ( unsigned int i = 0; i < NUMBER_OF_COLORS; i++ )
421 if ( AVAILABLE_COLORS[i] == selectedColor )
423 if ( mColorButtons[i] )
425 mColorButtons[ i ].SetProperty( Toolkit::DevelButton::Property::SELECTED, true );
432 // Create a bar of color buttons that the user can select.
433 void ShowColorButtons( StyleType styleButtonIndex )
435 mCollapseColorsAndStyles = false; // Request to show colors so reset flag
436 mStyleActivatedForColor = styleButtonIndex;
438 for( unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
440 if( !mColorButtonsAnimation )
442 mColorButtonsAnimation = Animation::New( 0.15f );
443 mColorButtonsAnimation.FinishedSignal().Connect( this, &TextLabelExample::OnColorButtonAnimationFinished );
446 // Create a color button
447 if ( ! mColorButtons[index] )
449 mColorButtons[index] = RadioButton::New();
450 mColorButtons[index].SetSize( mButtonSize );
451 mColorButtons[index].ClickedSignal().Connect( this, &TextLabelExample::OnColorSelected );
452 mColorButtons[index].SetProperty( Button::Property::TOGGLABLE, true );
453 Property::Map propertyMap;
454 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
455 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, AVAILABLE_COLORS[ index ]);
456 mColorButtons[index].SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap );
457 mColorButtons[index].SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, propertyMap );
458 mColorButtons[index].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
459 mColorButtons[index].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER );
462 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
463 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, AVAILABLE_COLORS[ index ]);
464 mColorButtons[index].SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, propertyMap );
466 mColorButtons[index].SetProperty( Toolkit::DevelButton::Property::SELECTED_VISUAL,
467 Property::Map().Add( Visual::Property::TYPE, Visual::BORDER )
468 .Add( BorderVisual::Property::COLOR, Color::WHITE )
469 .Add( BorderVisual::Property::SIZE, 4.0f )
470 .Add( BorderVisual::Property::ANTI_ALIASING, true ) );
472 // Use a white button with 50% transparency as a clear color button
473 if ( Color::WHITE == AVAILABLE_COLORS[ index ] && styleButtonIndex != StyleType::TEXT_COLOR )
475 mColorButtons[index].SetOpacity(0.5f);
477 mColorButtons[index].SetProperty( Toolkit::Button::Property::LABEL,
478 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
479 .Add( Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER )
480 .Add( Toolkit::TextVisual::Property::TEXT, "off") );
485 SetInitialSelectedColorButton( mStyleActivatedForColor );
487 mColorButtons[index].Unparent();
489 mStyleButtons[styleButtonIndex].Add( mColorButtons[index] );
490 mColorButtons[index].Lower();
492 // Position button using nice animation
493 mColorButtons[index].SetY( -GAP_BETWEEN_BUTTONS );
494 float desiredPosition = -( mButtonSize.height + GAP_BETWEEN_BUTTONS ) * (index);
495 AlphaFunction focusedAlphaFunction = AlphaFunction( Vector2 ( 0.32f, 0.08f ), Vector2( 0.38f, 1.72f ) );
496 mColorButtonsAnimation.AnimateBy( Property( mColorButtons[index], Actor::Property::POSITION_Y ), desiredPosition, focusedAlphaFunction );
499 mColorButtonsHidden = false;
500 mColorButtonsAnimation.Play();
503 // Remove the color buttons when not being shown.
504 void ResetColorButtons( Button buttons[], unsigned int numberOfButtons )
506 for( unsigned int index = 0; index < numberOfButtons; index++)
508 UnparentAndReset( buttons[index] );
512 void OnColorButtonAnimationFinished( Animation& animation )
515 if ( mColorButtonsHidden )
517 ResetColorButtons( mColorButtons, NUMBER_OF_COLORS );
518 animation.Reset(); // Handle reset
519 if ( mCollapseColorsAndStyles )
521 mExpandingButtons.Collapse();
526 // Create the style buttons that will expand from the expanding button.
527 void CreateStyleButtons()
529 for ( unsigned int index = 0; index < NUMBER_OF_STYLES; index++ )
531 if ( ! mStyleButtons[index] )
533 mStyleButtons[index] = PushButton::New();
534 mStyleButtons[index].SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_IMAGES[ index ] );
535 mStyleButtons[index].SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, STYLE_SELECTED_IMAGE );
536 mStyleButtons[index].SetProperty( Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
537 mStyleButtons[index].SetSize( mButtonSize );
538 mStyleButtons[index].ClickedSignal().Connect( this, &TextLabelExample::OnStyleButtonClicked );
543 // Animate away the color bar.
544 void HideColorButtons()
546 if ( ! mColorButtonsHidden )
548 for( unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
550 mColorButtonsAnimation.AnimateTo( Property( mColorButtons[index], Actor::Property::POSITION_Y ), 0.0f );
552 mColorButtonsHidden = true;
553 mColorButtonsAnimation.Play();
555 mStyleActivatedForColor = NUMBER_OF_STYLES;
558 // Request the expanding button to collapse.
559 void HideStyleAndColorButtons()
561 mCollapseColorsAndStyles = true;
562 if ( mColorButtonsHidden )
564 mExpandingButtons.Collapse();
572 // Resize the text-label with pan gesture
573 void OnPan( Actor actor, const PanGesture& gesture )
575 // Reset mLayoutSize when the pan starts
576 if( gesture.state == Gesture::Started )
578 if( mLayoutSize.x < 2.0f )
580 mLayoutSize.x = 2.0f;
583 if( mLayoutSize.y < 2.0f )
585 mLayoutSize.y = 2.0f;
588 // Only show the border during the panning
589 mBorder.SetVisible(true);
591 HideStyleAndColorButtons();
594 mLayoutSize.x += gesture.displacement.x * 2.0f;
595 mLayoutSize.y += gesture.displacement.y * 2.0f;
597 if( mLayoutSize.x >= 2.0f ||
598 mLayoutSize.y >= 2.0f )
600 mLayoutSize.x = std::min ( mLayoutSize.x, mStageSize.width );
601 mLayoutSize.y = std::min ( mLayoutSize.y, mStageSize.height*.9f );
603 // Avoid pixel mis-alignment issue
604 Vector2 clampedSize = Vector2( std::max( ConvertToEven( static_cast<int>( mLayoutSize.x )), 2 ),
605 std::max( ConvertToEven( static_cast<int>( mLayoutSize.y )), 2 ) );
607 mContainer.SetSize( clampedSize );
610 if( gesture.state == Gesture::Cancelled || gesture.state == Gesture::Finished )
612 // Resize the text label to match the container size when panning is finished
613 mLabel.SetSize(mLayoutSize);
614 mBorder.SetVisible(false);
619 * Main key event handler
621 void OnKeyEvent(const KeyEvent& event)
623 if(event.state == KeyEvent::Down)
625 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
629 else if( event.IsCtrlModifier() )
631 switch( event.keyCode )
633 // Select rendering back-end
634 case KEY_ZERO: // fall through
637 mLabel.SetProperty( TextLabel::Property::RENDERING_BACKEND, event.keyCode - 10 );
640 case KEY_A: // Animate text colour
642 Animation animation = Animation::New( 2.f );
643 animation.AnimateTo( Property( mLabel, TextLabel::Property::TEXT_COLOR ), Color::RED, AlphaFunction::SIN );
644 animation.SetLoopCount( 3 );
648 case KEY_F: // Fill vertically
650 if( ResizePolicy::DIMENSION_DEPENDENCY == mLabel.GetResizePolicy(Dimension::HEIGHT) )
652 mLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
656 mLabel.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
660 case KEY_H: // Horizontal alignment
662 if( ++mAlignment >= H_ALIGNMENT_STRING_COUNT )
667 mLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, H_ALIGNMENT_STRING_TABLE[ mAlignment ] );
670 case KEY_V: // Vertical alignment
672 if( ++mAlignment >= V_ALIGNMENT_STRING_COUNT )
677 mLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, V_ALIGNMENT_STRING_TABLE[ mAlignment ] );
680 case KEY_M: // Multi-line
682 bool multiLine = mLabel.GetProperty<bool>( TextLabel::Property::MULTI_LINE );
683 mLabel.SetProperty( TextLabel::Property::MULTI_LINE, !multiLine );
686 case KEY_L: // Language
688 const Language& language = LANGUAGES[ mLanguageId ];
690 mLabel.SetProperty( TextLabel::Property::TEXT, language.text );
692 if( ++mLanguageId >= NUMBER_OF_LANGUAGES )
698 case KEY_S: // Shadow color
700 Property::Value value = mLabel.GetProperty( TextLabel::Property::SHADOW );
702 value.Get( shadowColor );
703 Property::Map shadowMap;
704 if( Color::BLACK == shadowColor )
706 shadowMap.Insert( "color", Color::RED );
707 mLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap );
711 shadowMap.Insert( "color", Color::BLACK );
712 mLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap );
716 case KEY_U: // Markup
718 mLabel.SetProperty( TextLabel::Property::ENABLE_MARKUP, true );
719 mLabel.SetProperty( TextLabel::Property::TEXT, "<font family='DejaVuSerif' size='18'>H<color value='blue'>ello</color> <font weight='bold'>world</font> demo</font>" );
722 case KEY_PLUS: // Increase shadow offset
724 Property::Value value = mLabel.GetProperty( TextLabel::Property::SHADOW );
725 Vector2 shadowOffset;
726 value.Get( shadowOffset );
727 shadowOffset += Vector2( 1.0f, 1.0f );
729 Property::Map shadowMap;
730 shadowMap.Insert( "offset", shadowOffset );
731 mLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap );
734 case KEY_MINUS: // Decrease shadow offset
736 Property::Value value = mLabel.GetProperty( TextLabel::Property::SHADOW );
737 Vector2 shadowOffset;
738 value.Get( shadowOffset );
739 shadowOffset -= Vector2( 1.0f, 1.0f );
741 Property::Map shadowMap;
742 shadowMap.Insert( "offset", shadowOffset );
743 mLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap );
754 Application& mApplication;
758 Demo::ExpandingButtons mExpandingButtons;
759 PushButton mStyleButtons[ NUMBER_OF_STYLES ];
760 bool mStyleActiveState[ NUMBER_OF_STYLES ];
762 Vector4 mCurrentStyleColor[NUMBER_OF_STYLES ];
764 Vector4 mSelectedColor;
766 Button mColorButtons[ NUMBER_OF_COLORS ];
768 StyleType mStyleActivatedForColor; // The style that the color bar is connected to
774 PanGestureDetector mPanGestureDetector;
778 Animation mColorButtonsAnimation;
783 unsigned int mLanguageId;
784 unsigned int mAlignment;
785 Property::Index mHueAngleIndex;
786 Property::Index mOverrideMixColorIndex;
788 bool mColorButtonsHidden;
789 bool mCollapseColorsAndStyles;
792 int DALI_EXPORT_API main( int argc, char **argv )
794 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
795 TextLabelExample test( application );
796 application.MainLoop();