X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fbutton-impl.h;h=dc123cc3d48a955558626d08fc298f3912acd020;hp=71a42fe3ca78b99d6d93720790427f4f3393c97f;hb=863244a09761c6e22a224299b6155a285e21d6ec;hpb=78d6c4118411aa10112953fe6844eb08c944dd59 diff --git a/dali-toolkit/internal/controls/buttons/button-impl.h b/dali-toolkit/internal/controls/buttons/button-impl.h index 71a42fe..dc123cc 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.h +++ b/dali-toolkit/internal/controls/buttons/button-impl.h @@ -1,5 +1,5 @@ -#ifndef __DALI_TOOLKIT_INTERNAL_BUTTON_H__ -#define __DALI_TOOLKIT_INTERNAL_BUTTON_H__ +#ifndef DALI_TOOLKIT_INTERNAL_BUTTON_H +#define DALI_TOOLKIT_INTERNAL_BUTTON_H /* * Copyright (c) 2014 Samsung Electronics Co., Ltd. @@ -23,6 +23,7 @@ #include // INTERNAL INCLUDES +#include #include #include @@ -38,22 +39,32 @@ namespace Internal { /** + * @copydoc Toolkit::Button + * * Button is the base class implementation for all buttons. + * + * @note + * + * All Foreground/Icon visuals expected to be the same size. + * Background visuals will take the size of the control. + * Padding and struts take size precedence over visuals when available space is limited. + * Icon/Foreground visuals take size precedence over Labels when available space is limited. */ class Button : public Control { -protected: - - /** - * Construct a new Button. - */ - Button(); +public: /** - * A reference counted object may only be deleted by calling Unreference() + * Enum describing the position the text label can be in relation to the control (and foreground/icon) */ - virtual ~Button(); + enum Align + { + BEGIN, // At the start of the control before the foreground/icon + END, // At the end of the control after the foreground/icon + TOP, // At the top of the control above the foreground/icon + BOTTOM // At the bottom of the control below the foreground/icon + }; public: @@ -138,82 +149,13 @@ public: std::string GetLabelText() const; /** - * @copydoc Dali::Toolkit::PushButton::SetUnselectedImage - */ - void SetUnselectedImage( const std::string& filename ); - - /** - * @copydoc Dali::Toolkit::PushButton::SetSelectedImage - */ - void SetSelectedImage( const std::string& filename ); - - /** - * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage - */ - void SetBackgroundImage( const std::string& filename ); - - /** - * @copydoc Dali::Toolkit::PushButton::SetSelectedBackgroundImage - */ - void SetSelectedBackgroundImage( const std::string& filename ); - - /** - * @copydoc Dali::Toolkit::PushButton::SetDisabledImage - */ - void SetDisabledImage( const std::string& filename ); - - /** - * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage - */ - void SetDisabledSelectedImage( const std::string& filename ); - - /** - * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage - */ - void SetDisabledBackgroundImage( const std::string& filename ); - - /** - * @return The filename used for the button image. - */ - std::string GetUnselectedImageFilename() const; - - /** - * @return The filename used for the selected image. - */ - std::string GetSelectedImageFilename() const; - - /** - * @return The filename used for the background image. - */ - std::string GetBackgroundImageFilename() const; - - /** - * @return The filename used for the selected background image. - */ - std::string GetSelectedBackgroundImageFilename() const; - - /** - * @return The filename used for the disabled button image. - */ - std::string GetDisabledImageFilename() const; - - /** - * @return The filename used for the disabled selected image. - */ - std::string GetDisabledSelectedImageFilename() const; - - /** - * @return The filename used for the disabled background image. - */ - std::string GetDisabledBackgroundImageFilename() const; - - /** - * @brief Sets the specified properties on the button label. + * @brief Produces a Property::Map of Text properties to create a Text Visual * If the label does not exist yet, it is created. * The derived buttons are notified if any properties are changed. * @param[in] properties A Property::Map of key-value pairs of properties to set. + * @param[out] properties A Property::Map of text visual properties to set. */ - void ModifyLabel( const Property::Map& properties ); + void MergeLabelProperties( const Property::Map& inMap, Property::Map& outMap ); /** * Performs actions as requested using the action name. @@ -232,160 +174,168 @@ public: // Deprecated API void SetLabel( Actor label ); /** - * @deprecated Sets the unselected image with an Actor. + * @deprecated Sets the unselected image with an url. * @param[in] image The Actor to use. */ - void SetButtonImage( Actor image ); - - /** - * @deprecated Sets the selected image with an Actor. - * @param[in] image The Actor to use. - */ - void SetSelectedImage( Actor image ); - - /** - * @deprecated Sets the background image with an Actor. - * @param[in] image The Actor to use. - */ - void SetBackgroundImage( Actor image ); + void SetUnselectedImage( const std::string& filename ); /** - * @deprecated Sets the selected background image with an Actor. - * @param[in] image The Actor to use. + * @deprecated Sets the selected image with an url. + * @param[in] filename The url of the image to use to use. */ - void SetSelectedBackgroundImage( Actor image ); + void SetSelectedImage( const std::string& filename ); /** - * @deprecated Sets the disabled image with an Actor. - * @param[in] image The Actor to use. + * @deprecated Sets the selected background image with an url. + * @param[in] filename The url of the image to use to use. */ - void SetDisabledImage( Actor image ); + void SetSelectedBackgroundImage( const std::string& filename ); /** - * @deprecated Sets the disabled selected image with an Actor. - * @param[in] image The Actor to use. + * @deprecated Sets the background image with an url. + * @param[in] filename The url of the image to use to use. */ - void SetDisabledSelectedImage( Actor image ); + void SetBackgroundImage( const std::string& filename ); /** - * @deprecated Sets the disabled background image with an Actor. - * @param[in] image The Actor to use. + * @deprecated Sets the disabled unselected background image with an url. + * @param[in] filename The url of the image to use to use. */ - void SetDisabledBackgroundImage( Actor image ); + void SetDisabledBackgroundImage( const std::string& filename ); /** - * @copydoc Dali::Toolkit::Button::GetButtonImage + * @deprecated Sets the disabled unselected image with an url. + * @param[in] filename The url of the image to use to use. */ - Actor GetButtonImage() const; + void SetDisabledImage( const std::string& filename ); /** - * @copydoc Dali::Toolkit::Button::GetSelectedImage + * @deprecated Sets the disabled selected image with an url. + * @param[in] filename The url of the image to use to use. */ - Actor GetSelectedImage() const; - -protected: + void SetDisabledSelectedImage( const std::string& filename ); /** - * @return A reference to the label actor. + * @deprecated Sets the unselected image with an Actor. + * @param[in] image The Image to use. */ - Actor& GetLabelActor(); + void SetButtonImage( Image image ); /** - * @return A reference to the unselected button image. + * @deprecated Sets the selected image with an Actor. + * @param[in] image The Image to use. */ - Actor& GetUnselectedImage(); + void SetSelectedImage( Image image ); /** - * @return A reference to the selected image. + * @Gets url of a image visual, used by GetProperty but for deprecated Properties + * @param[in] index Visual index of url required + * @return filename for the corresponding visual */ - Actor& GetSelectedImage(); + std::string GetUrlForImageVisual( const Property::Index index ) const; /** - * @return A reference to the background image. + * @copydoc Dali::Toolkit::Button::GetButtonImage */ - Actor& GetBackgroundImage(); + Actor GetButtonImage() const; /** - * @return A reference to the selected background image. + * @copydoc Dali::Toolkit::Button::GetSelectedImage */ - Actor& GetSelectedBackgroundImage(); + Actor GetSelectedImage() const; - /** - * @return A reference to the disabled button image. - */ - Actor& GetDisabledImage(); +public: /** - * @return A reference to the disabled selected image. + * Button's state */ - Actor& GetDisabledSelectedImage(); + enum State + { + UNSELECTED_STATE, ///< The button is unselected. + SELECTED_STATE, ///< The button is selected. + DISABLED_UNSELECTED_STATE, ///< The button is disabled and unselected. + DISABLED_SELECTED_STATE, ///< The button is disabled and selected. + STATE_COUNT, ///< Number of States + }; /** - * @return A reference to the disabled background image. + * Enum to distinguish the different style-able components of the button */ - Actor& GetDisabledBackgroundImage(); - -private: + enum Visuals + { + UNSELECTED_FOREGROUND = 0, + SELECTED_FOREGROUND, + DISABLED_SELECTED_FOREGROUND, + DISABLED_UNSELECTED_FOREGROUND, + UNSELECTED_BACKGROUND, + SELECTED_BACKGROUND, + DISABLED_UNSELECTED_BACKGROUND, + DISABLED_SELECTED_BACKGROUND, + VISUALS_COUNT + }; /** - * Perform the click action to click the button. - * @param[in] attributes The attributes to perfrom this action. - * @return true if this control can perform action. + * Enum to list types of visual a state can have. */ - bool DoClickAction( const Property::Map& attributes ); + enum VisualState + { + BACKGROUND = 0, + FOREGROUND, + VISUAL_STATE_COUNT + }; - /** - * This method is called when the label is set. - * @param[in] noPadding Used to bypass padding if the label is to be treated generically. - */ - virtual void OnLabelSet( bool noPadding ) {} +protected: /** - * This method is called when the unselected button image is set + * Button press state which is not the same as the actual button's state. + * For example An UNSELECTED button can be DEPRESSED, but until released, the actual button state doesn't change to SELECTED */ - virtual void OnUnselectedImageSet() {} + enum PressState + { + DEPRESSED, ///< The button is up. + UNPRESSED, ///< The button is down. + TOGGLE_DEPRESSED, ///< The button has been pressed down and will stay depressed when released. + }; /** - * This method is called when the selected image is set + * Construct a new Button. */ - virtual void OnSelectedImageSet() {} + Button(); /** - * This method is called when the background image is set + * A reference counted object may only be deleted by calling Unreference() */ - virtual void OnBackgroundImageSet() {} - + virtual ~Button(); /** - * This method is called when the selected background image is set + * @return A reference to the label actor. */ - virtual void OnSelectedBackgroundImageSet() {} + Actor& GetLabelActor(); /** - * This method is called when the disabled button image is set + * @return A reference to the unselected button image. */ - virtual void OnDisabledImageSet() {} + Actor GetUnselectedImage(); /** - * This method is called when the disabled selected image is set + * @return A reference to the selected image. */ - virtual void OnDisabledSelectedImageSet() {} + Actor GetSelectedImage(); - /** - * This method is called when the disabled background image is set - */ - virtual void OnDisabledBackgroundImageSet() {} +private: /** - * This method is called the button is down. - * Could be reimplemented in subclasses to provide specific behaviour. + * Perform the click action to click the button. + * @param[in] attributes The attributes to perfrom this action. + * @return true if this control can perform action. */ - virtual void OnButtonDown(); + bool DoClickAction( const Property::Map& attributes ); /** - * This method is called when the button is up. + * This method is called when the button is a Toggle button and released * Could be reimplemented in subclasses to provide specific behaviour. + * @return bool returns true if state changed. */ - virtual void OnButtonUp(); + virtual bool OnToggleReleased(); /** * This method is called when touch leaves the boundary of the button or several touch points are received. @@ -402,7 +352,7 @@ private: /** * This method is called when the \e selected property is changed. */ - virtual void OnSelected() {} + virtual void OnStateChange( State newState ){} /** * This method is called when the \e disabled property is changed. @@ -492,7 +442,27 @@ protected: // From Control * @copydoc Toolkit::Control::OnStageDisconnection() * @note If overridden by deriving button classes, then an up-call to Button::OnStageDisconnection MUST be made at the end. */ - void OnStageDisconnection(); + virtual void OnStageDisconnection(); + + /** + * @copydoc Toolkit::Control::OnStageConnnection() + */ + virtual void OnStageConnection( int depth ); + + /** + * @copydoc Toolkit::Control::GetNaturalSize + */ + virtual Vector3 GetNaturalSize(); + + /** + * @copydoc Toolkit::Control::OnSetResizePolicy + */ + virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ); + + /** + * @copydoc Toolkit::Control::OnRelayout + */ + virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ); private: @@ -521,193 +491,152 @@ private: void SetUpTimer( float delay ); /** - * Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer. + * Button has been pressed */ - bool AutoRepeatingSlot(); + void Pressed(); /** - * Sets the button as selected or unselected. - * @param[in] selected \e selected property value. - * @param[in] emitSignal Emit a signal if this value is \e true. + * This method is called the button is down. */ - void SetSelected( bool selected, bool emitSignal ); + void ButtonDown(); /** - * This method is called when the button is pressed. + * This method is called when the button is up. */ - void Pressed(); + void ButtonUp(); /** - * This method is called when the button is released. + * Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer. */ - void Released(); + bool AutoRepeatingSlot(); /** - * Used to perform common setup applied to images within button. - * This will replace the current image with the specifed one. - * @param[in] actorToModify The image to replace. - * @param[out] newActor The new image to use. + * Check the requested state is an allowed transition. + * Some states can not be transitioned to from certain states. + * @param[in] requestedState check if can transition to this state + * @return bool true if state change valid */ - void SetupContent( Actor& actorToModify, Actor newActor ); + bool ValidateState( State requestedState ); /** - * Sets the color of the unselected image. - * If no image exists, it is created. - * @param[in] color The color to use. + * Perform the given function on the visuals in the given state. Can be used to add and remove visuals. + * @param[in] functionPtr pointer to the function to perform an action on a visual + * @param[in] state Visuals in this state will be the target */ - void SetUnselectedColor( const Vector4& color ); + void PerformFunctionOnVisualsInState( void(Button::*functionPtr)( Property::Index visualIndex), State state ); /** - * Gets the unselected content color. - * @return The currently used unselected color. + * Changes the button state when an action occurs on it + * @param[in] requestedState the state to change to */ - const Vector4 GetUnselectedColor() const; + void ChangeState( State requestedState ); /** - * Sets the color of the selected image. - * If no image exists, it is created. - * @param[in] color The color to use. + * @brief Get unselected button color + * @return color as vector4 */ - void SetSelectedColor( const Vector4& color ); + const Vector4 GetUnselectedColor() const; /** - * Gets the selected content color. - * @return The currently used selected color. + * @brief Get selected button color + * @return color as vector4 */ const Vector4 GetSelectedColor() const; -protected: - - enum ButtonState - { - ButtonUp, ///< The button is up. - ButtonDown, ///< The button is down. - }; - - /** - * Button paint states. - */ - enum PaintState - { - UnselectedState, ///< The button is unselected. - SelectedState, ///< The button is selected. - DisabledUnselectedState, ///< The button is disabled and unselected. - DisabledSelectedState, ///< The button is disabled and selected. - }; - /** - * Enum to specify which decoration when getting and setting decorations. + * Sets the color of button in selected or unselected state, if image also supplied this color will be appplied to it. + * If no visual exists, it is created. + * @param[in] color The color to use. + * @param[in] visualIndex The Visual to apply the color */ - enum DecorationState - { - UNSELECTED_DECORATION = 0, - SELECTED_DECORATION, - DECORATION_STATES - }; - - ButtonState GetState(); - PaintState GetPaintState(); - void SetDecoration( DecorationState state, Actor actor ); - Actor& GetDecoration( DecorationState state ); - + void SetColor( const Vector4& color, Property::Index visualIndex ); /** - * Returns the animation to be used for transitioning creating the animation if needed. - * @return The initialised transition animation. + * This method is called when the button is released. */ - Dali::Animation GetTransitionAnimation(); + void Released(); - /** - * Prepares the actor to be transitioned in. - * @param[in] actor The actor that will be transitioned in. - */ - virtual void PrepareForTranstionIn( Actor actor ) {} +protected: /** - * Prepares the actor to be transitioned in. - * @param[in] actor The actor that will be transitioned out. + * Set Text Label Padding + * @param[in] padding BEGIN END BOTTOM TOP */ - virtual void PrepareForTranstionOut( Actor actor ) {} + void SetLabelPadding( const Padding& padding ); /** - * Transitions the actor in, allowing derived classes to configure - * the GetTransitionAnimation() animation ready. - * Button is in charge of calling Dali::Animation::Play and so derived classes - * only need to add the animation. + * Get Text Label padding + * @return Padding */ - virtual void OnTransitionIn( Actor actor ) {} + Padding GetLabelPadding(); /** - * Transitions the actor out, allowing derived classes to configure - * the GetTransitionAnimation() animation ready. - * Button is in charge of calling Dali::Animation::Play and so derived classes - * only need to add the animation. + * Set Foreground/icon Padding + * @param[in] padding BEGIN END BOTTOM TOP */ - virtual void OnTransitionOut( Actor actor ) {} - -private: + void SetForegroundPadding( const Padding& padding); /** - * Starts the transition animation. - * Button::TransitionFinished is called when the animation finishes. + * Get Foreground padding + * @ return Padding */ - void StartTransitionAnimation(); + Padding GetForegroundPadding(); /** - * This method stops all transition animations + * @brief Setup the button components for example foregrounds and background + * @param[in] index the index of the visual to set + * @param[in] value the value to set on the component + * @param[in] visualDepth the depth of the visual if overlapping another */ - void StopTransitionAnimation(); + void CreateVisualsForComponent( Property::Index index ,const Property::Value& value, const float visualDepth ); /** - * Called when the transition animation finishes. + * @brief Get the Property map for the given Visual + * @param[in] visualIndex visual index of the required visual + * @param[out] retreivedMap the property map used to construct the required visual + * @return bool success flag, true if visual found */ - void TransitionAnimationFinished( Dali::Animation& source ); - + bool GetPropertyMapForVisual( Property::Index visualIndex, Property::Map& retreivedMap ) const; /** - * Resets the Button to the base state for the current paint state. - * Any additionally inserted images needed for transitions that are - * no longer needed and the removed. + * Returns the animation to be used for transition, creating the animation if needed. + * @return The initialised transition animation. */ - void ResetImageLayers(); + Dali::Animation GetTransitionAnimation(); /** - * Transitions out the actor + * @brief Set the position of the label relative to foreground/icon, if both present + * @param[in] labelAlignment given alignment setting */ - void TransitionOut( Actor actor ); + void SetLabelAlignment( Align labelAlignment); /** - * Removes the actor from the button and prepares it to be transitioned out + * @brief Get set alignment of label in relation to foreground/icon + * @return Set alignment value */ - void RemoveButtonImage( Actor& actor ); + Align GetLabelAlignment(); /** - * Finds the index of the actor. - * If the actor doesn't exist, return the last index + 1. + * Removes the visual from the button (un-staged) + * If the derived button does not want the visual removed then use this virtual function to + * define the required behaviour. + * Can decide to only remove specified visuals via index */ - unsigned int FindChildIndex( Actor& actor ); + virtual void OnButtonVisualRemoval( Property::Index visualIndex ); - /** - * Adds an actor to the hierarchy and prepares it to be transitioned. - * @param[in] actor The actor to add - */ - void PrepareAddButtonImage( Actor& actor ); - /** - * Adds an actor to the hierarchy and marks it to be transitioned. - * @param[in] actor The actor to add - */ - void TransitionButtonImage( Actor& actor ); +private: /** - * Adds an actor to the hierarchy. - * @param[in] actor The actor to add + * Removes the visual from the button and prepares it to be transitioned out + * @param[in] visualIndex the visual to remove */ - void AddButtonImage( Actor& actor ); + void RemoveVisual( Property::Index visualIndex ); /** - * (Re)Adds the label (if exists) to the hierarchy (so it is always on top). + * Adds the required visual to the button. + * @param[in] visualIndex The Property index of the visual required */ - void ReAddLabel(); + void SelectRequiredVisual( Property::Index visualIndex ); // Undefined Button( const Button& ); @@ -723,41 +652,34 @@ private: Toolkit::Button::ButtonSignalType mClickedSignal; ///< Signal emitted when the button is clicked. Toolkit::Button::ButtonSignalType mStateChangedSignal; ///< Signal emitted when the button's state is changed. - Timer mAutoRepeatingTimer; ///< Timer used to implement the autorepeating property. + Timer mAutoRepeatingTimer; - Actor mLabel; ///< Stores the button label. + Actor mLabel; ///< Stores the button text label. + Padding mLabelPadding; ///< The padding around the label (if present). + Padding mForegroundPadding; ///< The padding around the foreground/icon visual (if present). - Actor mDecoration[ DECORATION_STATES ]; ///< Stores the decorations for both selected and unselected states. + Align mTextLabelAlignment; ///< Position of text label in relation to foreground/icon when both are present. - Actor mUnselectedContent; ///< Stores the unselected content. - Actor mSelectedContent; ///< Stores the selected content. - Actor mBackgroundContent; ///< Stores the background content. - Actor mSelectedBackgroundContent; ///< Stores the selected background content. - Actor mDisabledContent; ///< Stores the disabled content. - Actor mDisabledSelectedContent; ///< Stores the disabled selected content. - Actor mDisabledBackgroundContent; ///< Stores the disabled background content. + TapGestureDetector mTapDetector; - Animation mTransitionAnimation; ///< Animation used in the state transitions. + Vector4 mUnselectedColor; + Vector4 mSelectedColor; - TapGestureDetector mTapDetector; + bool mAutoRepeating; ///< Stores the autorepeating property. + bool mTogglableButton; ///< Stores the togglable property as a flag. + bool mTextStringSetFlag; ///< Stores if text has been set. Required in relayout but don't want to calculate there. - Vector4 mUnselectedColor; ///< Color to use for unselected content. - Vector4 mSelectedColor; ///< Color to use for selected content. + float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds. + float mNextAutoRepeatingDelay; ///< Stores the next autorepeating delay in seconds. - bool mDisabled; ///< Stores the disabled property. - bool mAutoRepeating; ///< Stores the autorepeating property. - bool mTogglableButton; ///< Stores the togglable property. - bool mSelected; ///< Stores the selected state. - float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds. - float mNextAutoRepeatingDelay; ///< Stores the next autorepeating delay in seconds. + float mAnimationTime; - float mAnimationTime; ///< The animation time. + PressState mButtonPressedState; ///< In relation to the button being pressed/released + State mButtonState; + State mPreviousButtonState; ///< During a transition between two states, this stores the previous state so Visuals can be removed. // Actions - bool mClickActionPerforming; - - ButtonState mState; ///< Stores the button state. - PaintState mPaintState; ///< Stores the paint state. + bool mClickActionPerforming; ///< Used to manage signal emissions during action }; } // namespace Internal @@ -786,4 +708,4 @@ inline const Toolkit::Internal::Button& GetImplementation( const Toolkit::Button } // namespace Dali -#endif // __DALI_TOOLKIT_INTERNAL_BUTTON_H__ +#endif // DALI_TOOLKIT_INTERNAL_BUTTON_H