+ mContainer.RaiseToTop();
+ mGrabCorner.RaiseToTop();
+
+ Property::Value labelText = mLabel.GetProperty(TextLabel::Property::TEXT);
+ std::cout << "Displaying text: \"" << labelText.Get<std::string>() << "\"" << std::endl;
+ }
+
+ // If the styling buttons should colapse (hide) then the color buttons should also hide.
+ bool OnExpandingButtonCollapsing(Demo::ExpandingButtons button)
+ {
+ mCollapseColorsAndStyles = true;
+ HideColorButtons();
+ return true;
+ }
+
+ // Get the style type from the given button
+ StyleType GetStyleTypeFromButton(Toolkit::Button button)
+ {
+ StyleType style = StyleType::TEXT_COLOR;
+
+ if(button == mStyleButtons[StyleType::OUTLINE])
+ {
+ style = StyleType::OUTLINE;
+ }
+ else if(button == mStyleButtons[StyleType::SHADOW])
+ {
+ style = StyleType::SHADOW;
+ }
+ else if(button == mStyleButtons[StyleType::BACKGROUND])
+ {
+ style = StyleType::BACKGROUND;
+ }
+ return style;
+ }
+
+ // Style selected, show color buttons
+ bool OnStyleButtonClicked(Toolkit::Button button)
+ {
+ StyleType selectedStyle = GetStyleTypeFromButton(button);
+ if(mStyleActivatedForColor == selectedStyle)
+ {
+ HideColorButtons();
+ }
+ else
+ {
+ ResetColorButtons(mColorButtons, NUMBER_OF_COLORS);
+ ShowColorButtons(selectedStyle);
+ }
+ return true;
+ }
+
+ // Set style to selected color
+ bool OnColorSelected(Toolkit::Button button)
+ {
+ for(unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
+ {
+ if(mColorButtons[index] == button)
+ {
+ mSelectedColor = AVAILABLE_COLORS[index];
+ }
+ }
+
+ switch(mStyleActivatedForColor)
+ {
+ case TEXT_COLOR:
+ {
+ Animation animation = Animation::New(1.f);
+ animation.AnimateTo(Property(mLabel, TextLabel::Property::TEXT_COLOR), mSelectedColor, AlphaFunction::LINEAR);
+ mCurrentStyleColor[TEXT_COLOR] = mSelectedColor;
+ animation.Play();
+ break;
+ }
+ case OUTLINE:
+ {
+ Property::Map outlineMap;
+ float outlineWidth = OUTLINE_WIDTH;
+
+ if(mStyleActiveState[OUTLINE])
+ {
+ outlineWidth = (Color::WHITE == mSelectedColor) ? 0.0f : OUTLINE_WIDTH; // toggles outline on/off
+ }
+ mStyleActiveState[OUTLINE] = (outlineWidth > 0.0f) ? true : false;
+
+ outlineMap["color"] = mSelectedColor;
+ outlineMap["width"] = outlineWidth;
+ mCurrentStyleColor[OUTLINE] = mSelectedColor;
+ mLabel.SetProperty(TextLabel::Property::OUTLINE, outlineMap);
+ break;
+ }
+ case SHADOW:
+ {
+ Vector2 shadowOffset(SHADOW_OFFSET); // Will be set to zeros if color already set
+ Property::Value value = mLabel.GetProperty(TextLabel::Property::SHADOW);
+ Vector4 currentShadowColor;
+ value.Get(currentShadowColor);
+
+ if(mStyleActiveState[SHADOW])
+ {
+ // toggle shadow off ( zero offset ) if color is already set
+ shadowOffset = (Color::WHITE == mSelectedColor) ? Vector2::ZERO : Vector2(SHADOW_OFFSET);
+ }
+
+ mStyleActiveState[SHADOW] = (shadowOffset == Vector2::ZERO) ? false : true;
+ mCurrentStyleColor[SHADOW] = mSelectedColor;
+
+ Property::Map shadowMap;
+ shadowMap.Insert("offset", shadowOffset);
+ shadowMap.Insert("color", mSelectedColor);
+ mLabel.SetProperty(TextLabel::Property::SHADOW, shadowMap);
+
+ break;
+ }
+ case BACKGROUND:
+ {
+ Property::Map backgroundMap;
+ auto backgroundEnabled(true);
+
+ if(mStyleActiveState[BACKGROUND])
+ {
+ backgroundEnabled = (Color::WHITE != mSelectedColor); // toggles background on/off
+ }
+ mStyleActiveState[BACKGROUND] = backgroundEnabled;
+
+ backgroundMap["color"] = mSelectedColor;
+ backgroundMap["enable"] = backgroundEnabled;
+ mCurrentStyleColor[BACKGROUND] = mSelectedColor;
+ mLabel.SetProperty(DevelTextLabel::Property::BACKGROUND, backgroundMap);
+
+ break;
+ }
+ default:
+ break;
+ }
+
+ return true;
+ }
+
+ // Set the inital color button that should be be selected.
+ // If the style already has a color set then that should be used
+ void SetInitialSelectedColorButton(StyleType styleButtonIndex)
+ {
+ Vector4 selectedColor = mCurrentStyleColor[styleButtonIndex];
+
+ for(unsigned int i = 0; i < NUMBER_OF_COLORS; i++)
+ {
+ if(AVAILABLE_COLORS[i] == selectedColor)
+ {
+ if(mColorButtons[i])
+ {
+ mColorButtons[i].SetProperty(Toolkit::Button::Property::SELECTED, true);
+ }
+ break;
+ }
+ }
+ }
+
+ // Create a bar of color buttons that the user can select.
+ void ShowColorButtons(StyleType styleButtonIndex)
+ {
+ mCollapseColorsAndStyles = false; // Request to show colors so reset flag
+ mStyleActivatedForColor = styleButtonIndex;
+
+ for(unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
+ {
+ if(!mColorButtonsAnimation)
+ {
+ mColorButtonsAnimation = Animation::New(0.15f);
+ mColorButtonsAnimation.FinishedSignal().Connect(this, &TextLabelExample::OnColorButtonAnimationFinished);
+ }
+
+ // Create a color button
+ if(!mColorButtons[index])
+ {
+ mColorButtons[index] = RadioButton::New();
+ mColorButtons[index].SetProperty(Actor::Property::SIZE, mButtonSize);
+ mColorButtons[index].ClickedSignal().Connect(this, &TextLabelExample::OnColorSelected);
+ mColorButtons[index].SetProperty(Button::Property::TOGGLABLE, true);
+ Property::Map propertyMap;
+ propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
+ propertyMap.Insert(ColorVisual::Property::MIX_COLOR, AVAILABLE_COLORS[index]);
+ mColorButtons[index].SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap);
+ mColorButtons[index].SetProperty(Toolkit::Button::Property::UNSELECTED_VISUAL, propertyMap);
+ mColorButtons[index].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER);
+ mColorButtons[index].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER);
+
+ propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
+ propertyMap.Insert(ColorVisual::Property::MIX_COLOR, AVAILABLE_COLORS[index]);
+ mColorButtons[index].SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, propertyMap);
+
+ mColorButtons[index].SetProperty(Toolkit::Button::Property::SELECTED_VISUAL,
+ 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));
+
+ // Use a white button with 50% transparency as a clear color button
+ if(Color::WHITE == AVAILABLE_COLORS[index] && styleButtonIndex != StyleType::TEXT_COLOR)
+ {
+ mColorButtons[index].SetProperty(Actor::Property::OPACITY, 0.5f);
+
+ mColorButtons[index].SetProperty(Toolkit::Button::Property::LABEL,
+ Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT).Add(Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER).Add(Toolkit::TextVisual::Property::TEXT, "off"));
+ }
+ }
+
+ SetInitialSelectedColorButton(mStyleActivatedForColor);
+
+ mColorButtons[index].Unparent();
+
+ mStyleButtons[styleButtonIndex].Add(mColorButtons[index]);
+ mColorButtons[index].Lower();
+
+ // Position button using nice animation
+ mColorButtons[index].SetProperty(Actor::Property::POSITION_Y, -GAP_BETWEEN_BUTTONS);
+ float desiredPosition = -(mButtonSize.height + GAP_BETWEEN_BUTTONS) * (index);
+ AlphaFunction focusedAlphaFunction = AlphaFunction(Vector2(0.32f, 0.08f), Vector2(0.38f, 1.72f));
+ mColorButtonsAnimation.AnimateBy(Property(mColorButtons[index], Actor::Property::POSITION_Y), desiredPosition, focusedAlphaFunction);
+ }
+
+ mColorButtonsHidden = false;
+ mColorButtonsAnimation.Play();
+ }
+
+ // Remove the color buttons when not being shown.
+ void ResetColorButtons(Button buttons[], unsigned int numberOfButtons)
+ {
+ for(unsigned int index = 0; index < numberOfButtons; index++)
+ {
+ UnparentAndReset(buttons[index]);
+ }
+ }
+
+ void OnColorButtonAnimationFinished(Animation& animation)
+ {
+ animation.Clear();
+ if(mColorButtonsHidden)
+ {
+ ResetColorButtons(mColorButtons, NUMBER_OF_COLORS);
+ animation.Reset(); // Handle reset
+ if(mCollapseColorsAndStyles)
+ {
+ mExpandingButtons.Collapse();
+ }
+ }
+ }
+
+ // Create the style buttons that will expand from the expanding button.
+ void CreateStyleButtons()
+ {
+ for(unsigned int index = 0; index < NUMBER_OF_STYLES; index++)
+ {
+ if(!mStyleButtons[index])
+ {
+ mStyleButtons[index] = PushButton::New();
+ mStyleButtons[index].SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_IMAGES[index]);
+ mStyleButtons[index].SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, STYLE_SELECTED_IMAGE);
+ mStyleButtons[index].SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+ mStyleButtons[index].SetProperty(Actor::Property::SIZE, mButtonSize);
+ mStyleButtons[index].ClickedSignal().Connect(this, &TextLabelExample::OnStyleButtonClicked);
+ }
+ }
+ }
+
+ // Animate away the color bar.
+ void HideColorButtons()
+ {
+ if(!mColorButtonsHidden)
+ {
+ for(unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
+ {
+ mColorButtonsAnimation.AnimateTo(Property(mColorButtons[index], Actor::Property::POSITION_Y), 0.0f);
+ }
+ mColorButtonsHidden = true;
+ mColorButtonsAnimation.Play();
+ }
+ mStyleActivatedForColor = NUMBER_OF_STYLES;
+ }
+
+ // Request the expanding button to collapse.
+ void HideStyleAndColorButtons()
+ {
+ mCollapseColorsAndStyles = true;
+ if(mColorButtonsHidden)
+ {
+ mExpandingButtons.Collapse();
+ }
+ else
+ {
+ HideColorButtons();
+ }