From: Paul Wisbey
Date: Wed, 25 Mar 2015 19:30:39 +0000 (+0000)
Subject: Basic support for style names
X-Git-Tag: dali_1.0.38~11^2~26
X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=e6b7228703163899cf4bf4648a12ac5dbf73807d
Basic support for style names
Change-Id: I72bccc4a06bb3852ae16ec74cf4916dfce6a541f
---
diff --git a/dali-toolkit/internal/styling/style-manager-impl.cpp b/dali-toolkit/internal/styling/style-manager-impl.cpp
index 60fa868..4378e84 100644
--- a/dali-toolkit/internal/styling/style-manager-impl.cpp
+++ b/dali-toolkit/internal/styling/style-manager-impl.cpp
@@ -248,9 +248,13 @@ void StyleManager::BuildQualifiedStyleName( const std::string& styleName, const
void StyleManager::ApplyStyle( Toolkit::Builder builder, Toolkit::Control control )
{
- // Convert control name to lower case
- std::string styleName = control.GetTypeName();
- std::transform( styleName.begin(), styleName.end(), styleName.begin(), ::tolower );
+ std::string styleName = control.GetStyleName();
+ if( styleName.empty() )
+ {
+ // Convert control name to lower case
+ styleName = control.GetTypeName();
+ std::transform( styleName.begin(), styleName.end(), styleName.begin(), ::tolower );
+ }
// Apply the style after choosing the correct actual style (e.g. landscape or portrait)
StringList qualifiers;
diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp
index 21b2a4d..d88afec 100644
--- a/dali-toolkit/public-api/controls/control-impl.cpp
+++ b/dali-toolkit/public-api/controls/control-impl.cpp
@@ -242,6 +242,7 @@ public:
// Construction & Destruction
Impl(Control& controlImpl)
: mControlImpl( controlImpl ),
+ mStyleName(""),
mBackground( NULL ),
mStartingPinchScale( NULL ),
mKeyEventSignal(),
@@ -323,6 +324,12 @@ public:
switch ( index )
{
+ case Toolkit::Control::Property::STYLE_NAME:
+ {
+ controlImpl.SetStyleName( value.Get< std::string >() );
+ break;
+ }
+
case Toolkit::Control::Property::BACKGROUND_COLOR:
{
controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
@@ -407,6 +414,12 @@ public:
switch ( index )
{
+ case Toolkit::Control::Property::STYLE_NAME:
+ {
+ value = controlImpl.GetStyleName();
+ break;
+ }
+
case Toolkit::Control::Property::BACKGROUND_COLOR:
{
value = controlImpl.GetBackgroundColor();
@@ -545,6 +558,7 @@ public:
// Data
Control& mControlImpl;
+ std::string mStyleName;
Background* mBackground; ///< Only create the background if we use it
Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
Toolkit::Control::KeyEventSignalType mKeyEventSignal;
@@ -575,16 +589,18 @@ public:
static PropertyRegistration PROPERTY_5;
static PropertyRegistration PROPERTY_6;
static PropertyRegistration PROPERTY_7;
+ static PropertyRegistration PROPERTY_8;
};
// Properties registered without macro to use specific member variables.
-PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "width-policy", Toolkit::Control::Property::WIDTH_POLICY, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "height-policy", Toolkit::Control::Property::HEIGHT_POLICY, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "minimum-size", Toolkit::Control::Property::MINIMUM_SIZE, Property::VECTOR3, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "maximum-size", Toolkit::Control::Property::MAXIMUM_SIZE, Property::VECTOR3, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "width-policy", Toolkit::Control::Property::WIDTH_POLICY, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "height-policy", Toolkit::Control::Property::HEIGHT_POLICY, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "minimum-size", Toolkit::Control::Property::MINIMUM_SIZE, Property::VECTOR3, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "maximum-size", Toolkit::Control::Property::MAXIMUM_SIZE, Property::VECTOR3, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
Toolkit::Control Control::New()
{
@@ -759,6 +775,23 @@ LongPressGestureDetector Control::GetLongPressGestureDetector() const
return mImpl->mLongPressGestureDetector;
}
+void Control::SetStyleName( const std::string& styleName )
+{
+ if( styleName != mImpl->mStyleName )
+ {
+ mImpl->mStyleName = styleName;
+
+ // Apply new style
+ Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
+ GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
+ }
+}
+
+const std::string& Control::GetStyleName() const
+{
+ return mImpl->mStyleName;
+}
+
void Control::SetBackgroundColor( const Vector4& color )
{
Background& background( mImpl->GetBackground() );
@@ -1093,7 +1126,6 @@ Control::Control( ControlBehaviour behaviourFlags )
void Control::Initialize()
{
-
// Calling deriving classes
OnInitialize();
diff --git a/dali-toolkit/public-api/controls/control-impl.h b/dali-toolkit/public-api/controls/control-impl.h
index 09c035c..928fda1 100644
--- a/dali-toolkit/public-api/controls/control-impl.h
+++ b/dali-toolkit/public-api/controls/control-impl.h
@@ -214,6 +214,16 @@ public:
// Background
/**
+ * @copydoc Dali::Toolkit::Control::SetStyleName
+ */
+ void SetStyleName( const std::string& styleName );
+
+ /**
+ * @copydoc Dali::Toolkit::Control::GetStyleName
+ */
+ const std::string& GetStyleName() const;
+
+ /**
* @copydoc Dali::Toolkit::Control::SetBackgroundColor
*/
void SetBackgroundColor( const Vector4& color );
diff --git a/dali-toolkit/public-api/controls/control.cpp b/dali-toolkit/public-api/controls/control.cpp
index b987ade..0721ff9 100644
--- a/dali-toolkit/public-api/controls/control.cpp
+++ b/dali-toolkit/public-api/controls/control.cpp
@@ -149,6 +149,16 @@ LongPressGestureDetector Control::GetLongPressGestureDetector() const
return GetImplementation().GetLongPressGestureDetector();
}
+void Control::SetStyleName( const std::string& styleName )
+{
+ GetImplementation().SetStyleName( styleName );
+}
+
+const std::string& Control::GetStyleName() const
+{
+ return GetImplementation().GetStyleName();
+}
+
void Control::SetBackgroundColor( const Vector4& color )
{
GetImplementation().SetBackgroundColor( color );
diff --git a/dali-toolkit/public-api/controls/control.h b/dali-toolkit/public-api/controls/control.h
index af840cd..6e88177 100644
--- a/dali-toolkit/public-api/controls/control.h
+++ b/dali-toolkit/public-api/controls/control.h
@@ -82,7 +82,8 @@ public:
{
enum
{
- BACKGROUND_COLOR = PROPERTY_START_INDEX, ///< name "background-color", @see SetBackgroundColor, type Vector4
+ STYLE_NAME = PROPERTY_START_INDEX, ///< name "style-name", @see SetStyleName, type std::string
+ BACKGROUND_COLOR, ///< name "background-color", @see SetBackgroundColor, type Vector4
BACKGROUND, ///< name "background", @see SetBackground, type Map
WIDTH_POLICY, ///< name "width-policy", @see SetSizePolicy, type std::string
HEIGHT_POLICY, ///< name "height-policy", @see SetSizePolicy, type std::string
@@ -344,6 +345,22 @@ public:
// Background
/**
+ * @brief Sets the name of the style to be applied to the control.
+ *
+ * @param[in] styleName A string matching a style described in a stylesheet.
+ */
+ void SetStyleName( const std::string& styleName );
+
+ /**
+ * @brief Retrieves the name of the style to be applied to the control (if any).
+ *
+ * @return A string matching a style or an empty string.
+ */
+ const std::string& GetStyleName() const;
+
+ // Background
+
+ /**
* @brief Sets the background color of the control.
*
* @param[in] color The required background color of the control