StyleData

We found 10 examples in language CSharp for this search. You will see 31 fragments of code.

        private static void SaveTiles(StyleData styleData, ZipStorer zip, CancellableContext context)
        {
            var tilesCount = styleData.TileData.Length / (64 * 64);
            for (var i = 0; i < tilesCount; i++)
            {
                if (context.IsCancelling)
                    return;
                SaveTile(styleData, zip, ref i);
            }
        }


        private static void SaveTiles(StyleData styleData, ZipStorer zip, CancellableContext context)
        {
            var tilesCount = styleData.TileData.Length / (64 * 64);
            for (var i = 0; i < tilesCount; i++)
            {
                if (context.IsCancelling)
                    return;
                SaveTile(styleData, zip, ref i);
            }
        }



		#region Random Data Generation
		/*
		 * This code will be deleted in the final version
		 */
		public void GenerateRandomData()
		{
			GenerateRandomIndexes();
			if (StyleData.AnnotationTemplates.Count != 0)
			{
				GetRandomAnnotations();
				if (StyleData.RelationTemplates.Count != 0)
					GetRandomRelations();
			}
		}
		private void GetRandomAnnotations()
		{
			Random rnd = new Random();

			foreach (var item in randomNumbers)
			{
				AnnotationTemplate template = StyleData.AnnotationTemplates[rnd.Next(0, StyleData.AnnotationTemplates.Count)];

				SentenceData.AddAnnotation(template, item);
			}
		}

		#endregion

		#region Annotation Templates
		public void AddAnnotation()
		{
			if (string.IsNullOrEmpty(AnnotationName) || Color is null)
				return;

			var newTemplate = new AnnotationTemplate(AnnotationName, Color.Brush);
			if (!StyleData.AddAnnotationTemplate(newTemplate))
				MessageBox.Show("Duplicates are not allowed.", "", MessageBoxButton.OK, MessageBoxImage.Information);
			else
				SelectedAnnotationTemplate = newTemplate;
		}
		public void RemoveAnnotation()
		{
			if (SelectedAnnotationTemplate is null)
				return;

			StyleData.RemoveAnnotationTemplate(SelectedAnnotationTemplate);
			if (StyleData.AnnotationTemplates.Count != 0)
				SelectedAnnotationTemplate = StyleData.AnnotationTemplates[StyleData.AnnotationTemplates.Count - 1];
		}
		public void ExportAnnotations()
		{
			var saveFileDialog = new SaveFileDialog { Filter = fileDialogFilter };
			if (saveFileDialog.ShowDialog() != true)
				return;

			var exported = TemplateExporter.ExportAnnotations(StyleData.AnnotationTemplates);
			FileWriter.WriteFile(saveFileDialog.FileName, exported);
		}
		#endregion

		#region Relation Templates
		public void AddRelation()
		{
			if (string.IsNullOrEmpty(RelationName))
				return;
			var newTemplate = new RelationTemplate(RelationName, null, null);

			if (!StyleData.AddRelationTemplate(newTemplate))
				MessageBox.Show("Duplicates are not allowed.", "", MessageBoxButton.OK, MessageBoxImage.Information);
			else
				SelectedRelationTemplate = newTemplate;
		}
		public void RemoveRelation()
		{
			if (SelectedRelationTemplate is null)
				return;
			StyleData.RemoveRelationTemplate(SelectedRelationTemplate);

			if (StyleData.RelationTemplates.Count != 0)
				SelectedRelationTemplate = StyleData.RelationTemplates[StyleData.RelationTemplates.Count - 1];
		}

		public void ExportRelations()
		{
			var saveFileDialog = new SaveFileDialog { Filter = fileDialogFilter };
			if (saveFileDialog.ShowDialog() != true)
				return;

			var exported = TemplateExporter.ExportRelations(StyleData.RelationTemplates);
			FileWriter.WriteFile(saveFileDialog.FileName, exported);
		}


        private static void SaveTiles(StyleData styleData, ZipStorer zip, CancellableContext context)
        {
            var tilesCount = styleData.TileData.Length / (64 * 64);
            for (var i = 0; i < tilesCount; i++)
            {
                if (context.IsCancelling)
                    return;
                SaveTile(styleData, zip, ref i);
            }
        }


        public static void ApplyFlex(StylePropertyReader reader, VisualElementStylesData styleData)
        {
            StyleFloat grow;
            StyleFloat shrink;
            StyleLength basis;
            bool valid = CompileFlexShorthand(reader, out grow, out shrink, out basis);

            if (valid)
            {
                styleData.flexGrow = grow;
                styleData.flexShrink = shrink;
                styleData.flexBasis = basis;
            }
        }

        public static void ApplyMargin(StylePropertyReader reader, VisualElementStylesData styleData)
        {
            StyleLength top;
            StyleLength right;
            StyleLength bottom;
            StyleLength left;
            CompileBoxArea(reader, out top, out right, out bottom, out left);

            styleData.marginTop = top;
            styleData.marginRight = right;
            styleData.marginBottom = bottom;
            styleData.marginLeft = left;
        }

        public static void ApplyPadding(StylePropertyReader reader, VisualElementStylesData styleData)
        {
            StyleLength top;
            StyleLength right;
            StyleLength bottom;
            StyleLength left;
            CompileBoxArea(reader, out top, out right, out bottom, out left);

            styleData.paddingTop = top;
            styleData.paddingRight = right;
            styleData.paddingBottom = bottom;
            styleData.paddingLeft = left;
        }


		#region Constructor
		[Theory]
		[MemberData(nameof(ConstructorData), MemberType = typeof(StyleDataTest))]
		public void StyleData_Constructor_Correct_Success(ObservableCollection<AnnotationTemplate> at, ObservableCollection<RelationTemplate> rt)
		{
			//  Act & Assert
			var exception = Record.Exception(() => new StyleData(at, rt));
			Assert.Null(exception);
		}

		[Fact]
		public void StyleData_Constructor_EmptyArguments_Correct_Success()
		{
			//  Act & Assert
			var exception = Record.Exception(() => new StyleData());
			Assert.Null(exception);
		}


    void OnEnable()
    {
        for (int i = 0; i < styleSheet.Count; i++)
        {
            StyleData data = styleSheet[i];
            if (!string.IsNullOrEmpty(data.name))
                _map.Add(data.name, data);
        }
    }

    public StyleData Get(string name)
    {
        StyleData data;
        if (_map.TryGetValue(name, out data))
            return data;
        return null;
    }

    public StyleData GetBySort(int sort)
    {
        if (styleSheet.Count >= sort)
            return styleSheet[sort - 1];
        return null;
    }


        static void Apply<T>(T val, int specificity, ref StyleValue<T> property)
        {
            property.Apply(new StyleValue<T>(val, specificity), StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity);
        }

        public static void ApplyValue<T>(int specificity, ref StyleValue<T> property, T value = default(T))
        {
            Apply(value, specificity, ref property);
        }

        public static void ApplyBool(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue<bool> property)
        {
            bool value = sheet.ReadKeyword(handles[0]) == StyleValueKeyword.True;
            Apply(value, specificity, ref property);
        }

        public static void ApplyFloat(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue<float> property)
        {
            var value = sheet.ReadFloat(handles[0]);
            Apply(value, specificity, ref property);
        }

        public static void ApplyFloatOrKeyword(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue<FloatOrKeyword> property)
        {
            var handle = handles[0];
            FloatOrKeyword fk;
            if (handle.valueType == StyleValueType.Keyword)
            {
                fk = new FloatOrKeyword((StyleValueKeyword)handle.valueIndex);
            }
            else
            {
                fk = new FloatOrKeyword(sheet.ReadFloat(handle));
            }
            Apply(fk, specificity, ref property);
        }

        public static void ApplyInt(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue<int> property)
        {
            var value = (int)sheet.ReadFloat(handles[0]);
            Apply(value, specificity, ref property);
        }


        #endregion

        #region Unity Functions

        protected virtual void Awake()
        {
            Optimize();
        }

