2 * Copyright (c) 2020 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/text-controls/text-label-devel.h>
27 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
28 #include <dali-toolkit/dali-toolkit.h>
32 #include "shared/multi-language-strings.h"
33 #include "shared/view.h"
34 #include "expanding-buttons.h"
37 using namespace Dali::Toolkit;
38 using namespace MultiLanguageStrings;
42 const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "grab-handle.png";
43 const char* const STYLE_SELECTED_IMAGE = DEMO_IMAGE_DIR "FontStyleButton_OK_03.png";
45 const char* BUTTON_IMAGES[] =
47 DEMO_IMAGE_DIR "FontStyleButton_Colour.png",
48 DEMO_IMAGE_DIR "FontStyleButton_Outline.png",
49 DEMO_IMAGE_DIR "FontStyleButton_Shadow.png",
50 DEMO_IMAGE_DIR "FontStyleButton_Background.png"
53 const unsigned int KEY_ZERO = 10;
54 const unsigned int KEY_ONE = 11;
55 const unsigned int KEY_A = 38;
56 const unsigned int KEY_F = 41;
57 const unsigned int KEY_H = 43;
58 const unsigned int KEY_U = 30;
59 const unsigned int KEY_V = 55;
60 const unsigned int KEY_M = 58;
61 const unsigned int KEY_L = 46;
62 const unsigned int KEY_S = 39;
63 const unsigned int KEY_PLUS = 21;
64 const unsigned int KEY_MINUS = 20;
66 const char* H_ALIGNMENT_STRING_TABLE[] =
73 const unsigned int H_ALIGNMENT_STRING_COUNT = sizeof( H_ALIGNMENT_STRING_TABLE ) / sizeof( H_ALIGNMENT_STRING_TABLE[0u] );
75 const char* V_ALIGNMENT_STRING_TABLE[] =
82 const unsigned int V_ALIGNMENT_STRING_COUNT = sizeof( V_ALIGNMENT_STRING_TABLE ) / sizeof( V_ALIGNMENT_STRING_TABLE[0u] );
93 const Vector4 AVAILABLE_COLORS[] =
99 Color::WHITE // Used as clear
102 const unsigned int NUMBER_OF_COLORS = sizeof( AVAILABLE_COLORS ) / sizeof( AVAILABLE_COLORS[0u] );
104 int ConvertToEven(int value)
106 return (value % 2 == 0) ? value : (value + 1);
109 struct HSVColorConstraint
111 HSVColorConstraint(float hue, float saturation, float value)
113 saturation(saturation),
118 void operator()(Vector3& current, const PropertyInputContainer& inputs )
120 current = hsv2rgb(Vector3(inputs[0]->GetFloat(), saturation, value));
123 Vector3 hsv2rgb(Vector3 colorHSV)
125 float r=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x)-1));
126 float g=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x-2.09439)-1));
127 float b=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x+2.09439)-1));
128 return Vector3(r, g, b);
135 const float STYLE_BUTTON_POSTION_RELATIVE_TO_WINDOW = 0.9f;
136 const float BUTTON_SIZE_RATIO_TO_WINDOW = 0.1f;
137 const float OUTLINE_WIDTH = 2.0f;
138 const Vector2 SHADOW_OFFSET = Vector2( 2.0f, 2.0f );
139 const int GAP_BETWEEN_BUTTONS = 3;
142 } // anonymous namespace
145 * @brief The main class of the demo.
147 class TextLabelExample : public ConnectionTracker
151 TextLabelExample( Application& application )
152 : mApplication( application ),
154 mSelectedColor(AVAILABLE_COLORS[0]),
155 mStyleActivatedForColor( NUMBER_OF_STYLES ),
159 mPanGestureDetector(),
163 mHueAngleIndex( Property::INVALID_INDEX ),
164 mOverrideMixColorIndex( Property::INVALID_INDEX ),
165 mColorButtonsHidden( true ),
166 mCollapseColorsAndStyles( false )
168 // Connect to the Application's Init signal
169 mApplication.InitSignal().Connect( this, &TextLabelExample::Create );
171 // Set Style flags to inactive
172 for ( unsigned int i = TEXT_COLOR; i < NUMBER_OF_STYLES; i++ )
174 mStyleActiveState[ i ] = false;
175 mCurrentStyleColor[i] = AVAILABLE_COLORS[ NUMBER_OF_COLORS - 1 ];
181 // Nothing to do here.
184 // Clicking the expanding button shows the registered style buttons.
185 void SetUpExpandingStyleButtons( Vector2 position )
187 mExpandingButtons = Demo::ExpandingButtons::New();
188 mExpandingButtons.SetProperty( Actor::Property::POSITION, Vector2( mButtonSize.width, mWindowSize.height * STYLE_BUTTON_POSTION_RELATIVE_TO_WINDOW ));
189 mExpandingButtons.CollapsingSignal().Connect( this, &TextLabelExample::OnExpandingButtonCollapsing );
190 mExpandingButtons.SetProperty( Actor::Property::SIZE, mButtonSize );
191 // Creates the buttons to be expanded
192 CreateStyleButtons();
194 // Register the created buttons with the ExpandingButtons.
195 for ( unsigned int index = 0; index < NUMBER_OF_STYLES; index++ )
197 mExpandingButtons.RegisterButton( mStyleButtons[index] );
202 * One-time setup in response to Application InitSignal.
204 void Create( Application& application )
206 Window window = application.GetWindow();
208 window.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent);
209 mWindowSize = window.GetSize();
210 mButtonSize = Size( mWindowSize.height * 0.1, mWindowSize.height * 0.1 ); // Button size 1/10 of window height
212 mContainer = Control::New();
213 mContainer.SetProperty( Dali::Actor::Property::NAME, "Container" );
214 mContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
215 mLayoutSize = Vector2(mWindowSize.width*0.6f, mWindowSize.width*0.6f);
216 mContainer.SetProperty( Actor::Property::SIZE, mLayoutSize );
217 window.Add( mContainer );
219 // Resize the center layout when the corner is grabbed
220 mGrabCorner = ImageView::New( BACKGROUND_IMAGE );
221 mGrabCorner.SetProperty( Dali::Actor::Property::NAME, "GrabCorner" );
222 mGrabCorner.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
223 mGrabCorner.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT );
224 mGrabCorner.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
225 mContainer.Add( mGrabCorner );
227 mPanGestureDetector = PanGestureDetector::New();
228 mPanGestureDetector.Attach( mGrabCorner );
229 mPanGestureDetector.DetectedSignal().Connect( this, &TextLabelExample::OnPan );
231 mLabel = TextLabel::New( "\xF0\x9F\x98\x89 A Quick Brown Fox Jumps Over The Lazy Dog" );
233 mLabel.SetProperty( Dali::Actor::Property::NAME, "TextLabel" );
234 mLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
235 mLabel.SetProperty( Actor::Property::SIZE, mLayoutSize );
236 mLabel.SetProperty( TextLabel::Property::MULTI_LINE, true );
237 mLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::GREEN );
238 mLabel.SetBackgroundColor( Color::WHITE );
239 mContainer.Add( mLabel );
241 // Clicking ExpandingButton shows the Registered Style buttons, clicking again hides them.
242 Vector2 expandingButtonPosition( mButtonSize.width, mWindowSize.height * STYLE_BUTTON_POSTION_RELATIVE_TO_WINDOW );
243 SetUpExpandingStyleButtons( expandingButtonPosition );
244 window.Add( mExpandingButtons );
246 // Add a border for the container so you can see the container is being resized while grabbing the handle.
247 mBorder = Control::New();
248 mBorder.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
249 mBorder.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
250 mBorder.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
252 Dali::Property::Map border;
253 border.Insert( Toolkit::Visual::Property::TYPE, Visual::BORDER );
254 border.Insert( BorderVisual::Property::COLOR, Color::WHITE );
255 border.Insert( BorderVisual::Property::SIZE, 3.f );
256 mBorder.SetProperty( Control::Property::BACKGROUND, border );
257 mContainer.Add( mBorder );
258 mBorder.SetProperty( Actor::Property::VISIBLE,false);
259 mGrabCorner.RaiseToTop();
261 mHueAngleIndex = mLabel.RegisterProperty( "hue", 0.0f );
262 Renderer bgRenderer = mLabel.GetRendererAt(0);
263 mOverrideMixColorIndex = bgRenderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR );
265 Constraint constraint = Constraint::New<Vector3>( bgRenderer, mOverrideMixColorIndex, HSVColorConstraint(0.0f, 0.5f, 0.8f));
266 constraint.AddSource( Source( mLabel, mHueAngleIndex ) );
267 constraint.SetRemoveAction( Constraint::Discard );
270 Animation anim = Animation::New(50.0f);
271 anim.AnimateTo(Property(mLabel, mHueAngleIndex), 6.28318f);
272 anim.SetLooping(true);
275 mContainer.RaiseToTop();
276 mGrabCorner.RaiseToTop();
278 Property::Value labelText = mLabel.GetProperty( TextLabel::Property::TEXT );
279 std::cout << "Displaying text: \"" << labelText.Get< std::string >() << "\"" << std::endl;
282 // If the styling buttons should colapse (hide) then the color buttons should also hide.
283 bool OnExpandingButtonCollapsing( Demo::ExpandingButtons button )
285 mCollapseColorsAndStyles = true;
290 // Get the style type from the given button
291 StyleType GetStyleTypeFromButton( Toolkit::Button button )
293 StyleType style = StyleType::TEXT_COLOR;
295 if( button == mStyleButtons[ StyleType::OUTLINE ] )
297 style = StyleType::OUTLINE;
299 else if( button == mStyleButtons[ StyleType::SHADOW ] )
301 style = StyleType::SHADOW;
303 else if( button == mStyleButtons[ StyleType::BACKGROUND ] )
305 style = StyleType::BACKGROUND;
310 // Style selected, show color buttons
311 bool OnStyleButtonClicked( Toolkit::Button button )
313 StyleType selectedStyle = GetStyleTypeFromButton( button );
314 if ( mStyleActivatedForColor == selectedStyle )
320 ResetColorButtons( mColorButtons, NUMBER_OF_COLORS );
321 ShowColorButtons( selectedStyle);
326 // Set style to selected color
327 bool OnColorSelected( Toolkit::Button button )
329 for( unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
331 if ( mColorButtons[index] == button )
333 mSelectedColor = AVAILABLE_COLORS[ index ];
337 switch ( mStyleActivatedForColor )
341 Animation animation = Animation::New( 1.f );
342 animation.AnimateTo( Property( mLabel, TextLabel::Property::TEXT_COLOR ), mSelectedColor, AlphaFunction::LINEAR );
343 mCurrentStyleColor[ TEXT_COLOR ] = mSelectedColor;
349 Property::Map outlineMap;
350 float outlineWidth = OUTLINE_WIDTH;
352 if( mStyleActiveState[ OUTLINE ] )
354 outlineWidth = ( Color::WHITE == mSelectedColor ) ? 0.0f : OUTLINE_WIDTH ; // toggles outline on/off
356 mStyleActiveState[ OUTLINE ] = ( outlineWidth > 0.0f ) ? true : false;
358 outlineMap["color"] = mSelectedColor;
359 outlineMap["width"] = outlineWidth;
360 mCurrentStyleColor[ OUTLINE ] = mSelectedColor;
361 mLabel.SetProperty( TextLabel::Property::OUTLINE, outlineMap );
366 Vector2 shadowOffset( SHADOW_OFFSET ); // Will be set to zeros if color already set
367 Property::Value value = mLabel.GetProperty( TextLabel::Property::SHADOW );
368 Vector4 currentShadowColor;
369 value.Get( currentShadowColor );
371 if ( mStyleActiveState[ SHADOW ] )
373 // toggle shadow off ( zero offset ) if color is already set
374 shadowOffset = ( Color::WHITE == mSelectedColor ) ? Vector2::ZERO : Vector2( SHADOW_OFFSET );
377 mStyleActiveState[ SHADOW ] = ( shadowOffset == Vector2::ZERO ) ? false : true;
378 mCurrentStyleColor[ SHADOW ] = mSelectedColor;
380 Property::Map shadowMap;
381 shadowMap.Insert( "offset", shadowOffset );
382 shadowMap.Insert( "color", mSelectedColor );
383 mLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap );
389 Property::Map backgroundMap;
390 auto backgroundEnabled(true);
392 if( mStyleActiveState[ BACKGROUND ] )
394 backgroundEnabled = ( Color::WHITE != mSelectedColor ); // toggles background on/off
396 mStyleActiveState[ BACKGROUND ] = backgroundEnabled;
398 backgroundMap["color"] = mSelectedColor;
399 backgroundMap["enable"] = backgroundEnabled;
400 mCurrentStyleColor[ BACKGROUND ] = mSelectedColor;
401 mLabel.SetProperty( DevelTextLabel::Property::BACKGROUND, backgroundMap );
412 // Set the inital color button that should be be selected.
413 // If the style already has a color set then that should be used
414 void SetInitialSelectedColorButton( StyleType styleButtonIndex )
416 Vector4 selectedColor = mCurrentStyleColor[ styleButtonIndex ];
418 for ( unsigned int i = 0; i < NUMBER_OF_COLORS; i++ )
420 if ( AVAILABLE_COLORS[i] == selectedColor )
422 if ( mColorButtons[i] )
424 mColorButtons[ i ].SetProperty( Toolkit::Button::Property::SELECTED, true );
431 // Create a bar of color buttons that the user can select.
432 void ShowColorButtons( StyleType styleButtonIndex )
434 mCollapseColorsAndStyles = false; // Request to show colors so reset flag
435 mStyleActivatedForColor = styleButtonIndex;
437 for( unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
439 if( !mColorButtonsAnimation )
441 mColorButtonsAnimation = Animation::New( 0.15f );
442 mColorButtonsAnimation.FinishedSignal().Connect( this, &TextLabelExample::OnColorButtonAnimationFinished );
445 // Create a color button
446 if ( ! mColorButtons[index] )
448 mColorButtons[index] = RadioButton::New();
449 mColorButtons[index].SetProperty( Actor::Property::SIZE, mButtonSize );
450 mColorButtons[index].ClickedSignal().Connect( this, &TextLabelExample::OnColorSelected );
451 mColorButtons[index].SetProperty( Button::Property::TOGGLABLE, true );
452 Property::Map propertyMap;
453 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
454 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, AVAILABLE_COLORS[ index ]);
455 mColorButtons[index].SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap );
456 mColorButtons[index].SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, propertyMap );
457 mColorButtons[index].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
458 mColorButtons[index].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER );
461 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
462 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, AVAILABLE_COLORS[ index ]);
463 mColorButtons[index].SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, propertyMap );
465 mColorButtons[index].SetProperty( Toolkit::Button::Property::SELECTED_VISUAL,
466 Property::Map().Add( Visual::Property::TYPE, Visual::BORDER )
467 .Add( BorderVisual::Property::COLOR, Color::WHITE )
468 .Add( BorderVisual::Property::SIZE, 4.0f )
469 .Add( BorderVisual::Property::ANTI_ALIASING, true ) );
471 // Use a white button with 50% transparency as a clear color button
472 if ( Color::WHITE == AVAILABLE_COLORS[ index ] && styleButtonIndex != StyleType::TEXT_COLOR )
474 mColorButtons[index].SetProperty( Actor::Property::OPACITY,0.5f);
476 mColorButtons[index].SetProperty( Toolkit::Button::Property::LABEL,
477 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
478 .Add( Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER )
479 .Add( Toolkit::TextVisual::Property::TEXT, "off") );
484 SetInitialSelectedColorButton( mStyleActivatedForColor );
486 mColorButtons[index].Unparent();
488 mStyleButtons[styleButtonIndex].Add( mColorButtons[index] );
489 mColorButtons[index].Lower();
491 // Position button using nice animation
492 mColorButtons[index].SetProperty( Actor::Property::POSITION_Y, -GAP_BETWEEN_BUTTONS );
493 float desiredPosition = -( mButtonSize.height + GAP_BETWEEN_BUTTONS ) * (index);
494 AlphaFunction focusedAlphaFunction = AlphaFunction( Vector2 ( 0.32f, 0.08f ), Vector2( 0.38f, 1.72f ) );
495 mColorButtonsAnimation.AnimateBy( Property( mColorButtons[index], Actor::Property::POSITION_Y ), desiredPosition, focusedAlphaFunction );
498 mColorButtonsHidden = false;
499 mColorButtonsAnimation.Play();
502 // Remove the color buttons when not being shown.
503 void ResetColorButtons( Button buttons[], unsigned int numberOfButtons )
505 for( unsigned int index = 0; index < numberOfButtons; index++)
507 UnparentAndReset( buttons[index] );
511 void OnColorButtonAnimationFinished( Animation& animation )
514 if ( mColorButtonsHidden )
516 ResetColorButtons( mColorButtons, NUMBER_OF_COLORS );
517 animation.Reset(); // Handle reset
518 if ( mCollapseColorsAndStyles )
520 mExpandingButtons.Collapse();
525 // Create the style buttons that will expand from the expanding button.
526 void CreateStyleButtons()
528 for ( unsigned int index = 0; index < NUMBER_OF_STYLES; index++ )
530 if ( ! mStyleButtons[index] )
532 mStyleButtons[index] = PushButton::New();
533 mStyleButtons[index].SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_IMAGES[ index ] );
534 mStyleButtons[index].SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, STYLE_SELECTED_IMAGE );
535 mStyleButtons[index].SetProperty( Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
536 mStyleButtons[index].SetProperty( Actor::Property::SIZE, mButtonSize );
537 mStyleButtons[index].ClickedSignal().Connect( this, &TextLabelExample::OnStyleButtonClicked );
542 // Animate away the color bar.
543 void HideColorButtons()
545 if ( ! mColorButtonsHidden )
547 for( unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
549 mColorButtonsAnimation.AnimateTo( Property( mColorButtons[index], Actor::Property::POSITION_Y ), 0.0f );
551 mColorButtonsHidden = true;
552 mColorButtonsAnimation.Play();
554 mStyleActivatedForColor = NUMBER_OF_STYLES;
557 // Request the expanding button to collapse.
558 void HideStyleAndColorButtons()
560 mCollapseColorsAndStyles = true;
561 if ( mColorButtonsHidden )
563 mExpandingButtons.Collapse();
571 // Resize the text-label with pan gesture
572 void OnPan( Actor actor, const PanGesture& gesture )
574 // Reset mLayoutSize when the pan starts
575 if( gesture.state == Gesture::Started )
577 if( mLayoutSize.x < 2.0f )
579 mLayoutSize.x = 2.0f;
582 if( mLayoutSize.y < 2.0f )
584 mLayoutSize.y = 2.0f;
587 // Only show the border during the panning
588 mBorder.SetProperty( Actor::Property::VISIBLE,true);
590 HideStyleAndColorButtons();
593 mLayoutSize.x += gesture.displacement.x * 2.0f;
594 mLayoutSize.y += gesture.displacement.y * 2.0f;
596 if( mLayoutSize.x >= 2.0f ||
597 mLayoutSize.y >= 2.0f )
599 mLayoutSize.x = std::min ( mLayoutSize.x, mWindowSize.width );
600 mLayoutSize.y = std::min ( mLayoutSize.y, mWindowSize.height*.9f );
602 // Avoid pixel mis-alignment issue
603 Vector2 clampedSize = Vector2( std::max( ConvertToEven( static_cast<int>( mLayoutSize.x )), 2 ),
604 std::max( ConvertToEven( static_cast<int>( mLayoutSize.y )), 2 ) );
606 mContainer.SetProperty( Actor::Property::SIZE, clampedSize );
609 if( gesture.state == Gesture::Cancelled || gesture.state == Gesture::Finished )
611 // Resize the text label to match the container size when panning is finished
612 mLabel.SetProperty( Actor::Property::SIZE, mLayoutSize );
613 mBorder.SetProperty( Actor::Property::VISIBLE,false);
618 * Main key event handler
620 void OnKeyEvent(const KeyEvent& event)
622 if(event.GetState() == KeyEvent::DOWN)
624 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
628 else if( event.IsCtrlModifier() )
630 switch( event.GetKeyCode() )
632 // Select rendering back-end
633 case KEY_ZERO: // fall through
636 mLabel.SetProperty( DevelTextLabel::Property::RENDERING_BACKEND, event.GetKeyCode() - 10 );
639 case KEY_A: // Animate text colour
641 Animation animation = Animation::New( 2.f );
642 animation.AnimateTo( Property( mLabel, TextLabel::Property::TEXT_COLOR ), Color::RED, AlphaFunction::SIN );
643 animation.SetLoopCount( 3 );
647 case KEY_F: // Fill vertically
649 if( ResizePolicy::DIMENSION_DEPENDENCY == mLabel.GetResizePolicy(Dimension::HEIGHT) )
651 mLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
655 mLabel.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
659 case KEY_H: // Horizontal alignment
661 if( ++mAlignment >= H_ALIGNMENT_STRING_COUNT )
666 mLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, H_ALIGNMENT_STRING_TABLE[ mAlignment ] );
669 case KEY_V: // Vertical alignment
671 if( ++mAlignment >= V_ALIGNMENT_STRING_COUNT )
676 mLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, V_ALIGNMENT_STRING_TABLE[ mAlignment ] );
679 case KEY_M: // Multi-line
681 bool multiLine = mLabel.GetProperty<bool>( TextLabel::Property::MULTI_LINE );
682 mLabel.SetProperty( TextLabel::Property::MULTI_LINE, !multiLine );
685 case KEY_L: // Language
687 const Language& language = LANGUAGES[ mLanguageId ];
689 mLabel.SetProperty( TextLabel::Property::TEXT, language.text );
691 if( ++mLanguageId >= NUMBER_OF_LANGUAGES )
697 case KEY_S: // Shadow color
699 Property::Value value = mLabel.GetProperty( TextLabel::Property::SHADOW );
701 value.Get( shadowColor );
702 Property::Map shadowMap;
703 if( Color::BLACK == shadowColor )
705 shadowMap.Insert( "color", Color::RED );
706 mLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap );
710 shadowMap.Insert( "color", Color::BLACK );
711 mLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap );
715 case KEY_U: // Markup
717 mLabel.SetProperty( TextLabel::Property::ENABLE_MARKUP, true );
718 mLabel.SetProperty( TextLabel::Property::TEXT, "<font family='DejaVuSerif' size='18'>H<color value='blue'>ello</color> <font weight='bold'>world</font> demo</font>" );
721 case KEY_PLUS: // Increase shadow offset
723 Property::Value value = mLabel.GetProperty( TextLabel::Property::SHADOW );
724 Vector2 shadowOffset;
725 value.Get( shadowOffset );
726 shadowOffset += Vector2( 1.0f, 1.0f );
728 Property::Map shadowMap;
729 shadowMap.Insert( "offset", shadowOffset );
730 mLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap );
733 case KEY_MINUS: // Decrease shadow offset
735 Property::Value value = mLabel.GetProperty( TextLabel::Property::SHADOW );
736 Vector2 shadowOffset;
737 value.Get( shadowOffset );
738 shadowOffset -= Vector2( 1.0f, 1.0f );
740 Property::Map shadowMap;
741 shadowMap.Insert( "offset", shadowOffset );
742 mLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap );
753 Application& mApplication;
757 Demo::ExpandingButtons mExpandingButtons;
758 PushButton mStyleButtons[ NUMBER_OF_STYLES ];
759 bool mStyleActiveState[ NUMBER_OF_STYLES ];
761 Vector4 mCurrentStyleColor[NUMBER_OF_STYLES ];
763 Vector4 mSelectedColor;
765 Button mColorButtons[ NUMBER_OF_COLORS ];
767 StyleType mStyleActivatedForColor; // The style that the color bar is connected to
773 PanGestureDetector mPanGestureDetector;
777 Animation mColorButtonsAnimation;
782 unsigned int mLanguageId;
783 unsigned int mAlignment;
784 Property::Index mHueAngleIndex;
785 Property::Index mOverrideMixColorIndex;
787 bool mColorButtonsHidden;
788 bool mCollapseColorsAndStyles;
791 int DALI_EXPORT_API main( int argc, char **argv )
793 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
794 TextLabelExample test( application );
795 application.MainLoop();