public void AttributeDictionary_Add_DuplicateKey() { // Arrange var attributes = new AttributeDictionary(); attributes.Add("zero", "0"); attributes.Add("one", "1"); attributes.Add("two", "2"); // Act & Assert Assert.Throws<InvalidOperationException>(() => attributes.Add("one", "15")); }
public void AttributeDictionary_Clear() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act attributes.Clear(); // Assert Assert.Equal(0, attributes.Count); Assert.Empty(attributes); }
public void AttributeDictionary_AddItems_AsKeyValuePairs() { // Arrange var attributes = new AttributeDictionary(); // Act attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Assert Assert.Equal(3, attributes.Count); Assert.Collection( attributes, kvp => Assert.Equal(new KeyValuePair<string, string>("one", "1"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("two", "2"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("zero", "0"), kvp)); }
public void AttributeDictionary_CaseInsensitive() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act attributes["oNe"] = "1!"; // Assert Assert.Equal(3, attributes.Count); Assert.Collection( attributes, kvp => Assert.Equal(new KeyValuePair<string, string>("oNe", "1!"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("two", "2"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("zero", "0"), kvp)); }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { }
internal Insert() : base(EntityType.Insert, DxfObjectCode.Insert) { this.endSequence = new EndSequence(); this.attributes = new AttributeDictionary(); }
public static AttributeDictionary AppendCssClass(this AttributeDictionary attributes, Func <string> cssClass) { attributes.AppendInValue("class", ' ', cssClass()); return(attributes); }
public override void Apply(XmlElement xmlElement, string value, AttributeDictionary elementAttributes) { var isActive = value.ToBoolean(); xmlElement.gameObject.SetActive(isActive); }
internal Insert() : base (EntityType.Insert, DxfObjectCode.Insert) { this.endSequence = new EndSequence(); this.attributes = new AttributeDictionary(); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn protected override BaseMessage BuildBaseMessage(object messageType, string messageName, int round) /// /// \brief Builds base message. /// /// \brief #### Description. /// This method is called when there is a decision to send a base message /// in order to build the base message /// /// \brief #### Algorithm. /// /// \brief #### Usage Notes. /// The base class method generate a message with the type and one field for the message name /// /// \author Ilan Hindy /// \date 28/02/2017 /// /// \param messageType Type of the message. /// \param messageName Name of the message. /// \param round The round. /// /// \return A BaseMessage. //////////////////////////////////////////////////////////////////////////////////////////////////// protected override BaseMessage BuildBaseMessage(object messageType, string messageName, AttributeDictionary messageFields, int round, AttributeList targets) { return(base.BuildBaseMessage(messageType, messageName, messageFields, round, targets)); }
protected override void InitPrivateAttributes() { AttributeDictionary dictionary = pa; base.InitPrivateAttributes(); }
/// <summary> /// Constructs a new instance of XmlNode /// </summary> /// <param name="name">The name of the node</param> public XmlNode(string name) { this.name = name; this.attributes = new AttributeDictionary(); this.childNodes = new NodeList(); }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { MatchParentDimensions(); base.ApplyAttributes(attributesToApply); }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); var inputField = primaryComponent as InputField; var textComponents = new List <Text> { inputField.textComponent }; if (inputField.placeholder != null) { var placeholderText = inputField.placeholder.GetComponent <Text>(); if (placeholderText != null) { textComponents.Add(placeholderText); } if (attributesToApply.ContainsKey("placeholdertext")) { placeholderText.text = StringExtensions.DecodeEncodedNonAsciiCharacters(attributesToApply["placeholdertext"]); } } foreach (var textComponent in textComponents) { var tagHandler = XmlLayoutUtilities.GetXmlTagHandler("Text"); tagHandler.SetInstance(textComponent.rectTransform, this.currentXmlLayoutInstance); var textAttributes = new AttributeDictionary( attributesToApply.Where(a => TextTagHandler.TextAttributes.Contains(a.Key, StringComparer.OrdinalIgnoreCase)) .ToDictionary(a => a.Key, b => b.Value)); if (attributesToApply.ContainsKey("textshadow")) { textAttributes.Add("shadow", attributesToApply["textshadow"]); } if (attributesToApply.ContainsKey("textoutline")) { textAttributes.Add("outline", attributesToApply["textoutline"]); } if (attributesToApply.ContainsKey("textcolor")) { textAttributes.Add("color", attributesToApply["textcolor"]); } if (attributesToApply.ContainsKey("textalignment")) { textAttributes.Add("alignment", attributesToApply["textalignment"]); } textAttributes.Remove("text"); if (attributesToApply.ContainsKey("textoffset")) { var offset = attributesToApply["textoffset"].ToRectOffset(); textAttributes.Add("offsetMin", String.Format("{0} {1}", offset.left, offset.bottom)); textAttributes.Add("offsetMax", String.Format("-{0} -{1}", offset.right, offset.top)); } tagHandler.ApplyAttributes(textAttributes); } }
public override void Open(AttributeDictionary elementAttributes) { currentInstanceTransform.gameObject.AddComponent <RawImage>(); }
public CandyGridRow() { Attributes = new AttributeDictionary(StateHasChanged); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn protected override BaseMessage BuildBaseAlgorithmMessage(dynamic messageType, string messageName, AttributeDictionary messageFields, int round, AttributeList targets) /// /// \brief Builds base message. /// /// \par Description. /// - This method is called in execution time. /// - The purpose of this method is to allow the algorithm to add fields to the Base Algorithm message /// - The following is the process of sending a base algorithm message /// -# During running time before/after a send/receive message the event is checked /// -# If the conditions are filled up this method is called with the base message data /// -# This message can add fields to the Base Message according to the status of the algorithm /// -# The base message is sent /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilan Hindy /// \date 02/03/2017 /// /// \param messageType (dynamic) - Type of the message. /// \param messageName (string) - Name of the message. /// \param messageFields (AttributeDictionary) - The message fields. /// \param round (int) - The round. /// \param targets (List<Attribute>) - The targets. /// /// \return A BaseMessage. //////////////////////////////////////////////////////////////////////////////////////////////////// public override BaseMessage BuildBaseAlgorithmMessage(dynamic messageType, string messageName, AttributeDictionary messageFields, int round, AttributeList targets) { BaseMessage message = new BaseMessage(network, messageType, messageFields, new BaseChannel(), messageName, round); return(message); }
public void AttributeDictionary_Indexer_Success() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act var value = attributes["two"]; // Assert Assert.Equal("2", value); }
protected override void InitOperationResults() { AttributeDictionary dictionary = or; base.InitOperationResults(); }
public void AttributeDictionary_Indexer_Insert() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act attributes["exciting!"] = "1!"; // Assert Assert.Equal(4, attributes.Count); Assert.Collection( attributes, kvp => Assert.Equal(new KeyValuePair<string, string>("exciting!", "1!"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("one", "1"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("two", "2"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("zero", "0"), kvp)); }
public override void Apply(XmlElement xmlElement, string value, AttributeDictionary elementAttributes) { base.Apply(xmlElement, value, elementAttributes); uResize.ResizeListenerColor = value.ToColor(); }
/// <summary> /// Initializes a new instance of the <c>Insert</c> class. /// </summary> /// <param name="block">Insert block definition.</param> /// <param name="position">Insert <see cref="Vector3">point</see> in world coordinates.</param> public Insert(Block block, Vector3 position) : base(EntityType.Insert, DxfObjectCode.Insert) { if (block == null) throw new ArgumentNullException("block"); this.block = block; this.position = position; this.scale = new Vector3(1.0); this.rotation = 0.0; this.endSequence = new EndSequence(); List<Attribute> atts = new List<Attribute>(block.AttributeDefinitions.Count); foreach (AttributeDefinition attdef in block.AttributeDefinitions.Values) { Attribute att = new Attribute(attdef) { Position = attdef.Position + this.position - this.block.Position, Owner = this }; atts.Add(att); } this.attributes = new AttributeDictionary(atts); }
public override void Apply(XmlElement xmlElement, string value, AttributeDictionary elementAttributes) { base.Apply(xmlElement, value, elementAttributes); uResize.ResizeListenerThickness = value.ToFloat(); }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); var toggle = primaryComponent as Toggle; var checkMark = toggle.graphic as Image; var textComponent = currentXmlElement.GetComponentInChildren <Text>(); if (currentXmlElement.childElements.Any()) { var childAttributes = new AttributeDictionary(); var child = currentXmlElement.childElements.First(); if (child.tagType == "Text") { // Replace the original text component with the child element child.rectTransform.SetParent(textComponent.rectTransform.parent); if (Application.isPlaying) { GameObject.Destroy(textComponent.gameObject); } else { GameObject.DestroyImmediate(textComponent.gameObject); } textComponent = child.GetComponent <Text>(); if (!child.HasAttribute("alignment")) { childAttributes.Add("alignment", "MiddleLeft"); } } #if TEXTMESHPRO_PRESENT else if (child.tagType == "TextMeshPro") { // Replace the original text component with the child element child.rectTransform.SetParent(textComponent.rectTransform.parent); if (Application.isPlaying) { GameObject.Destroy(textComponent.gameObject); } else { GameObject.DestroyImmediate(textComponent.gameObject); } if (!child.HasAttribute("alignment")) { childAttributes.Add("alignment", "Left"); } } #endif if (!child.HasAttribute("text")) { if (attributesToApply.ContainsKey("text")) { childAttributes.Add("text", attributesToApply["text"]); } else { // if the child has no text, and the parent has no text, disable the text component if (!currentXmlElement.HasAttribute("text")) { childAttributes.Add("active", "false"); } } } else { // override the parent value if need be attributesToApply.SetValue("text", child.GetAttribute("text")); } // default padding value as per standard toggle element if (!child.HasAttribute("padding")) { childAttributes.Add("padding", "23 5 2 1"); } if (!child.HasAttribute("flexibleWidth")) { childAttributes.Add("flexibleWidth", "1"); } if (childAttributes.Any()) { child.ApplyAttributes(childAttributes); } } if (attributesToApply.ContainsKey("checkcolor")) { checkMark.color = attributesToApply["checkcolor"].ToColor(); } var targetGraphic = toggle.targetGraphic as Image; if (attributesToApply.ContainsKey("togglewidth")) { var width = float.Parse(attributesToApply["togglewidth"]); /*targetGraphic.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width); * checkMark.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width); * * if (textComponent != null) * { * textComponent.rectTransform.localPosition = new Vector2(width, textComponent.rectTransform.localPosition.y); * }*/ var toggleLayoutElement = targetGraphic.GetComponent <LayoutElement>() ?? targetGraphic.gameObject.AddComponent <LayoutElement>(); toggleLayoutElement.preferredWidth = width; toggleLayoutElement.minWidth = width; } if (attributesToApply.ContainsKey("toggleheight")) { var height = float.Parse(attributesToApply["toggleheight"]); /*targetGraphic.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height); * checkMark.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);*/ var toggleLayoutElement = targetGraphic.GetComponent <LayoutElement>() ?? targetGraphic.gameObject.AddComponent <LayoutElement>(); toggleLayoutElement.preferredHeight = height; toggleLayoutElement.minHeight = height; } if (ToggleGroupTagHandler.CurrentToggleGroupInstance != null) { var xmlLayoutToggleGroupInstance = ToggleGroupTagHandler.CurrentToggleGroupInstance; xmlLayoutToggleGroupInstance.AddToggle(toggle); xmlLayoutToggleGroupInstance.UpdateToggleElement(toggle); toggle.onValueChanged.AddListener((e) => { if (e) { var value = xmlLayoutToggleGroupInstance.GetValueForElement(toggle); xmlLayoutToggleGroupInstance.SetSelectedValue(value); } }); } // Text attributes if (textComponent != null) { // disable the text component if there is no text textComponent.gameObject.SetActive(!String.IsNullOrEmpty(textComponent.text)); var tagHandler = XmlLayoutUtilities.GetXmlTagHandler("Text"); tagHandler.SetInstance(textComponent.rectTransform, this.currentXmlLayoutInstance); var textAttributes = new AttributeDictionary( attributesToApply.Where(a => TextTagHandler.TextAttributes.Contains(a.Key, StringComparer.OrdinalIgnoreCase)) .ToDictionary(a => a.Key, b => b.Value)); if (attributesToApply.ContainsKey("textshadow")) { textAttributes.Add("shadow", attributesToApply["textshadow"]); } if (attributesToApply.ContainsKey("textoutline")) { textAttributes.Add("outline", attributesToApply["textoutline"]); } if (attributesToApply.ContainsKey("textcolor")) { textAttributes.Add("color", attributesToApply["textcolor"]); } tagHandler.ApplyAttributes(textAttributes); // disable the XmlElement component, it can interfere with mouse clicks/etc. textComponent.GetComponent <XmlElement>().enabled = false; } if (!attributesToApply.ContainsKey("text") && !currentXmlElement.attributes.ContainsKey("text")) { var background = (Image)toggle.targetGraphic; var backgroundTransform = background.rectTransform; if (!attributesToApply.ContainsKey("dontModifyBackground")) { backgroundTransform.anchorMin = new Vector2(0.5f, 0.5f); backgroundTransform.anchorMax = new Vector2(0.5f, 0.5f); backgroundTransform.anchoredPosition3D = new Vector3(0, 0, 0); } } if (attributesToApply.ContainsKey("togglebackgroundimage")) { targetGraphic.sprite = attributesToApply["togglebackgroundimage"].ToSprite(); } if (attributesToApply.ContainsKey("togglecheckmarkimage")) { checkMark.sprite = attributesToApply["togglecheckmarkimage"].ToSprite(); } if (attributesToApply.ContainsKey("togglecheckmarkimagepreserveaspect")) { checkMark.preserveAspect = attributesToApply["togglecheckmarkimagepreserveaspect"].ToBoolean(); } if (attributesToApply.ContainsKey("togglecheckmarksize")) { float checkSize = float.Parse(attributesToApply["togglecheckmarksize"]); //var checkMarkLayoutElement = checkMark.GetComponent<LayoutElement>(); //checkMarkLayoutElement.preferredWidth = checkSize; //checkMarkLayoutElement.preferredHeight = checkSize; checkMark.rectTransform.anchorMin = new Vector2(0.5f, 0.5f); checkMark.rectTransform.anchorMax = new Vector2(0.5f, 0.5f); checkMark.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, checkSize); checkMark.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, checkSize); } }
public void AttributeDictionary_ContainsKey_Failure() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act var result = attributes.ContainsKey("one!"); // Assert Assert.False(result); }
public void SendWave(AttributeDictionary fields, SelectingMethod selectingMethod = SelectingMethod.All, List <int> ids = null) { Send(m.MessageTypes.Wave, fields, selectingMethod, ids, 0, 0); }
public void AttributeDictionary_IsReadOnly() { // Arrange var attributes = new AttributeDictionary(); // Act var result = attributes.IsReadOnly; // Assert Assert.False(result); }
public static AttributeDictionary PrependCssClass(this AttributeDictionary attributes, string cssClass) { attributes.PrependInValue("class", ' ', cssClass); return(attributes); }
public void AttributeDictionary_TryGetValue_Success() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); string value; // Act var result = attributes.TryGetValue("two", out value); // Assert Assert.True(result); Assert.Equal("2", value); }
public override void Apply(XmlElement xmlElement, string value, AttributeDictionary elementAttributes) { base.Apply(xmlElement, value, elementAttributes); uResize.AspectRatioControl = (eAspectRatioMode)Enum.Parse(typeof(eAspectRatioMode), value); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public BaseMessage(BaseNetwork network, dynamic messageType, AttributeDictionary fields, BaseChannel channel, string messageName = "" , int round, int logicalClock):base(true) /// /// \brief Constructor. /// /// \par Description. /// Create a message from : /// -# The messageType /// -# Fields for the algorithm specific fields in attribute dictionary. /// -# The sending parameters from the channel /// -# The message name /// -# The parameters for the header : round, logical clock /// /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 14/03/2017 /// /// \param network (BaseNetwork) - The network. /// \param messageType (dynamic) - Type of the message. /// \param fields (AttributeDictionary) - The fields. /// \param channel (BaseChannel) - The channel. /// \param messageName (Optional) (string) - Name of the message. /// \param round (Optional) (int) - The round. /// \param logicalClock (Optional) (int) - The logical clock. //////////////////////////////////////////////////////////////////////////////////////////////////// public BaseMessage(BaseNetwork network, dynamic messageType, AttributeDictionary fields, BaseChannel channel, string messageName = "", int round = 0, int logicalClock = 0) : base(true) { InitElementAttributes(0); this.network = network; pa.Add(bm.pak.MessageType, new Attribute { Value = messageType }); try { pa.Add(bm.pak.SourceProcess, new Attribute { Value = channel.ea[bc.eak.SourceProcess] }); pa.Add(bm.pak.SourcePort, new Attribute { Value = channel.or[bc.ork.SourcePort], IncludedInShortDescription = false, IncludeInEqualsTo = false }); pa.Add(bm.pak.DestProcess, new Attribute { Value = channel.ea[bc.eak.DestProcess] }); pa.Add(bm.pak.DestPort, new Attribute { Value = channel.or[bc.ork.DestPort], IncludedInShortDescription = false, IncludeInEqualsTo = false }); } catch { pa.Add(bm.pak.SourceProcess, new Attribute { Value = 0 }); pa.Add(bm.pak.SourcePort, new Attribute { Value = 0, IncludedInShortDescription = false, IncludeInEqualsTo = false }); pa.Add(bm.pak.DestProcess, new Attribute { Value = 0 }); pa.Add(bm.pak.DestPort, new Attribute { Value = 0, IncludedInShortDescription = false, IncludeInEqualsTo = false }); } pa.Add(bm.pak.Round, new Attribute { Value = round }); pa.Add(bm.pak.LogicalClock, new Attribute { Value = logicalClock }); if (messageName == "") { messageName = TypesUtility.GetKeyToString(messageType); } or.Add(bm.ork.Name, new Attribute { Value = messageName }); op.Add(bm.opk.Breakpoints, new Attribute { Value = new Breakpoint(Breakpoint.HostingElementTypes.Message), Editable = false, IncludedInShortDescription = false }); or.Add(bm.ork.PositionInProcessQ, new Attribute { Value = 0, IncludedInShortDescription = false }); if (fields != null) { foreach (var entry in fields) { AddField(entry.Key, entry.Value); } } }
public void AttributeDictionary_CopyTo() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); var array = new KeyValuePair<string, string>[attributes.Count + 1]; // Act attributes.CopyTo(array, 1); // Assert Assert.Collection( array, kvp => Assert.Equal(default(KeyValuePair<string, string>), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("one", "1"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("two", "2"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("zero", "0"), kvp)); }
public override void Apply(XmlElement xmlElement, string value, AttributeDictionary elementAttributes) { base.Apply(xmlElement, value, elementAttributes); uResize.DesiredAspectRatio = value.ToVector2(); }
public void AttributeDictionary_Remove_KeyValuePair_Failure() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act var result = attributes.Remove(new KeyValuePair<string, string>("one", "0")); // Assert Assert.False(result); Assert.Equal(3, attributes.Count); Assert.Collection( attributes, kvp => Assert.Equal(new KeyValuePair<string, string>("one", "1"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("two", "2"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("zero", "0"), kvp)); }
public override void Apply(XmlElement xmlElement, string value, AttributeDictionary elementAttributes) { base.Apply(xmlElement, value, elementAttributes); uResize.enabled = value.ToBoolean(); }
public void AttributeDictionary_TryGetValue_Failure() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); string value; // Act var result = attributes.TryGetValue("nada", out value); // Assert Assert.False(result); Assert.Null(value); }
public override void Apply(XmlElement xmlElement, string value, AttributeDictionary elementAttributes) { base.Apply(xmlElement, value, elementAttributes); uResize.AllowResizeFromTopRight = value.ToBoolean(); }
public void AttributeDictionary_Values() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act var values = attributes.Values; // Assert Assert.Equal(3, values.Count); Assert.Collection( values, key => Assert.Equal("1", key), key => Assert.Equal("2", key), key => Assert.Equal("0", key)); }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); var dropdown = primaryComponent as Dropdown; var templateComponent = dropdown.template.GetComponent <Image>(); var itemTemplateComponent = dropdown.template.GetComponentInChildren <Toggle>(); var textComponent = dropdown.captionText; var textTagHandler = XmlLayoutUtilities.GetXmlTagHandler("Text"); textTagHandler.SetInstance(textComponent.rectTransform, this.currentXmlLayoutInstance); var textAttributes = new AttributeDictionary( attributesToApply.Where(a => TextTagHandler.TextAttributes.Contains(a.Key, StringComparer.OrdinalIgnoreCase)) .ToDictionary(a => a.Key, b => b.Value)); if (attributesToApply.ContainsKey("textshadow")) { textAttributes.Add("shadow", attributesToApply["textshadow"]); } if (attributesToApply.ContainsKey("textoutline")) { textAttributes.Add("outline", attributesToApply["textoutline"]); } if (attributesToApply.ContainsKey("textcolor")) { textAttributes.Add("color", attributesToApply["textcolor"]); } if (attributesToApply.ContainsKey("textalignment")) { textAttributes.Add("alignment", attributesToApply["textalignment"]); } textTagHandler.ApplyAttributes(textAttributes); // disable the XmlElement component, it can interfere with mouse clicks/etc. textComponent.GetComponent <XmlElement>().enabled = false; var xmlLayoutDropdown = dropdown.GetComponent <XmlLayoutDropdown>(); var arrow = xmlLayoutDropdown.Arrow; if (attributesToApply.ContainsKey("arrowimage")) { arrow.sprite = attributesToApply["arrowimage"].ToSprite(); } if (attributesToApply.ContainsKey("arrowcolor")) { arrow.color = attributesToApply["arrowcolor"].ToColor(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("arrowOffset")) { arrow.rectTransform.anchoredPosition = attributesToApply["arrowOffset"].ToVector2(); } // dropdownHeight property if (attributesToApply.ContainsKey("dropdownheight")) { dropdown.template.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, float.Parse(attributesToApply["dropdownheight"])); } // Apply text attributes to the item template var itemTemplate = xmlLayoutDropdown.ItemTemplate; var itemTagHandler = XmlLayoutUtilities.GetXmlTagHandler("Toggle"); var itemAttributes = attributesToApply.Clone(); if (attributesToApply.ContainsKey("itemheight")) { var itemHeight = float.Parse(attributesToApply["itemheight"]); (itemTemplate.transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, itemHeight); // it's also necessary to set the height of the content transform, otherwise we end up with weird issues var contentTransform = templateComponent.GetComponentInChildren <ScrollRect>().content; contentTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, itemHeight); } /* * // This isn't working yet - it looks like the Dropdown code may be overriding this value * if (attributesToApply.ContainsKey("itemWidth")) * { * var itemWidth = attributesToApply["itemWidth"].ToFloat(); * (itemTemplate.transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, itemWidth); * } */ if (attributesToApply.ContainsKey("checkcolor")) { itemAttributes.Add("togglecheckmarkcolor", attributesToApply["checkcolor"]); } if (attributesToApply.ContainsKey("checksize")) { itemAttributes.Add("togglecheckmarksize", attributesToApply["checksize"]); } if (attributesToApply.ContainsKey("checkimage")) { itemAttributes.Add("togglecheckmarkimage", attributesToApply["checkimage"]); } if (attributesToApply.ContainsKey("checkimagepreserveaspect")) { itemAttributes.Add("togglecheckmarkimagepreserveaspect", attributesToApply["checkimagepreserveaspect"]); } // don't attempt to apply data source attributes to the item template itemAttributes.Remove("vm-dataSource"); itemAttributes.Remove("vm-options"); itemAttributes.Remove("color"); itemAttributes.Remove("colors"); // this attribute is checked by the Toggle to see if changes to the background should be permitted // (used by regular toggles to center the background if there is no text) itemAttributes.Add("dontModifyBackground", String.Empty); var itemXmlElement = itemTemplate.transform.GetComponent <XmlElement>(); if (itemXmlElement == null) { itemTagHandler.SetInstance(itemTemplate.transform as RectTransform, this.currentXmlLayoutInstance); itemTagHandler.ApplyAttributes(itemAttributes); itemXmlElement = itemTemplate.transform.GetComponent <XmlElement>(); } else { itemXmlElement.ApplyAttributes(itemAttributes); } if (itemXmlElement != null) { itemXmlElement.enabled = false; } if (attributesToApply.ContainsKey("itembackgroundcolors")) { itemTemplateComponent.colors = attributesToApply["itembackgroundcolors"].ToColorBlock(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("dropdownbackgroundcolor")) { dropdown.template.GetComponent <Image>().color = attributesToApply["dropdownbackgroundcolor"].ToColor(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("dropdownbackgroundimage")) { dropdown.template.GetComponent <Image>().sprite = attributesToApply["dropdownbackgroundimage"].ToSprite(); } if (attributesToApply.ContainsKey("itemtextcolor")) { var itemTextComponent = dropdown.itemText; itemTextComponent.color = attributesToApply["itemtextcolor"].ToColor(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("scrollbarcolors")) { xmlLayoutDropdown.DropdownScrollbar.colors = attributesToApply["scrollbarcolors"].ToColorBlock(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("scrollbarimage")) { xmlLayoutDropdown.DropdownScrollbar.image.sprite = attributesToApply["scrollbarimage"].ToSprite(); } if (attributesToApply.ContainsKey("scrollbarbackgroundcolor")) { xmlLayoutDropdown.DropdownScrollbar.GetComponent <Image>().color = attributesToApply["scrollbarbackgroundcolor"].ToColor(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("scrollbarbackgroundimage")) { xmlLayoutDropdown.DropdownScrollbar.GetComponent <Image>().sprite = attributesToApply["scrollbarbackgroundimage"].ToSprite(); } if (attributesToApply.ContainsKey("scrollsensitivity")) { dropdown.template.GetComponent <ScrollRect>().scrollSensitivity = attributesToApply["scrollsensitivity"].ToFloat(); } foreach (var attribute in attributesToApply) { SetPropertyValue(templateComponent, attribute.Key, attribute.Value); } // data source #if !ENABLE_IL2CPP && MVVM_ENABLED if (attributesToApply.ContainsKey("vm-options")) { xmlLayoutDropdown.optionsDataSource = attributesToApply["vm-options"]; } if (attributesToApply.ContainsKey("vm-dataSource")) { HandleDataSourceAttribute(attributesToApply.GetValue("vm-dataSource"), attributesToApply.GetValue("vm-options")); } #endif }
public void AttributeDictionary_Indexer_Fails() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act & Assert Assert.Throws<KeyNotFoundException>(() => attributes["nada"]); }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { var dropdownTransform = currentXmlElement.rectTransform.Find("Template") as RectTransform; var layoutElement = currentInstanceTransform.GetComponent <LayoutElement>(); if (layoutElement == null) { layoutElement = currentInstanceTransform.gameObject.AddComponent <LayoutElement>(); } // apply attributes as per usual base.ApplyAttributes(attributesToApply); if (ElementHasAttribute("dropdownheight", attributesToApply)) { dropdownTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, float.Parse(attributesToApply["dropdownheight"])); } var itemTemplate = CurrentDropdown.itemText.rectTransform.parent as RectTransform; if (ElementHasAttribute("itemHeight", attributesToApply)) { var itemHeight = float.Parse(currentXmlElement.GetAttribute("itemheight")); (itemTemplate.transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, itemHeight); // it's also necessary to set the height of the content transform, otherwise we end up with weird issues var contentTransform = currentXmlElement.rectTransform.Find("Template/Viewport/Content") as RectTransform; contentTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, itemHeight); } if (attributesToApply.ContainsKey("itemWidth")) { var itemWidth = attributesToApply["itemWidth"].ToFloat(); (itemTemplate.transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, itemWidth); } var arrow = currentXmlElement.rectTransform.Find("Arrow").GetComponent <Image>(); if (attributesToApply.ContainsKey("arrowImage")) { arrow.sprite = attributesToApply["arrowImage"].ToSprite(); } if (attributesToApply.ContainsKey("arrowColor")) { arrow.color = attributesToApply["arrowColor"].ToColor(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("arrowOffset")) { arrow.rectTransform.anchoredPosition = attributesToApply["arrowOffset"].ToVector2(); } if (attributesToApply.ContainsKey("itemBackgroundColors")) { var toggle = itemTemplate.GetComponent <Toggle>(); toggle.colors = attributesToApply["itemBackgroundColors"].ToColorBlock(currentXmlLayoutInstance); } var dropdownBackground = dropdownTransform.GetComponent <Image>(); if (attributesToApply.ContainsKey("dropdownBackgroundColor")) { dropdownBackground.color = attributesToApply["dropdownBackgroundColor"].ToColor(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("dropdownBackgroundImage")) { dropdownBackground.sprite = attributesToApply["dropdownBackgroundImage"].ToSprite(); } var scrollbar = dropdownTransform.GetComponentInChildren <Scrollbar>(); var scrollbarImage = scrollbar.targetGraphic as Image; if (attributesToApply.ContainsKey("scrollbarColors")) { scrollbar.colors = attributesToApply["scrollbarColors"].ToColorBlock(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("scrollbarImage")) { scrollbarImage.sprite = attributesToApply["scrollbarImage"].ToSprite(); } var scrollbarBackground = scrollbar.GetComponent <Image>(); if (attributesToApply.ContainsKey("scrollbarBackgroundColor")) { scrollbarBackground.color = attributesToApply["scrollbarBackgroundColor"].ToColor(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("scrollbarBackgroundImage")) { scrollbarBackground.sprite = attributesToApply["scrollbarBackgroundImage"].ToSprite(); } if (attributesToApply.ContainsKey("scrollbarWidth")) { scrollbar.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, attributesToApply["scrollbarWidth"].ToFloat()); } if (attributesToApply.ContainsKey("padding")) { var padding = attributesToApply["padding"].ToVector4(); var itemLabelTransform = currentInstanceTransform.Find("Label") as RectTransform; itemLabelTransform.offsetMin = new Vector2(padding.x, padding.w); itemLabelTransform.offsetMax = new Vector2(-padding.y, -padding.z); } var checkMark = itemTemplate.Find("Item Checkmark").GetComponent <Image>(); if (attributesToApply.ContainsKey("checkColor")) { checkMark.color = attributesToApply["checkColor"].ToColor(currentXmlLayoutInstance); } else { checkMark.color = new Color(0, 0, 0); } if (attributesToApply.ContainsKey("checkImage")) { checkMark.sprite = attributesToApply["checkImage"].ToSprite(); } else { checkMark.sprite = XmlLayoutUtilities.LoadResource <Sprite>("Sprites/Elements/Checkmark"); } if (attributesToApply.ContainsKey("checkSize")) { var size = attributesToApply["checkSize"].ToFloat(); checkMark.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size); checkMark.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size); } if (attributesToApply.ContainsKey("checkImagePreserveAspect")) { checkMark.preserveAspect = attributesToApply["checkMarkImagePreserveAspect"].ToBoolean(); } // data source #if !ENABLE_IL2CPP && MVVM_ENABLED if (attributesToApply.ContainsKey("vm-options")) { var xmlLayoutDropdown = currentXmlElement.GetComponent <XmlLayoutDropdown>(); xmlLayoutDropdown.optionsDataSource = attributesToApply["vm-options"]; } if (attributesToApply.ContainsKey("vm-dataSource")) { HandleDataSourceAttribute(attributesToApply.GetValue("vm-dataSource"), attributesToApply.GetValue("vm-options")); } #endif }
public override void Open(AttributeDictionary elementAttributes) { base.Open(elementAttributes); currentInstanceTransform.name = "TextMeshPro - Dropdown"; CurrentHandler = this; var tmpDropdown = currentInstanceTransform.GetComponent <TMP_Dropdown>(); if (tmpDropdown == null) { tmpDropdown = currentInstanceTransform.gameObject.AddComponent <TMP_Dropdown>(); tmpDropdown.ClearOptions(); } tmpDropdown.targetGraphic = tmpDropdown.GetComponent <Image>(); var labelTransform = currentInstanceTransform.Find("Label") as RectTransform; var label = labelTransform.GetComponent <TextMeshProUGUI>(); if (label == null) { label = labelTransform.gameObject.AddComponent <TextMeshProUGUI>(); label.color = new Color(0.2f, 0.2f, 0.2f); label.fontSize = 14; label.alignment = TextAlignmentOptions.Left; } var dropdownTransform = currentXmlElement.rectTransform.Find("Template") as RectTransform; // if we don't make the template active while we set the dimensions, then TextMesh Pro will override them later dropdownTransform.gameObject.SetActive(true); var itemLabelTransform = currentInstanceTransform.Find("Template/Viewport/Content/Item/Item Label") as RectTransform; var itemLabel = itemLabelTransform.GetComponentInChildren <TextMeshProUGUI>(); if (itemLabel == null) { itemLabel = itemLabelTransform.gameObject.AddComponent <TextMeshProUGUI>(); itemLabel.alignment = TextAlignmentOptions.Left; itemLabel.color = new Color(0.2f, 0.2f, 0.2f); itemLabel.fontSize = 14; } tmpDropdown.template = dropdownTransform; tmpDropdown.captionText = label; tmpDropdown.itemText = itemLabel; labelTransform.anchorMin = Vector2.zero; labelTransform.anchorMax = Vector2.one; labelTransform.offsetMin = new Vector2(10, 6); labelTransform.offsetMax = new Vector2(-25, -7); itemLabelTransform.anchorMin = Vector2.zero; itemLabelTransform.anchorMax = Vector2.one; itemLabelTransform.offsetMin = new Vector2(20, 1); itemLabelTransform.offsetMax = new Vector2(-20, -2); var itemLabelXmlElement = itemLabelTransform.GetComponent <XmlElement>() ?? itemLabelTransform.gameObject.AddComponent <XmlElement>(); itemLabelXmlElement.SetAttribute("alignment", "MidlineLeft"); itemLabelXmlElement.SetAttribute("offsetMin", "20,1"); itemLabelXmlElement.SetAttribute("offsetMax", "-20,-2"); // disable the template again dropdownTransform.gameObject.SetActive(false); }
internal protected SequenceItemReadElement() : base() { attributeDictionary = new AttributeDictionary(); redirectList = new RedirectList(); explicitIndex = -1; }
public void AttributeDictionary_Contains_Success() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act var result = attributes.Contains(new KeyValuePair<string, string>("zero", "0")); // Assert Assert.True(result); }
public override void Open(AttributeDictionary elementAttributes) { base.Open(elementAttributes); currentInstanceTransform.name = "TextMeshPro - Input Field"; }
/// <summary> /// Updates the actual insert with the attribute properties currently defined in the block. This does not affect any values assigned to attributes in each block. /// </summary> /// <remarks>This method will automatically call the TransformAttributes method, to keep all attributes position and orientation up to date.</remarks> public void Sync() { List<Attribute> atts = new List<Attribute>(this.block.AttributeDefinitions.Count); // remove all attributes that are not present in the actual insert foreach (Attribute att in this.attributes.Values) { if (!this.block.AttributeDefinitions.ContainsTag(att.Tag)) { this.OnAttributeRemovedEvent(att); att.Handle = null; att.Owner = null; } } // add any new attribute that might have been added to the block foreach (AttributeDefinition attdef in this.block.AttributeDefinitions.Values) { if (this.attributes.ContainsTag(attdef.Tag)) { atts.Add(this.attributes[attdef.Tag]); } else { Attribute att = new Attribute(attdef) { Owner = this }; atts.Add(att); this.OnAttributeAddedEvent(att); } } this.attributes = new AttributeDictionary(atts); this.TransformAttributes(); }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { var backgroundImage = currentInstanceTransform.GetComponent <Image>(); if (backgroundImage == null) { CreateBackgroundImage(); } var textArea = currentInstanceTransform.Find("Text Area") as RectTransform; if (textArea == null) { textArea = CreateTextArea(); } if (attributesToApply.ContainsKey("padding")) { var padding = attributesToApply["padding"].ToVector4(); textArea.offsetMin = new Vector2(padding.x, padding.w); textArea.offsetMax = new Vector2(-padding.y, -padding.z); } var placeHolderTransform = textArea.Find("Placeholder") as RectTransform; if (placeHolderTransform == null) { placeHolderTransform = CreatePlaceholder(textArea); } var textTransform = textArea.Find("Text") as RectTransform; if (textTransform == null) { textTransform = CreateText(textArea); } var tmpInputField = currentInstanceTransform.GetComponent <TMP_InputField>(); if (tmpInputField == null) { tmpInputField = CreateTMPInputField(); } var text = textTransform.GetComponent <TextMeshProUGUI>(); tmpInputField.textViewport = textArea; tmpInputField.textComponent = text; tmpInputField.placeholder = placeHolderTransform.GetComponent <TextMeshProUGUI>(); // we need to manually call OnEnable on the input field, // as it performs setup functionality which doesn't work // if the textComponent hasn't been set yet (which it isn't if the object is created dynamically) if (Application.isPlaying) { tmpInputField.SendMessage("OnEnable", SendMessageOptions.DontRequireReceiver); } var layoutElement = currentInstanceTransform.GetComponent <LayoutElement>(); if (layoutElement == null) { layoutElement = currentInstanceTransform.gameObject.AddComponent <LayoutElement>(); } base.ApplyAttributes(attributesToApply); var textElement = text.GetComponent <XmlElement>(); if (textElement == null) { textElement = text.gameObject.AddComponent <XmlElement>(); } //var shouldSetTextElementTextDirectly = tmpInputField.contentType != TMP_InputField.ContentType.Password && tmpInputField.contentType != TMP_InputField.ContentType.Pin; //tmpInputField.text = .GetAttribute("text") ?? String.Empty; /*if (ElementHasAttribute("text", attributesToApply)) * { * if (!textElement.HasAttribute("text") && shouldSetTextElementTextDirectly) * { * text.text = currentXmlElement.GetAttribute("text") ?? String.Empty; * } * } * else * { * tmpInputField.text = textElement.GetAttribute("text") ?? String.Empty; * }*/ // Override the text value of the TMP with the value from the input field // This is only necessary if the user has provided a text value for both /*if (shouldSetTextElementTextDirectly) * { * XmlLayoutTimer.AtEndOfFrame(() => textElement.GetComponent<TextMeshProUGUI>().text = tmpInputField.text, textElement, true); * }*/ }
public ResourceDefinition SetAttribute(string name, string value) { if (Attributes == null) { Attributes = new AttributeDictionary(); } Attributes[name] = value; return this; }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); var scrollView = (ScrollRect)primaryComponent; if (attributesToApply.ContainsKey("noscrollbars") && attributesToApply["noscrollbars"].ToBoolean()) { if (scrollView.verticalScrollbar != null) { Destroy(scrollView.verticalScrollbar.gameObject); scrollView.verticalScrollbar = null; } if (scrollView.horizontalScrollbar != null) { Destroy(scrollView.horizontalScrollbar.gameObject); scrollView.horizontalScrollbar = null; } } scrollView.viewport.offsetMax = new Vector2(); scrollView.viewport.offsetMin = new Vector2(); var hasVerticalScrollbar = scrollView.verticalScrollbar != null; var hasHorizontalScrollbar = scrollView.horizontalScrollbar != null; if (attributesToApply.ContainsKey("scrollbarbackgroundcolor")) { var color = attributesToApply["scrollbarbackgroundcolor"].ToColor(currentXmlLayoutInstance); if (hasVerticalScrollbar) { scrollView.verticalScrollbar.GetComponent <Image>().color = color; } if (hasHorizontalScrollbar) { scrollView.horizontalScrollbar.GetComponent <Image>().color = color; } } if (attributesToApply.ContainsKey("scrollbarbackgroundimage")) { var image = attributesToApply["scrollbarbackgroundimage"].ToSprite(); if (hasVerticalScrollbar) { scrollView.verticalScrollbar.GetComponent <Image>().sprite = image; } if (hasHorizontalScrollbar) { scrollView.horizontalScrollbar.GetComponent <Image>().sprite = image; } } if (attributesToApply.ContainsKey("scrollbarcolors")) { var colors = attributesToApply["scrollbarcolors"].ToColorBlock(currentXmlLayoutInstance); if (hasVerticalScrollbar) { scrollView.verticalScrollbar.colors = colors; } if (hasHorizontalScrollbar) { scrollView.horizontalScrollbar.colors = colors; } } if (attributesToApply.ContainsKey("scrollbarimage")) { var image = attributesToApply["scrollbarimage"].ToSprite(); if (hasVerticalScrollbar) { scrollView.verticalScrollbar.image.sprite = image; } if (hasHorizontalScrollbar) { scrollView.horizontalScrollbar.image.sprite = image; } } if (hasVerticalScrollbar) { if (attributesToApply.ContainsKey("verticalscrollbarwidth")) { var scrollbarWidth = float.Parse(attributesToApply["verticalscrollbarwidth"]); (scrollView.viewport.transform as RectTransform).offsetMax = new Vector2(-scrollbarWidth, 0); (scrollView.verticalScrollbar.transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth); } else { (scrollView.viewport.transform as RectTransform).offsetMax = new Vector2(-17, 0); } } if (hasHorizontalScrollbar) { if (attributesToApply.ContainsKey("horizontalscrollbarheight")) { var scrollbarheight = float.Parse(attributesToApply["horizontalscrollbarheight"]); (scrollView.viewport.transform as RectTransform).offsetMin = new Vector2(0, scrollbarheight); (scrollView.horizontalScrollbar.transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, scrollbarheight); } else { (scrollView.viewport.transform as RectTransform).offsetMin = new Vector2(0, 17); } } if (attributesToApply.ContainsKey("maskimage")) { var viewportImage = scrollView.viewport.GetComponent <Image>(); var maskImageName = attributesToApply["maskimage"]; if (!string.IsNullOrEmpty(maskImageName)) { viewportImage.sprite = maskImageName.ToSprite(); } else { viewportImage.sprite = null; } } /* * // ScrollRect just overrides this value * if (attributes.ContainsKey("scrollbarsize")) * { * var size = float.Parse(attributes["scrollbarsize"]); * if (hasVerticalScrollbar) scrollView.verticalScrollbar.size = size; * if (hasHorizontalScrollbar) scrollView.horizontalScrollbar.size = size; * }*/ }