2 * Copyright (c) 2022 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-toolkit/dali-toolkit.h>
25 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
26 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
27 #include <dali/devel-api/actors/actor-devel.h>
28 #include <dali/devel-api/object/handle-devel.h>
32 #include "expanding-buttons.h"
33 #include "shared/multi-language-strings.h"
34 #include "shared/view.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"};
52 const unsigned int KEY_ZERO = 10;
53 const unsigned int KEY_ONE = 11;
54 const unsigned int KEY_A = 38;
55 const unsigned int KEY_F = 41;
56 const unsigned int KEY_H = 43;
57 const unsigned int KEY_U = 30;
58 const unsigned int KEY_V = 55;
59 const unsigned int KEY_M = 58;
60 const unsigned int KEY_L = 46;
61 const unsigned int KEY_S = 39;
62 const unsigned int KEY_PLUS = 21;
63 const unsigned int KEY_MINUS = 20;
65 const char* H_ALIGNMENT_STRING_TABLE[] =
71 const unsigned int H_ALIGNMENT_STRING_COUNT = sizeof(H_ALIGNMENT_STRING_TABLE) / sizeof(H_ALIGNMENT_STRING_TABLE[0u]);
73 const char* V_ALIGNMENT_STRING_TABLE[] =
79 const unsigned int V_ALIGNMENT_STRING_COUNT = sizeof(V_ALIGNMENT_STRING_TABLE) / sizeof(V_ALIGNMENT_STRING_TABLE[0u]);
90 const Vector4 AVAILABLE_COLORS[] =
96 Color::WHITE // Used as clear
99 const unsigned int NUMBER_OF_COLORS = sizeof(AVAILABLE_COLORS) / sizeof(AVAILABLE_COLORS[0u]);
101 int ConvertToEven(int value)
103 return (value % 2 == 0) ? value : (value + 1);
106 struct HSVColorConstraint
108 HSVColorConstraint(float hueParam, float saturationParam, float valueParam)
110 saturation(saturationParam),
115 void operator()(Vector3& current, const PropertyInputContainer& inputs)
117 current = hsv2rgb(Vector3(inputs[0]->GetFloat(), saturation, value));
120 Vector3 hsv2rgb(Vector3 colorHSV)
122 float r = colorHSV.z * (1 + colorHSV.y * (cos(colorHSV.x) - 1));
123 float g = colorHSV.z * (1 + colorHSV.y * (cos(colorHSV.x - 2.09439) - 1));
124 float b = colorHSV.z * (1 + colorHSV.y * (cos(colorHSV.x + 2.09439) - 1));
125 return Vector3(r, g, b);
132 const float STYLE_BUTTON_POSTION_RELATIVE_TO_WINDOW = 0.9f;
133 const float BUTTON_SIZE_RATIO_TO_WINDOW = 0.1f;
134 const float OUTLINE_WIDTH = 2.0f;
135 const Vector2 SHADOW_OFFSET = Vector2(2.0f, 2.0f);
136 const int GAP_BETWEEN_BUTTONS = 3;
138 } // anonymous namespace
141 * @brief The main class of the demo.
143 class TextLabelExample : public ConnectionTracker
146 TextLabelExample(Application& application)
147 : mApplication(application),
149 mSelectedColor(AVAILABLE_COLORS[0]),
150 mStyleActivatedForColor(NUMBER_OF_STYLES),
154 mPanGestureDetector(),
158 mHueAngleIndex(Property::INVALID_INDEX),
159 mOverrideMixColorIndex(Property::INVALID_INDEX),
160 mColorButtonsHidden(true),
161 mCollapseColorsAndStyles(false)
163 // Connect to the Application's Init signal
164 mApplication.InitSignal().Connect(this, &TextLabelExample::Create);
166 // Set Style flags to inactive
167 for(unsigned int i = TEXT_COLOR; i < NUMBER_OF_STYLES; i++)
169 mStyleActiveState[i] = false;
170 mCurrentStyleColor[i] = AVAILABLE_COLORS[NUMBER_OF_COLORS - 1];
176 // Nothing to do here.
179 // Clicking the expanding button shows the registered style buttons.
180 void SetUpExpandingStyleButtons(Vector2 position)
182 mExpandingButtons = Demo::ExpandingButtons::New();
183 mExpandingButtons.SetProperty(Actor::Property::POSITION, Vector2(mButtonSize.width, mWindowSize.height * STYLE_BUTTON_POSTION_RELATIVE_TO_WINDOW));
184 mExpandingButtons.CollapsingSignal().Connect(this, &TextLabelExample::OnExpandingButtonCollapsing);
185 mExpandingButtons.SetProperty(Actor::Property::SIZE, mButtonSize);
186 // Creates the buttons to be expanded
187 CreateStyleButtons();
189 // Register the created buttons with the ExpandingButtons.
190 for(unsigned int index = 0; index < NUMBER_OF_STYLES; index++)
192 mExpandingButtons.RegisterButton(mStyleButtons[index]);
197 * One-time setup in response to Application InitSignal.
199 void Create(Application& application)
201 Window window = application.GetWindow();
203 window.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent);
204 mWindowSize = window.GetSize();
205 mButtonSize = Size(mWindowSize.height * 0.1, mWindowSize.height * 0.1); // Button size 1/10 of window height
207 mContainer = Control::New();
208 mContainer.SetProperty(Dali::Actor::Property::NAME, "Container");
209 mContainer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
210 mLayoutSize = Vector2(mWindowSize.width * 0.6f, mWindowSize.width * 0.6f);
211 mContainer.SetProperty(Actor::Property::SIZE, mLayoutSize);
212 window.Add(mContainer);
214 // Resize the center layout when the corner is grabbed
215 mGrabCorner = ImageView::New(BACKGROUND_IMAGE);
216 mGrabCorner.SetProperty(Dali::Actor::Property::NAME, "GrabCorner");
217 mGrabCorner.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER);
218 mGrabCorner.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT);
219 mGrabCorner.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
220 mContainer.Add(mGrabCorner);
222 mPanGestureDetector = PanGestureDetector::New();
223 mPanGestureDetector.Attach(mGrabCorner);
224 mPanGestureDetector.DetectedSignal().Connect(this, &TextLabelExample::OnPan);
226 mLabel = TextLabel::New("\xF0\x9F\x98\x89 A Quick Brown Fox Jumps Over The Lazy Dog");
228 mLabel.SetProperty(Dali::Actor::Property::NAME, "TextLabel");
229 mLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
230 mLabel.SetProperty(Actor::Property::SIZE, mLayoutSize);
231 mLabel.SetProperty(TextLabel::Property::MULTI_LINE, true);
232 mLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::GREEN);
233 mLabel.SetBackgroundColor(Color::WHITE);
234 mContainer.Add(mLabel);
236 // Clicking ExpandingButton shows the Registered Style buttons, clicking again hides them.
237 Vector2 expandingButtonPosition(mButtonSize.width, mWindowSize.height * STYLE_BUTTON_POSTION_RELATIVE_TO_WINDOW);
238 SetUpExpandingStyleButtons(expandingButtonPosition);
239 window.Add(mExpandingButtons);
241 // Add a border for the container so you can see the container is being resized while grabbing the handle.
242 mBorder = Control::New();
243 mBorder.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
244 mBorder.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
245 mBorder.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
247 Dali::Property::Map border;
248 border.Insert(Toolkit::Visual::Property::TYPE, Visual::BORDER);
249 border.Insert(BorderVisual::Property::COLOR, Color::WHITE);
250 border.Insert(BorderVisual::Property::SIZE, 3.f);
251 mBorder.SetProperty(Control::Property::BACKGROUND, border);
252 mContainer.Add(mBorder);
253 mBorder.SetProperty(Actor::Property::VISIBLE, false);
254 mGrabCorner.RaiseToTop();
256 mHueAngleIndex = mLabel.RegisterProperty("hue", 0.0f);
257 Renderer bgRenderer = mLabel.GetRendererAt(0);
259 Constraint constraint = Constraint::New<Vector3>(bgRenderer, VisualRenderer::Property::VISUAL_MIX_COLOR, HSVColorConstraint(0.0f, 0.5f, 0.8f));
260 constraint.AddSource(Source(mLabel, mHueAngleIndex));
261 constraint.SetRemoveAction(Constraint::DISCARD);
264 Animation anim = Animation::New(50.0f);
265 anim.AnimateTo(Property(mLabel, mHueAngleIndex), 6.28318f);
266 anim.SetLooping(true);
269 mContainer.RaiseToTop();
270 mGrabCorner.RaiseToTop();
272 Property::Value labelText = mLabel.GetProperty(TextLabel::Property::TEXT);
273 std::cout << "Displaying text: \"" << labelText.Get<std::string>() << "\"" << std::endl;
276 // If the styling buttons should colapse (hide) then the color buttons should also hide.
277 bool OnExpandingButtonCollapsing(Demo::ExpandingButtons button)
279 mCollapseColorsAndStyles = true;
284 // Get the style type from the given button
285 StyleType GetStyleTypeFromButton(Toolkit::Button button)
287 StyleType style = StyleType::TEXT_COLOR;
289 if(button == mStyleButtons[StyleType::OUTLINE])
291 style = StyleType::OUTLINE;
293 else if(button == mStyleButtons[StyleType::SHADOW])
295 style = StyleType::SHADOW;
297 else if(button == mStyleButtons[StyleType::BACKGROUND])
299 style = StyleType::BACKGROUND;
304 // Style selected, show color buttons
305 bool OnStyleButtonClicked(Toolkit::Button button)
307 StyleType selectedStyle = GetStyleTypeFromButton(button);
308 if(mStyleActivatedForColor == selectedStyle)
314 ResetColorButtons(mColorButtons, NUMBER_OF_COLORS);
315 ShowColorButtons(selectedStyle);
320 // Set style to selected color
321 bool OnColorSelected(Toolkit::Button button)
323 for(unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
325 if(mColorButtons[index] == button)
327 mSelectedColor = AVAILABLE_COLORS[index];
331 switch(mStyleActivatedForColor)
335 Animation animation = Animation::New(1.f);
336 animation.AnimateTo(Property(mLabel, TextLabel::Property::TEXT_COLOR), mSelectedColor, AlphaFunction::LINEAR);
337 mCurrentStyleColor[TEXT_COLOR] = mSelectedColor;
343 Property::Map outlineMap;
344 float outlineWidth = OUTLINE_WIDTH;
346 if(mStyleActiveState[OUTLINE])
348 outlineWidth = (Color::WHITE == mSelectedColor) ? 0.0f : OUTLINE_WIDTH; // toggles outline on/off
350 mStyleActiveState[OUTLINE] = (outlineWidth > 0.0f) ? true : false;
352 outlineMap["color"] = mSelectedColor;
353 outlineMap["width"] = outlineWidth;
354 mCurrentStyleColor[OUTLINE] = mSelectedColor;
355 mLabel.SetProperty(TextLabel::Property::OUTLINE, outlineMap);
360 Vector2 shadowOffset(SHADOW_OFFSET); // Will be set to zeros if color already set
361 Property::Value value = mLabel.GetProperty(TextLabel::Property::SHADOW);
362 Vector4 currentShadowColor;
363 value.Get(currentShadowColor);
365 if(mStyleActiveState[SHADOW])
367 // toggle shadow off ( zero offset ) if color is already set
368 shadowOffset = (Color::WHITE == mSelectedColor) ? Vector2::ZERO : Vector2(SHADOW_OFFSET);
371 mStyleActiveState[SHADOW] = (shadowOffset == Vector2::ZERO) ? false : true;
372 mCurrentStyleColor[SHADOW] = mSelectedColor;
374 Property::Map shadowMap;
375 shadowMap.Insert("offset", shadowOffset);
376 shadowMap.Insert("color", mSelectedColor);
377 mLabel.SetProperty(TextLabel::Property::SHADOW, shadowMap);
383 Property::Map backgroundMap;
384 auto backgroundEnabled(true);
386 if(mStyleActiveState[BACKGROUND])
388 backgroundEnabled = (Color::WHITE != mSelectedColor); // toggles background on/off
390 mStyleActiveState[BACKGROUND] = backgroundEnabled;
392 backgroundMap["color"] = mSelectedColor;
393 backgroundMap["enable"] = backgroundEnabled;
394 mCurrentStyleColor[BACKGROUND] = mSelectedColor;
395 mLabel.SetProperty(DevelTextLabel::Property::BACKGROUND, backgroundMap);
406 // Set the inital color button that should be be selected.
407 // If the style already has a color set then that should be used
408 void SetInitialSelectedColorButton(StyleType styleButtonIndex)
410 Vector4 selectedColor = mCurrentStyleColor[styleButtonIndex];
412 for(unsigned int i = 0; i < NUMBER_OF_COLORS; i++)
414 if(AVAILABLE_COLORS[i] == selectedColor)
418 mColorButtons[i].SetProperty(Toolkit::Button::Property::SELECTED, true);
425 // Create a bar of color buttons that the user can select.
426 void ShowColorButtons(StyleType styleButtonIndex)
428 mCollapseColorsAndStyles = false; // Request to show colors so reset flag
429 mStyleActivatedForColor = styleButtonIndex;
431 for(unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
433 if(!mColorButtonsAnimation)
435 mColorButtonsAnimation = Animation::New(0.15f);
436 mColorButtonsAnimation.FinishedSignal().Connect(this, &TextLabelExample::OnColorButtonAnimationFinished);
439 // Create a color button
440 if(!mColorButtons[index])
442 mColorButtons[index] = RadioButton::New();
443 mColorButtons[index].SetProperty(Actor::Property::SIZE, mButtonSize);
444 mColorButtons[index].ClickedSignal().Connect(this, &TextLabelExample::OnColorSelected);
445 mColorButtons[index].SetProperty(Button::Property::TOGGLABLE, true);
446 Property::Map propertyMap;
447 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
448 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, AVAILABLE_COLORS[index]);
449 mColorButtons[index].SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap);
450 mColorButtons[index].SetProperty(Toolkit::Button::Property::UNSELECTED_VISUAL, propertyMap);
451 mColorButtons[index].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER);
452 mColorButtons[index].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER);
454 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
455 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, AVAILABLE_COLORS[index]);
456 mColorButtons[index].SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, propertyMap);
458 mColorButtons[index].SetProperty(Toolkit::Button::Property::SELECTED_VISUAL,
459 Property::Map().Add(Visual::Property::TYPE, Visual::BORDER).Add(BorderVisual::Property::COLOR, Color::WHITE).Add(BorderVisual::Property::SIZE, 4.0f).Add(BorderVisual::Property::ANTI_ALIASING, true));
461 // Use a white button with 50% transparency as a clear color button
462 if(Color::WHITE == AVAILABLE_COLORS[index] && styleButtonIndex != StyleType::TEXT_COLOR)
464 mColorButtons[index].SetProperty(Actor::Property::OPACITY, 0.5f);
466 mColorButtons[index].SetProperty(Toolkit::Button::Property::LABEL,
467 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT).Add(Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER).Add(Toolkit::TextVisual::Property::TEXT, "off"));
471 SetInitialSelectedColorButton(mStyleActivatedForColor);
473 mColorButtons[index].Unparent();
475 mStyleButtons[styleButtonIndex].Add(mColorButtons[index]);
476 mColorButtons[index].Lower();
478 // Position button using nice animation
479 mColorButtons[index].SetProperty(Actor::Property::POSITION_Y, -GAP_BETWEEN_BUTTONS);
480 float desiredPosition = -(mButtonSize.height + GAP_BETWEEN_BUTTONS) * (index);
481 AlphaFunction focusedAlphaFunction = AlphaFunction(Vector2(0.32f, 0.08f), Vector2(0.38f, 1.72f));
482 mColorButtonsAnimation.AnimateBy(Property(mColorButtons[index], Actor::Property::POSITION_Y), desiredPosition, focusedAlphaFunction);
485 mColorButtonsHidden = false;
486 mColorButtonsAnimation.Play();
489 // Remove the color buttons when not being shown.
490 void ResetColorButtons(Button buttons[], unsigned int numberOfButtons)
492 for(unsigned int index = 0; index < numberOfButtons; index++)
494 UnparentAndReset(buttons[index]);
498 void OnColorButtonAnimationFinished(Animation& animation)
501 if(mColorButtonsHidden)
503 ResetColorButtons(mColorButtons, NUMBER_OF_COLORS);
504 animation.Reset(); // Handle reset
505 if(mCollapseColorsAndStyles)
507 mExpandingButtons.Collapse();
512 // Create the style buttons that will expand from the expanding button.
513 void CreateStyleButtons()
515 for(unsigned int index = 0; index < NUMBER_OF_STYLES; index++)
517 if(!mStyleButtons[index])
519 mStyleButtons[index] = PushButton::New();
520 mStyleButtons[index].SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_IMAGES[index]);
521 mStyleButtons[index].SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, STYLE_SELECTED_IMAGE);
522 mStyleButtons[index].SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
523 mStyleButtons[index].SetProperty(Actor::Property::SIZE, mButtonSize);
524 mStyleButtons[index].ClickedSignal().Connect(this, &TextLabelExample::OnStyleButtonClicked);
529 // Animate away the color bar.
530 void HideColorButtons()
532 if(!mColorButtonsHidden)
534 for(unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
536 mColorButtonsAnimation.AnimateTo(Property(mColorButtons[index], Actor::Property::POSITION_Y), 0.0f);
538 mColorButtonsHidden = true;
539 mColorButtonsAnimation.Play();
541 mStyleActivatedForColor = NUMBER_OF_STYLES;
544 // Request the expanding button to collapse.
545 void HideStyleAndColorButtons()
547 mCollapseColorsAndStyles = true;
548 if(mColorButtonsHidden)
550 mExpandingButtons.Collapse();
558 // Resize the text-label with pan gesture
559 void OnPan(Actor actor, const PanGesture& gesture)
561 // Reset mLayoutSize when the pan starts
562 GestureState state = gesture.GetState();
563 if(state == GestureState::STARTED)
565 if(mLayoutSize.x < 2.0f)
567 mLayoutSize.x = 2.0f;
570 if(mLayoutSize.y < 2.0f)
572 mLayoutSize.y = 2.0f;
575 // Only show the border during the panning
576 mBorder.SetProperty(Actor::Property::VISIBLE, true);
578 HideStyleAndColorButtons();
581 const Vector2& displacement = gesture.GetDisplacement();
582 mLayoutSize.x += displacement.x * 2.0f;
583 mLayoutSize.y += displacement.y * 2.0f;
585 if(mLayoutSize.x >= 2.0f ||
586 mLayoutSize.y >= 2.0f)
588 mLayoutSize.x = std::min(mLayoutSize.x, mWindowSize.width);
589 mLayoutSize.y = std::min(mLayoutSize.y, mWindowSize.height * .9f);
591 // Avoid pixel mis-alignment issue
592 Vector2 clampedSize = Vector2(std::max(ConvertToEven(static_cast<int>(mLayoutSize.x)), 2),
593 std::max(ConvertToEven(static_cast<int>(mLayoutSize.y)), 2));
595 mContainer.SetProperty(Actor::Property::SIZE, clampedSize);
598 if(state == GestureState::CANCELLED || state == GestureState::FINISHED)
600 // Resize the text label to match the container size when panning is finished
601 mLabel.SetProperty(Actor::Property::SIZE, mLayoutSize);
602 mBorder.SetProperty(Actor::Property::VISIBLE, false);
607 * Main key event handler
609 void OnKeyEvent(const KeyEvent& event)
611 if(event.GetState() == KeyEvent::DOWN)
613 if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK))
617 else if(event.IsCtrlModifier())
619 switch(event.GetKeyCode())
621 // Select rendering back-end
622 case KEY_ZERO: // fall through
625 mLabel.SetProperty(DevelTextLabel::Property::RENDERING_BACKEND, event.GetKeyCode() - 10);
628 case KEY_A: // Animate text colour
630 Animation animation = Animation::New(2.f);
631 animation.AnimateTo(Property(mLabel, TextLabel::Property::TEXT_COLOR), Color::RED, AlphaFunction::SIN);
632 animation.SetLoopCount(3);
636 case KEY_F: // Fill vertically
638 if(ResizePolicy::DIMENSION_DEPENDENCY == mLabel.GetResizePolicy(Dimension::HEIGHT))
640 mLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
644 mLabel.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT);
648 case KEY_H: // Horizontal alignment
650 if(++mAlignment >= H_ALIGNMENT_STRING_COUNT)
655 mLabel.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, H_ALIGNMENT_STRING_TABLE[mAlignment]);
658 case KEY_V: // Vertical alignment
660 if(++mAlignment >= V_ALIGNMENT_STRING_COUNT)
665 mLabel.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, V_ALIGNMENT_STRING_TABLE[mAlignment]);
668 case KEY_M: // Multi-line
670 bool multiLine = mLabel.GetProperty<bool>(TextLabel::Property::MULTI_LINE);
671 mLabel.SetProperty(TextLabel::Property::MULTI_LINE, !multiLine);
674 case KEY_L: // Language
676 const Language& language = LANGUAGES[mLanguageId];
678 mLabel.SetProperty(TextLabel::Property::TEXT, language.text);
680 if(++mLanguageId >= NUMBER_OF_LANGUAGES)
686 case KEY_S: // Shadow color
688 Property::Value value = mLabel.GetProperty(TextLabel::Property::SHADOW);
690 value.Get(shadowColor);
691 Property::Map shadowMap;
692 if(Color::BLACK == shadowColor)
694 shadowMap.Insert("color", Color::RED);
695 mLabel.SetProperty(TextLabel::Property::SHADOW, shadowMap);
699 shadowMap.Insert("color", Color::BLACK);
700 mLabel.SetProperty(TextLabel::Property::SHADOW, shadowMap);
704 case KEY_U: // Markup
706 mLabel.SetProperty(TextLabel::Property::ENABLE_MARKUP, true);
707 mLabel.SetProperty(TextLabel::Property::TEXT, "<font family='DejaVuSerif' size='18'>H<color value='blue'>ello</color> <font weight='bold'>world</font> demo</font>");
710 case KEY_PLUS: // Increase shadow offset
712 Property::Value value = mLabel.GetProperty(TextLabel::Property::SHADOW);
713 Vector2 shadowOffset;
714 value.Get(shadowOffset);
715 shadowOffset += Vector2(1.0f, 1.0f);
717 Property::Map shadowMap;
718 shadowMap.Insert("offset", shadowOffset);
719 mLabel.SetProperty(TextLabel::Property::SHADOW, shadowMap);
722 case KEY_MINUS: // Decrease 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);
740 Application& mApplication;
744 Demo::ExpandingButtons mExpandingButtons;
745 PushButton mStyleButtons[NUMBER_OF_STYLES];
746 bool mStyleActiveState[NUMBER_OF_STYLES];
748 Vector4 mCurrentStyleColor[NUMBER_OF_STYLES];
750 Vector4 mSelectedColor;
752 Button mColorButtons[NUMBER_OF_COLORS];
754 StyleType mStyleActivatedForColor; // The style that the color bar is connected to
760 PanGestureDetector mPanGestureDetector;
764 Animation mColorButtonsAnimation;
769 unsigned int mLanguageId;
770 unsigned int mAlignment;
771 Property::Index mHueAngleIndex;
772 Property::Index mOverrideMixColorIndex;
774 bool mColorButtonsHidden;
775 bool mCollapseColorsAndStyles;
778 int DALI_EXPORT_API main(int argc, char** argv)
780 Application application = Application::New(&argc, &argv, DEMO_THEME_PATH);
781 TextLabelExample test(application);
782 application.MainLoop();