/// <summary> /// /// </summary> /// <param name="parent"></param> public override void Apply(Component parent) { //Debug.Log("SetStyle->Apply: Name: " + Name + "; Value: " + Value); _appliedTarget = GetTarget(Target, parent); IStyleClient obj = ((IStyleClient)_appliedTarget); if (!Applied) { /** * IMPORTANT: obj.StyleDeclaration.GetStyle(Name) returns UNDEFINED * UNDEFINED is a flag indicating that the style ISN'T DEFINED in the style declaration (overrides) * That's because the null is a valid style value, so it cannot return null because we couldn't be * able to differentiate between the null (value) or undefined style * */ _wasInline = null != obj.StyleDeclaration && //StyleDeclaration.UNDEFINED != obj.StyleDeclaration.GetStyle(Name); !StyleDeclaration.UNDEFINED.Equals(obj.StyleDeclaration.GetStyle(Name)); // if it is the inline style remember its value, null otherwise (it doesn't metter, we won't use the old value in "Remove") _oldValue = _wasInline ? obj.GetStyle(Name) : null; } _relatedProps = GetRelatedProperties(_appliedTarget, Name); if (_relatedProps.Count > 0) { if (null == _oldRelatedValues) { _oldRelatedValues = new List <object>(); // lazily } else { _oldRelatedValues.Clear(); } foreach (string property in _relatedProps) { _oldRelatedValues.Add(new MemberProxy(_appliedTarget, property).GetValue()); } } // Set new value if (null == Value) { obj.ClearStyle(Name); // (??? why setting it to UNDEFINED? Does null for SetStyle object mean "clear property?") } else { obj.SetStyle(Name, Value); } Applied = true; }
/// <summary> /// Sets style /// </summary> /// <param name="client"></param> /// <param name="styleProp"></param> /// <param name="newValue"></param> public static void SetStyle(IStyleClient client, string styleProp, object newValue) { if (styleProp == "styleName") { // Let the setter handle this one, see Component. client.StyleName = styleProp; // Short circuit, because styleName isn't really a style. return; } bool isInheritingStyle = StyleManager.Instance.IsInheritingStyle(styleProp); bool isProtoChainInitialized = client.InheritingStyles != STYLE_UNINITIALIZED; bool valueChanged = client.GetStyle(styleProp) != newValue; /** * Čim setiramo stil na komponenti pomoću fje. setStyle(), to zahtijeva specijalnu deklaraciju vezanu uz komponentu * Deklaraciju inicijaliziramo ovdje * */ if (null == client.StyleDeclaration) { client.StyleDeclaration = new StyleDeclaration(null); client.StyleDeclaration.SetLocalStyle(styleProp, newValue); // If inheritingStyles is undefined, then this object is being // initialized and we haven't yet generated the proto chain. To // avoid redundant work, don't bother to create the proto chain here. if (isProtoChainInitialized) { client.RegenerateStyleCache(isInheritingStyle); } } else { client.StyleDeclaration.SetLocalStyle(styleProp, newValue); } if (isProtoChainInitialized && valueChanged) { client.StyleChanged(styleProp); client.NotifyStyleChangeInChildren(styleProp, newValue, isInheritingStyle); } }