1 #ifndef __DALI_TOOLKIT_STYLE_MANAGER_H__
2 #define __DALI_TOOLKIT_STYLE_MANAGER_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
23 #include <dali/dali.h>
24 #include <dali-toolkit/public-api/controls/control.h>
26 namespace Dali DALI_IMPORT_API
32 namespace Internal DALI_INTERNAL
38 * @brief StyleManager provides the following functionalities:
40 * Applies various styles to Controls using the properties system.
41 * On theme change a signal is raised that controls can be configured to listen to.
43 * The default theme is automatically loaded and applied.
45 * If the application wants to customize the theme, RequestThemeChange needs to be called.
46 * Also, the default orientation is Portrait, if the application wants to adapt to the orientation change, call SetOrientation or SetOrienationValue.
48 * const char* CUSTOM_THEME = DALI_SCRIPT_DIR "tizen-dark-theme.json";
50 * void OnInit(Application& app)
52 * Toolkit::StyleManager::Get().RequestThemeChange( CUSTOM_THEME );
53 * Toolkit::StyleManager::Get().SetOrientation( app.GetOrientation() );
58 * Internal::Control can be configured to register for the signals that are required from StyleManager,
59 * such as theme change.
61 class StyleManager : public BaseHandle
66 typedef SignalV2< void ( StyleManager, StyleChange ) > StyleChangeSignalType;
69 * @brief Create a StyleManager handle; this can be initialised with StyleManager::Get()
70 * Calling member functions with an uninitialised handle is not allowed.
77 * This is non-virtual since derived Handle types must not contain data or virtual methods.
82 * @brief Get the singleton of StyleManager object.
84 * @return A handle to the StyleManager control.
86 static StyleManager Get();
89 * @brief Specify the orientation value directly for the style manager
91 * @param[in] orientation The orientation in degrees
93 void SetOrientationValue( int orientation );
96 * @brief Return the orientation value
98 * @return The orientation value
100 int GetOrientationValue();
103 * @brief Set the orientation object. This will take precedence over setting the orientation value.
105 * @param[in] orientation Device orientation
107 void SetOrientation( Orientation orientation );
110 * @brief Return the orientation object
112 * @return The orientation.
114 Orientation GetOrientation();
117 * @brief Make a request to set the theme JSON file to one that exists in the Toolkit package.
119 * Multiple requests per event processing cycle can be made, but only the final one will be acted
120 * on in the event processing finished callback.
122 * @param[in] themeFile This is just the JSON theme file name and not the full path.
124 void RequestThemeChange( const std::string& themeFile );
127 * @brief Request a change to the default theme
129 void RequestDefaultTheme();
132 * @brief Set a constant for use when building styles
134 * A constant is used in JSON files e.g. "my-image":"{ROOT_PATH}/mypath/image.jpg"
135 * where the string "{ROOT_PATH}" is substituted with the value.
137 * @param[in] key The key of the constant
138 * @param[in] value The value of the constant
140 void SetStyleConstant( const std::string& key, const Property::Value& value );
143 * @brief Return the style constant set for a specific key
145 * @param[in] key The key of the constant
146 * @param[out] valueOut The value of the constant if it exists
148 * @return If the constant for key exists then return the constant in valueOut and return true
150 bool GetStyleConstant( const std::string& key, Property::Value& valueOut );
153 * @brief Apply the specified style to the control.
155 * The JSON file will be cached and subsequent calls using the same JSON file name will
156 * use the already loaded cached values instead.
158 * @param[in] control The control to apply style.
159 * @param[in] jsonFileName The name of the JSON style file to apply.
160 * @param[in] styleName The name of the style within the JSON file to apply.
162 void ApplyStyle( Toolkit::Control control, const std::string& jsonFileName, const std::string& styleName );
167 * @brief This signal is emitted whenever the style (e.g. theme/font change) is changed on device
168 * A callback of the following type may be connected:
170 * void YourCallbackName( StyleManager styleManager, StyleChange change );
172 * @return The signal to connect to.
174 StyleChangeSignalType& StyleChangeSignal();
179 * @brief Creates a new handle from the implementation.
181 * @param[in] impl A pointer to the object.
183 explicit DALI_INTERNAL StyleManager( Internal::StyleManager *impl );
185 }; // class StyleManager
187 } // namespace Toolkit
192 #endif /* __DALI_TOOLKIT_STYLE_MANAGER_H__ */