#if UNITY_EDITOR
        protected virtual void OnValidate()
        {
            Optimize();
        }
#endif

        #endregion

        #region Helper Functions

        public virtual List<StyleData> GetAllStyleDatasFromType(System.Type p_type)
        {
            List<StyleData> v_allValidStyleBehaviours = new List<StyleData>();
            foreach (var v_style in this.StyleObjectsMap)
            {
                if (v_style.Value != null)
                {
                    var v_styleValueType = v_style.Value.Asset != null? v_style.Value.Asset.GetType() : null;
                    if (v_styleValueType == null || p_type == v_styleValueType || v_styleValueType.IsSubclassOf(p_type))
                        v_allValidStyleBehaviours.Add(v_style.Value);
                }
            }
            return v_allValidStyleBehaviours;
        }

        public bool TryGetStyleDataOrFirstValid(string p_name, System.Type p_acceptedType, out StyleData p_style)
        {
            TryGetStyleData(p_name, p_acceptedType, out p_style);

            var v_type = p_style != null ? p_style.Asset.GetType() : null;
            if (p_acceptedType != null && (p_style == null || v_type != null))
            {
                //Find First Valid of the type
                if (p_style == null || (p_acceptedType != v_type && !v_type.IsSubclassOf(p_acceptedType)))
                {
                    p_style = null;
                    foreach (var v_style in m_styles)
                    {
                        if (v_style != null)
                        {
                            var v_styleValueType = v_style.Asset != null? v_style.Asset.GetType() : null;
                            if (v_styleValueType == null || (p_acceptedType == v_styleValueType || v_styleValueType.IsSubclassOf(p_acceptedType)))
                            {
                                p_style = v_style;
                                break;
                            }
                        }
                    }
                }
            }
            return p_style != null;
        }

        public bool TryGetStyleData(string p_name, out StyleData p_style)
        {
            return TryGetStyleData(p_name, null, out p_style);
        }

        public bool TryGetStyleData(string p_name, System.Type p_acceptedType, out StyleData p_style)
        {
            StyleObjectsMap.TryGetValue(p_name, out p_style);

            if (p_acceptedType != null && p_style != null && p_style.Asset != null)
            {
                var v_type = p_style.Asset.GetType();
                if (p_acceptedType != v_type && !v_type.IsSubclassOf(p_acceptedType))
                    p_style = null;
            }
            return p_style != null;
        }
        public virtual void Optimize()
        {
            if (_styleDataMap == null)
                _styleDataMap = new Dictionary<string, StyleData>();
            else
                _styleDataMap.Clear();
            foreach (var v_style in m_styles)
            {
                if(v_style != null && v_style.Asset != null && !string.IsNullOrEmpty(v_style.Name) && !_styleDataMap.ContainsKey(v_style.Name))
                    _styleDataMap.Add(v_style.Name, v_style);
            }
        }

