X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=dali-toolkit%2Finternal%2Fbuilder%2Fstyle.cpp;h=b834b13aa4e1208d0d78a3884e45b6a1d2bd85a5;hb=HEAD;hp=eaf59dcfd172f362d4da8b75f92650fede8ae1b2;hpb=a3b69d118ee5f918a827b23ea76813a7aefad845;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/builder/style.cpp b/dali-toolkit/internal/builder/style.cpp index eaf59dc..b834b13 100644 --- a/dali-toolkit/internal/builder/style.cpp +++ b/dali-toolkit/internal/builder/style.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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. @@ -14,10 +14,13 @@ * limitations under the License. */ -#include -#include #include #include +#include +#include +#include +#include +#include namespace Dali { @@ -25,47 +28,54 @@ namespace Toolkit { namespace Internal { +extern const Dali::Scripting::StringEnum ControlStateTable[]; +extern const unsigned int ControlStateTableCount; StylePtr Style::New() { - StylePtr stylePtr( new Style() ); + StylePtr stylePtr(new Style()); return stylePtr; } -void Style::ApplyVisualsAndPropertiesRecursively( Handle handle ) const +void Style::ApplyVisualsAndPropertiesRecursively( + Handle handle, + const Dictionary& instancedProperties) const { - ApplyVisuals( handle ); - ApplyProperties( handle ); + ApplyVisuals(handle, instancedProperties); + ApplyProperties(handle); Toolkit::Control control = Toolkit::Control::DownCast(handle); - if( control ) + if(control) { - Property::Value value = control.GetProperty(DevelControl::Property::STATE); - std::string stateName; - if( value.Get( stateName ) ) + std::string stateName; + Property::Value value = control.GetProperty(DevelControl::Property::STATE); + Dali::Toolkit::DevelControl::State state = static_cast(value.Get()); + stateName = Scripting::GetEnumerationName(state, ControlStateTable, ControlStateTableCount); + + if(!stateName.empty()) { // Look up state in states table: - const StylePtr* stylePtr = subStates.FindCaseInsensitiveC( stateName ); - if( stylePtr ) + const StylePtr* stylePtr = subStates.FindConst(stateName); + if(stylePtr) { const StylePtr statePtr(*stylePtr); // We have a state match. - statePtr->ApplyVisuals( handle ); - statePtr->ApplyProperties( handle ); + statePtr->ApplyVisuals(handle, instancedProperties); + statePtr->ApplyProperties(handle); // Apply substate visuals Property::Value value = control.GetProperty(DevelControl::Property::SUB_STATE); - std::string subStateName; - if( value.Get( subStateName ) && ! subStateName.empty() ) + std::string subStateName; + if(value.Get(subStateName) && !subStateName.empty()) { - const StylePtr* stylePtr = statePtr->subStates.FindCaseInsensitiveC( subStateName ); - if( stylePtr ) + const StylePtr* stylePtr = statePtr->subStates.FindConst(subStateName); + if(stylePtr) { const StylePtr subStatePtr(*stylePtr); // We have a sub-state match. - subStatePtr->ApplyVisuals( handle ); - subStatePtr->ApplyProperties( handle ); + subStatePtr->ApplyVisuals(handle, instancedProperties); + subStatePtr->ApplyProperties(handle); } } } @@ -73,29 +83,77 @@ void Style::ApplyVisualsAndPropertiesRecursively( Handle handle ) const } } -void Style::ApplyVisuals( Handle handle ) const +void Style::ApplyVisuals( + Handle handle, + const Dictionary& instancedProperties) const +{ + ApplyVisuals(handle, visuals, instancedProperties); +} + +void Style::ApplyVisuals( + Handle handle, + const Dictionary& visualMaps, + const Dictionary& instancedProperties) +{ + for(Dictionary::iterator iter = visualMaps.Begin(); iter != visualMaps.End(); ++iter) + { + const std::string& visualName = (*iter).key; + Property::Map map = (*iter).entry; + Property::Map* instancedMap = instancedProperties.Find(visualName); + ApplyVisual(handle, visualName, map, instancedMap); + } +} + +void Style::ApplyVisual( + Handle handle, + const std::string& visualName, + const Property::Map& visualMap, + const Property::Map* instancedProperties) { - for( Dictionary::iterator iter = visuals.Begin(); iter != visuals.End() ; ++iter ) + // Check if this visual name is a valid property of handle + Dali::Property::Index index = handle.GetPropertyIndex(visualName); + if(index != Property::INVALID_INDEX) { - const std::string& visualName = (*iter).key; - const Property::Map& map = (*iter).entry; - Dali::Property::Index index = handle.GetPropertyIndex( visualName ); - if( index != Property::INVALID_INDEX ) + const Property::Map* applyMap = &visualMap; + Property::Map mergedMap; + + // If there are instanced properties, and the visual types match, + // merge them into the visual map + if(instancedProperties) { - const Property::Value value(const_cast(map)); - handle.SetProperty( index, value ); + Property::Value* instanceTypeValue = instancedProperties->Find(Toolkit::Visual::Property::TYPE); + Property::Value* newTypeValue = visualMap.Find(Toolkit::Visual::Property::TYPE, VISUAL_TYPE); + if(instanceTypeValue && newTypeValue) + { + int instanceVisualType = -1; + int newVisualType = -1; + Scripting::GetEnumerationProperty(*instanceTypeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, instanceVisualType); + Scripting::GetEnumerationProperty(*newTypeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, newVisualType); + + if(instanceVisualType == newVisualType) + { + // Same type - merge remaining instance data + mergedMap.Merge(visualMap); + mergedMap.Merge(*instancedProperties); + applyMap = &mergedMap; + } + } } + + // Apply the visual property map to the handle + const Property::Value value(const_cast(*applyMap)); + handle.SetProperty(index, value); } } -void Style::ApplyProperties( Handle handle ) const +void Style::ApplyProperties(Handle handle) const { - for( Property::Map::SizeType i=0; i