public static bool TryScan(string line, out StyleValue value) { value = null; line = line.Trim().Trim(';'); if (!Regex.IsMatch(line, "(" + RegExHelper.StyleConstants + "|" + RegExHelper.StyleFunction + "|" + RegExHelper.StyleValue + ")")) { return(false); } if (Regex.IsMatch(line, RegExHelper.StyleFunction)) { string name = line.Split('(')[0]; List <string> parameters = new List <string>(); foreach (var parameter in line.Substring(line.IndexOf(name) + name.Length).Trim('(', ')', ' ').Split(',')) { parameters.Add(parameter.Trim().Trim('\'')); } value = new StyleValueFunc(name, parameters.ToArray()); } else if (Regex.IsMatch(line, RegExHelper.StyleConstants)) { value = new StyleValueConstant(line); } else if (Regex.IsMatch(line, RegExHelper.StyleValue)) { string valueStr = Regex.Match(line, RegExHelper.Number).Value; string unit = line.Substring(line.IndexOf(valueStr) + valueStr.Length); value = new StyleUnit(float.Parse(valueStr), StyleUnit.FromString(unit)); } else { return(false); } return(true); }
public static void Padding(Element element, StyleUnit top, StyleUnit right, StyleUnit bottom, StyleUnit left) => element.Padding += new Thickness(top, right, bottom, left);
public static bool TryScan(string line, out Instruction scanned) { scanned = null; if (!Regex.IsMatch(line, RegExHelper.Variable + "(." + RegExHelper.Variable + @")?: (" + RegExHelper.StyleConstants + "|" + RegExHelper.StyleFunction + "|" + RegExHelper.Value + ")")) { //Actually too much, only string, number and stylevalue are accepted out of command.value return(false); } string property = Regex.Match(line, RegExHelper.Variable + "(." + RegExHelper.Variable + ")?").Value; if (Regex.IsMatch(line, RegExHelper.StyleFunction)) { string name = line.Substring(property.Length + 1).Trim().Split('(')[0]; List <string> parameters = new List <string>(); foreach (var parameter in line.Substring(line.IndexOf(name) + name.Length).Trim('(', ')', ' ').Split(',')) { parameters.Add(parameter.Trim().Trim('\'')); } scanned = new Instruction(property, new StyleValueFunc(name, parameters.ToArray())); } else if (Regex.IsMatch(line, RegExHelper.StyleConstants)) { string name = line.Substring(property.Length + 1).Trim().Trim(';'); scanned = new Instruction(property, new StyleValueConstant(name)); } else if (Regex.IsMatch(line, RegExHelper.StyleValue)) { string instruct = line.Substring(property.Length + 1).Trim().Trim(';'); string value = Regex.Match(instruct, RegExHelper.Number).Value; string unit = instruct.Substring(instruct.IndexOf(value) + value.Length); scanned = new Instruction(property, new StyleUnit(float.Parse(value), StyleUnit.FromString(unit))); } else if (Regex.IsMatch(line, RegExHelper.Value)) { string value = line.Substring(property.Length + 1).Trim().Trim(';'); scanned = new Instruction(property, new StyleCommandValue(value)); } else { throw new Exception("Unkwon Command in Line '" + line + "'."); } return(true); }
public static void Padding(Element element, StyleUnit horizontal, StyleUnit vertical) => element.Padding += new Thickness(horizontal, vertical);
public static void Padding(Element element, StyleUnit thickness) => element.Padding += new Thickness(thickness);
public static void Margin(Element element, StyleUnit top, StyleUnit right, StyleUnit bottom, StyleUnit left) => element.Margin += new Thickness(top, right, bottom, left);
public static void Margin(Element element, StyleUnit horizontal, StyleUnit vertical) => element.Margin += new Thickness(horizontal, vertical);
public static void Margin(Element element, StyleUnit thickness) => element.Margin += new Thickness(thickness);