DocumentFormat.OpenXml.Drawing.Diagrams.StyleData : IEnumerable

Constructors :

public StyleData()
public StyleData(IEnumerable<OpenXmlElement> childElements = )
public StyleData(OpenXmlElement[] childElements = )
public StyleData(String outerXml = )

Methods :

public OpenXmlElement CloneNode(Boolean deep = )
public BooleanValue get_UseDefault()
public Void set_UseDefault(BooleanValue value = )
public DataModel get_DataModel()
public Void set_DataModel(DataModel value = )
public OpenXmlElement get_FirstChild()
public OpenXmlElement get_LastChild()
public Boolean get_HasChildren()
public String get_InnerText()
public Void set_InnerXml(String value = )
public Boolean AddChild(OpenXmlElement newChild = , Boolean throwOnError = True)
public T AppendChild(T newChild = )
public T InsertAfter(T newChild = , OpenXmlElement referenceChild = )
public T InsertBefore(T newChild = , OpenXmlElement referenceChild = )
public T InsertAt(T newChild = , Int32 index = )
public T PrependChild(T newChild = )
public T RemoveChild(T child = )
public Void RemoveAllChildren()
public T ReplaceChild(OpenXmlElement newChild = , T oldChild = )
public Void RemoveAllChildren()
public Void Remove()
public Boolean IsAfter(OpenXmlElement element = )
public Boolean IsBefore(OpenXmlElement element = )
public Void AddAnnotation(Object annotation = )
public T Annotation()
public Object Annotation(Type type = )
public IEnumerable<T> Annotations()
public IEnumerable<Object> Annotations(Type type = )
public Void RemoveAnnotations()
public Void RemoveAnnotations(Type type = )
public IEnumerator<OpenXmlElement> GetEnumerator()
public Object Clone()
public MarkupCompatibilityAttributes get_MCAttributes()
public Void set_MCAttributes(MarkupCompatibilityAttributes value = )
public String LookupNamespace(String prefix = )
public String LookupPrefix(String namespaceUri = )
public IFeatureCollection get_Features()
public OpenXmlElementContext get_OpenXmlElementContext()
public Boolean get_HasAttributes()
public IEnumerable<OpenXmlAttribute> get_ExtendedAttributes()
public OpenXmlElementList get_ChildElements()
public OpenXmlElement get_Parent()
public String get_NamespaceUri()
public String get_LocalName()
public String get_Prefix()
public IEnumerable<KeyValuePair<StringString>> get_NamespaceDeclarations()
public XmlQualifiedName get_XmlQualifiedName()
public XName get_XName()
public String get_InnerXml()
public String get_OuterXml()
public OpenXmlAttribute GetAttribute(String localName = , String namespaceUri = )
public IList<OpenXmlAttribute> GetAttributes()
public Void SetAttribute(OpenXmlAttribute openXmlAttribute = )
public Void RemoveAttribute(String localName = , String namespaceUri = )
public Void SetAttributes(IEnumerable<OpenXmlAttribute> openXmlAttributes = )
public Void ClearAllAttributes()
public Void AddNamespaceDeclaration(String prefix = , String uri = )
public Void RemoveNamespaceDeclaration(String prefix = )
public T GetFirstChild()
public OpenXmlElement PreviousSibling()
public T PreviousSibling()
public OpenXmlElement NextSibling()
public T NextSibling()
public IEnumerable<OpenXmlElement> Ancestors()
public IEnumerable<T> Ancestors()
public IEnumerable<T> Elements()
public IEnumerable<OpenXmlElement> Elements()
public IEnumerable<T> Descendants()
public IEnumerable<OpenXmlElement> Descendants()
public IEnumerable<OpenXmlElement> ElementsBefore()
public IEnumerable<OpenXmlElement> ElementsAfter()
public Void WriteTo(XmlWriter xmlWriter = )
public Void Append(IEnumerable<OpenXmlElement> newChildren = )
public Void Append(OpenXmlElement[] newChildren = )
public T InsertAfterSelf(T newElement = )
public T InsertBeforeSelf(T newElement = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()