From 6b8ba635f15d672e4773fac8d94b2ff2aa58e9b0 Mon Sep 17 00:00:00 2001 From: David Steele Date: Wed, 17 Aug 2016 19:20:47 +0100 Subject: [PATCH] Changed styles to use case-insensitive matching Modified style sheets to use capitalized names for the styles to aid readability. Match algorithm changes control / style name to lower case, then compares it to the style names that are also down-cased. Change-Id: I048da5a7b8d00350669d11d797fab93f148dbdac Signed-off-by: David Steele --- dali-toolkit/devel-api/builder/tree-node.cpp | 48 +++++++++++++++++++++- dali-toolkit/devel-api/builder/tree-node.h | 13 ++++-- dali-toolkit/internal/builder/builder-get-is.inl.h | 27 +++++++++++- dali-toolkit/internal/builder/builder-impl.cpp | 6 ++- .../text-controls/text-selection-popup-impl.cpp | 4 +- .../internal/styling/style-manager-impl.cpp | 6 +-- .../1920x1080/dali-toolkit-default-theme.json | 36 ++++++++-------- .../styles/480x800/dali-toolkit-default-theme.json | 44 ++++++++++---------- .../720x1280/dali-toolkit-default-theme.json | 44 ++++++++++---------- 9 files changed, 151 insertions(+), 77 deletions(-) diff --git a/dali-toolkit/devel-api/builder/tree-node.cpp b/dali-toolkit/devel-api/builder/tree-node.cpp index 302c7a2..6b0f6b3 100644 --- a/dali-toolkit/devel-api/builder/tree-node.cpp +++ b/dali-toolkit/devel-api/builder/tree-node.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +17,37 @@ // EXTERNAL INCLUDES #include +#include // INTERNAL INCLUDES #include "dali-toolkit/devel-api/builder/tree-node.h" #include "dali-toolkit/internal/builder/tree-node-manipulator.h" +namespace +{ + +bool CaseInsensitiveCharacterCompare( unsigned char a, unsigned char b ) +{ + // Converts to lower case in the current locale. + return std::tolower( a ) == std::tolower( b ); +} + +/** + * return true if the lower cased ASCII strings are equal. + */ +bool CaseInsensitiveStringCompare( const std::string& a, const std::string& b ) +{ + bool result = false; + if( a.length() == b.length() ) + { + result = std::equal( a.begin(), a.end(), b.begin(), CaseInsensitiveCharacterCompare ); + } + return result; +} + +} // anonymous namespace + + namespace Dali { @@ -80,7 +106,6 @@ bool TreeNode::GetBoolean() const return mIntValue == 1 ? true : false; } - size_t TreeNode::Size() const { size_t c = 0; @@ -120,6 +145,25 @@ const TreeNode* TreeNode::GetChild(const std::string& childName) const return NULL; } + +const TreeNode* TreeNode::GetChildIgnoreCase(const std::string& childName) const +{ + const TreeNode* p = mFirstChild; + while(p) + { + if(p->mName) + { + std::string nodeName(p->mName); + if( CaseInsensitiveStringCompare( nodeName, childName) ) + { + return p; + } + } + p = p->mNextSibling; + } + return NULL; +} + const TreeNode* TreeNode::Find(const std::string& childName) const { if(mName && std::string(mName) == childName) diff --git a/dali-toolkit/devel-api/builder/tree-node.h b/dali-toolkit/devel-api/builder/tree-node.h index 3e47aea..c63bf1f 100644 --- a/dali-toolkit/devel-api/builder/tree-node.h +++ b/dali-toolkit/devel-api/builder/tree-node.h @@ -2,7 +2,7 @@ #define __DALI_SCRIPT_TREE_NODE_H__ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -182,13 +182,20 @@ public: bool HasSubstitution() const; /* - * Gets a child of the node - * @param name The name of the child + * Gets a child of the node (using case sensitive matching) + * @param name The name of the child. * @return The child if found, else NULL */ const TreeNode* GetChild(const std::string& name) const; /* + * Gets a child of the node (using case insensitive matching) + * @param name The name of the child in lower case + * @return The child if found, else NULL + */ + const TreeNode* GetChildIgnoreCase(const std::string& name) const; + + /* * Recursively search for a child of the node * @param name The name of the child * @return The child if found, else NULL diff --git a/dali-toolkit/internal/builder/builder-get-is.inl.h b/dali-toolkit/internal/builder/builder-get-is.inl.h index d13b70b..ae17837 100644 --- a/dali-toolkit/internal/builder/builder-get-is.inl.h +++ b/dali-toolkit/internal/builder/builder-get-is.inl.h @@ -2,7 +2,7 @@ #define __DALI_TOOLKIT_INTERNAL_BUILDER_GET_IS_INL__ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,11 +41,36 @@ inline OptionalChild IsChild(const TreeNode* node, const std::string& childName) } } +inline OptionalChild IsChildIgnoreCase(const TreeNode* node, const std::string& childName) +{ + if( node ) + { + const TreeNode* c = node->GetChildIgnoreCase(childName); + if( NULL != c ) + { + return OptionalChild( *c ); + } + else + { + return OptionalChild(); + } + } + else + { + return OptionalChild(); + } +} + inline OptionalChild IsChild(const TreeNode& node, const std::string& childName) { return IsChild(&node, childName); } +inline OptionalChild IsChildIgnoreCase(const TreeNode& node, const std::string& childName) +{ + return IsChildIgnoreCase(&node, childName); +} + inline OptionalString IsString(const OptionalChild& node) { if( node && (*node).GetType() == TreeNode::STRING ) diff --git a/dali-toolkit/internal/builder/builder-impl.cpp b/dali-toolkit/internal/builder/builder-impl.cpp index 8203437..de3fbe1 100644 --- a/dali-toolkit/internal/builder/builder-impl.cpp +++ b/dali-toolkit/internal/builder/builder-impl.cpp @@ -117,7 +117,7 @@ void CollectAllStyles( const TreeNode& stylesCollection, const TreeNode& style, { if( OptionalString styleName = IsString( (*iter).second ) ) { - if( OptionalChild node = IsChild( stylesCollection, *styleName) ) + if( OptionalChild node = IsChildIgnoreCase( stylesCollection, *styleName) ) { styleList.push_back( &(*node) ); @@ -1231,7 +1231,9 @@ bool Builder::ApplyStyle( const std::string& styleName, Handle& handle, const Re DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded"); OptionalChild styles = IsChild( *mParser.GetRoot(), KEYNAME_STYLES ); - OptionalChild style = IsChild( *styles, styleName ); + + std::string styleNameLower(styleName); + OptionalChild style = IsChildIgnoreCase( *styles, styleNameLower ); if( styles && style ) { diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp index 1633dc9..2248668 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp @@ -49,7 +49,7 @@ namespace // todo Move this to adaptor?? #define GET_LOCALE_TEXT(string) dgettext("dali-toolkit", string) -const std::string TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME( "textselectionpopupbutton" ); +const std::string TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME( "TextSelectionPopupButton" ); const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 1.0f ) ); #if defined(DEBUG_ENABLED) @@ -836,5 +836,3 @@ TextSelectionPopup::~TextSelectionPopup() } // namespace Toolkit } // namespace Dali - - diff --git a/dali-toolkit/internal/styling/style-manager-impl.cpp b/dali-toolkit/internal/styling/style-manager-impl.cpp index 7e08cf4..d1fa388 100644 --- a/dali-toolkit/internal/styling/style-manager-impl.cpp +++ b/dali-toolkit/internal/styling/style-manager-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ namespace const char* LANDSCAPE_QUALIFIER = "landscape"; const char* PORTRAIT_QUALIFIER = "portrait"; -const char* FONT_SIZE_QUALIFIER = "FontSize"; +const char* FONT_SIZE_QUALIFIER = "fontsize"; const char* DEFAULT_THEME = DALI_STYLE_DIR "dali-toolkit-default-theme.json"; @@ -332,9 +332,7 @@ void StyleManager::ApplyStyle( Toolkit::Builder builder, Toolkit::Control contro 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) diff --git a/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json b/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json index a6ded0d..8f472d8 100644 --- a/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json @@ -28,7 +28,7 @@ { "styles": { - "textlabel": + "TextLabel": { "pointSize":108, "enableAutoScroll":false, @@ -37,28 +37,28 @@ "autoScrollSpeed":80 }, - "textlabelFontSize0": + "TextLabelFontSize0": { "pointSize":84 }, - "textlabelFontSize1": + "TextLabelFontSize1": { "pointSize":96 }, - "textlabelFontSize2": + "TextLabelFontSize2": { "pointSize":108 }, - "textlabelFontSize3": + "TextLabelFontSize3": { "pointSize":120 }, - "textlabelFontSize4": + "TextLabelFontSize4": { "pointSize":132 }, - "textfield": + "TextField": { "pointSize":120, "primaryCursorColor":[0.0,0.72,0.9,1.0], @@ -70,27 +70,27 @@ "selectionHandleImageRight": {"filename":"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png" } }, - "textfieldFontSize0": + "TextFieldFontSize0": { "pointSize":120 }, - "textfieldFontSize1": + "TextFieldFontSize1": { "pointSize":120 }, - "textfieldFontSize2": + "TextFieldFontSize2": { "pointSize":120 }, - "textfieldFontSize3": + "TextFieldFontSize3": { "pointSize":120 }, - "textfieldFontSize4": + "TextFieldFontSize4": { "pointSize":120 }, - "textselectionpopup": + "TextSelectionPopup": { "popupMaxSize":[1700,100], "optionDividerSize":[2,0], @@ -104,7 +104,7 @@ "popupFadeInDuration":0.25, "popupFadeOutDuration":0.25 }, - "textselectionpopupbutton": + "TextSelectionPopupButton": { "label": { @@ -112,7 +112,7 @@ "fontStyle":"{\"weight\":\"light\"}" } }, - "textselectiontoolbar": + "TextSelectionToolbar": { "enableOvershoot":true, "scrollView": @@ -121,19 +121,19 @@ "overshootSize":[1920.0,130.0] } }, - "scrollview": + "ScrollView": { "overshootEffectColor":"B018", "overshootAnimationSpeed":960.0, "overshootSize":[1920.0,130.0] }, - "itemview": + "ItemView": { "overshootEffectColor":"B018", "overshootAnimationSpeed":960.0, "overshootSize":[1920.0,130.0] }, - "texteditor": + "TextEditor": { "pointSize":120, "primaryCursorColor":[0.0,0.72,0.9,1.0], diff --git a/dali-toolkit/styles/480x800/dali-toolkit-default-theme.json b/dali-toolkit/styles/480x800/dali-toolkit-default-theme.json index fd8e1a4..6d9eb61 100644 --- a/dali-toolkit/styles/480x800/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/480x800/dali-toolkit-default-theme.json @@ -28,7 +28,7 @@ { "styles": { - "textlabel": + "TextLabel": { "pointSize":18, "enableAutoScroll":false, @@ -37,27 +37,27 @@ "autoScrollSpeed":80 }, - "textlabelFontSize0": + "TextLabelFontSize0": { "pointSize":8 }, - "textlabelFontSize1": + "TextLabelFontSize1": { "pointSize":10 }, - "textlabelFontSize2": + "TextLabelFontSize2": { "pointSize":15 }, - "textlabelFontSize3": + "TextLabelFontSize3": { "pointSize":19 }, - "textlabelFontSize4": + "TextLabelFontSize4": { "pointSize":25 }, - "radiobutton": + "RadioButton": { "unselectedStateImage":"{DALI_IMAGE_DIR}radio-button-unselected.png", "selectedStateImage":"{DALI_IMAGE_DIR}radio-button-selected.png", @@ -65,7 +65,7 @@ "disabledSelectedStateImage":"{DALI_IMAGE_DIR}radio-button-selected-disabled.png" }, - "textfield": + "TextField": { "pointSize":18, "primaryCursorColor":[0.0,0.72,0.9,1.0], @@ -77,27 +77,27 @@ "selectionHandleImageRight": {"filename":"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png" } }, - "textfieldFontSize0": + "TextFieldFontSize0": { "pointSize":10 }, - "textfieldFontSize1": + "TextFieldFontSize1": { "pointSize":10 }, - "textfieldFontSize2": + "TextFieldFontSize2": { "pointSize":10 }, - "textfieldFontSize3": + "TextFieldFontSize3": { "pointSize":10 }, - "textfieldFontSize4": + "TextFieldFontSize4": { "pointSize":10 }, - "textselectionpopup": + "TextSelectionPopup": { "popupMaxSize":[400,100], "optionDividerSize":[2,0], @@ -111,7 +111,7 @@ "popupFadeInDuration":0.25, "popupFadeOutDuration":0.25 }, - "textselectionpopupbutton": + "TextSelectionPopupButton": { "label": { @@ -119,7 +119,7 @@ "fontStyle":"{\"weight\":\"light\"}" } }, - "textselectiontoolbar": + "TextSelectionToolbar": { "enableOvershoot":true, "scrollView": @@ -128,19 +128,19 @@ "overshootSize":[480.0,42.0] } }, - "scrollview": + "ScrollView": { "overshootEffectColor":"B018", "overshootAnimationSpeed":120.0, "overshootSize":[480.0,42.0] }, - "itemview": + "ItemView": { "overshootEffectColor":"B018", "overshootAnimationSpeed":120.0, "overshootSize":[480.0,42.0] }, - "texteditor": + "TextEditor": { "pointSize":18, "primaryCursorColor":[0.0,0.72,0.9,1.0], @@ -151,15 +151,15 @@ "selectionHandleImageLeft" : {"filename":"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_left.png" }, "selectionHandleImageRight": {"filename":"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png" } }, - "popup": + "Popup": { "popupBackgroundImage":"{DALI_IMAGE_DIR}00_popup_bg.9.png" }, - "confirmationpopup": + "ConfirmationPopup": { "popupBackgroundImage":"{DALI_IMAGE_DIR}00_popup_bg.9.png" }, - "slider": + "Slider": { "showPopup": true, "showValue": true, diff --git a/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json b/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json index 0a6f61f..25b2375 100644 --- a/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json @@ -28,7 +28,7 @@ { "styles": { - "textlabel": + "TextLabel": { "pointSize":18, "enableAutoScroll":false, @@ -37,27 +37,27 @@ "autoScrollSpeed":80 }, - "textlabelFontSize0": + "TextLabelFontSize0": { "pointSize":8 }, - "textlabelFontSize1": + "TextLabelFontSize1": { "pointSize":10 }, - "textlabelFontSize2": + "TextLabelFontSize2": { "pointSize":15 }, - "textlabelFontSize3": + "TextLabelFontSize3": { "pointSize":19 }, - "textlabelFontSize4": + "TextLabelFontSize4": { "pointSize":25 }, - "radiobutton": + "RadioButton": { "unselectedStateImage":"{DALI_IMAGE_DIR}radio-button-unselected.png", "selectedStateImage":"{DALI_IMAGE_DIR}radio-button-selected.png", @@ -65,7 +65,7 @@ "disabledSelectedStateImage":"{DALI_IMAGE_DIR}radio-button-selected-disabled.png" }, - "textfield": + "TextField": { "pointSize":18, "primaryCursorColor":[0.0,0.72,0.9,1.0], @@ -77,27 +77,27 @@ "selectionHandleImageRight": {"filename":"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png" } }, - "textfieldFontSize0": + "TextFieldFontSize0": { "pointSize":10 }, - "textfieldFontSize1": + "TextFieldFontSize1": { "pointSize":10 }, - "textfieldFontSize2": + "TextFieldFontSize2": { "pointSize":10 }, - "textfieldFontSize3": + "TextFieldFontSize3": { "pointSize":10 }, - "textfieldFontSize4": + "TextFieldFontSize4": { "pointSize":10 }, - "textselectionpopup": + "TextSelectionPopup": { "popupMaxSize":[656,72], "optionDividerSize":[2,0], @@ -111,7 +111,7 @@ "popupFadeInDuration":0.25, "popupFadeOutDuration":0.25 }, - "textselectionpopupbutton": + "TextSelectionPopupButton": { "label": { @@ -119,7 +119,7 @@ "fontStyle":"{\"weight\":\"light\"}" } }, - "textselectiontoolbar": + "TextSelectionToolbar": { "enableOvershoot":true, "scrollView": @@ -128,19 +128,19 @@ "overshootSize":[720.0,130.0] } }, - "scrollview": + "ScrollView": { "overshootEffectColor":"B018", "overshootAnimationSpeed":360.0, "overshootSize":[720.0,130.0] }, - "itemview": + "ItemView": { "overshootEffectColor":"B018", "overshootAnimationSpeed":360.0, "overshootSize":[720.0,130.0] }, - "texteditor": + "TextEditor": { "pointSize":18, "primaryCursorColor":[0.0,0.72,0.9,1.0], @@ -151,15 +151,15 @@ "selectionHandleImageLeft" : {"filename":"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_left.png" }, "selectionHandleImageRight": {"filename":"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png" } }, - "popup": + "Popup": { "popupBackgroundImage":"{DALI_IMAGE_DIR}00_popup_bg.9.png" }, - "confirmationpopup": + "ConfirmationPopup": { "popupBackgroundImage":"{DALI_IMAGE_DIR}00_popup_bg.9.png" }, - "slider": + "Slider": { "showPopup": true, "showValue": true, -- 2.7.4