public void ParseMultipleAttributes() { var nodes = StyleParser.Parse(@" style hasBackgroundOnHover { not [attr:attrName1] and not [attr:attrName2] and [attr:attrName3]{ } } "); Assert.AreEqual(1, nodes.Count); StyleRootNode styleRootNode = (StyleRootNode)nodes[0]; Assert.AreEqual(1, styleRootNode.children.Count); var attributeGroupContainer3 = (((AttributeNodeContainer)styleRootNode.children[0])); Assert.AreEqual("attrName3", attributeGroupContainer3.identifier); Assert.AreEqual(false, attributeGroupContainer3.invert); var attributeGroupContainer2 = attributeGroupContainer3.next; Assert.AreEqual("attrName2", attributeGroupContainer2.identifier); Assert.AreEqual(true, attributeGroupContainer2.invert); var attributeGroupContainer1 = attributeGroupContainer2.next; Assert.AreEqual("attrName1", attributeGroupContainer1.identifier); Assert.AreEqual(true, attributeGroupContainer1.invert); Assert.IsNull(attributeGroupContainer1.next); }
public void ParseKeyFrames() { LightList <StyleASTNode> nodes = StyleParser.Parse(@" animation anim1 { [keyframes] { 0% { BackgroundColor = red; } 100% { BackgroundColor = green; } } } "); Assert.AreEqual(1, nodes.Count); AnimationRootNode rootNode = nodes[0] as AnimationRootNode; KeyFrameNode keyFrameNode0 = rootNode.keyframeNodes[0]; Assert.AreEqual(0, keyFrameNode0.keyframes[0]); Assert.AreEqual(1, keyFrameNode0.children.Count); Assert.AreEqual(StyleASTNodeType.Property, keyFrameNode0.children[0].type); KeyFrameNode keyFrameNode1 = rootNode.keyframeNodes[1]; Assert.AreEqual(100, keyFrameNode1.keyframes[0]); Assert.AreEqual(1, keyFrameNode1.children.Count); Assert.AreEqual(StyleASTNodeType.Property, keyFrameNode1.children[0].type); }
public void CompileCursor() { var nodes = StyleParser.Parse(@" const path = ""testimg/Cursor1""; export const cursor1 = url(@path); style image1 { Cursor = @cursor1 1 2; } style image2 { Cursor = url(@path) 20; } style image3 { Cursor = url(testimg/Cursor1); } ".Trim()); StyleSheet styleSheet = NewStyleSheetCompiler().Compile("test", nodes); var containers = styleSheet.styleGroupContainers; Assert.AreEqual(3, containers.Length); Assert.AreEqual("Cursor1", containers[0].groups[0].normal.style.Cursor.texture.name); Assert.AreEqual(new Vector2(1, 2), containers[0].groups[0].normal.style.Cursor.hotSpot); Assert.AreEqual("Cursor1", containers[1].groups[0].normal.style.Cursor.texture.name); Assert.AreEqual(new Vector2(20, 20), containers[1].groups[0].normal.style.Cursor.hotSpot); Assert.AreEqual("Cursor1", containers[2].groups[0].normal.style.Cursor.texture.name); Assert.AreEqual(new Vector2(0, 0), containers[2].groups[0].normal.style.Cursor.hotSpot); }
public void ParseMaterialStyle() { var nodes = StyleParser.Parse(@" style simple { Material = ""noise"" { shake = 4; }; } "); Assert.AreEqual(1, nodes.Count); StyleRootNode rootNode = ((StyleRootNode)nodes[0]); Assert.AreEqual("simple", rootNode.identifier); Assert.AreEqual(null, rootNode.tagName); Assert.AreEqual(1, rootNode.children.Count); var propertyNode = rootNode.children[0]; Assert.AreEqual(StyleASTNodeType.Property, propertyNode.type); PropertyNode typedPropertyNode = (((PropertyNode)propertyNode)); Assert.AreEqual("Material", typedPropertyNode.identifier); Assert.AreEqual(StyleASTNodeType.StringLiteral, typedPropertyNode.children[0].type); }
public void ParseStyleState() { var nodes = StyleParser.Parse(@" style hasBackgroundOnHover { [hover] { Background = url(@pathRef.member); } } "); Assert.AreEqual(1, nodes.Count); var stateGroupContainer = (((StyleStateContainer)((StyleRootNode)nodes[0]).children[0])); Assert.AreEqual("hover", stateGroupContainer.identifier); var property = (PropertyNode)stateGroupContainer.children[0]; Assert.AreEqual("Background", property.identifier); var urlNode = (UrlNode)property.children[0]; Assert.AreEqual(StyleASTNodeType.Url, urlNode.type); Assert.AreEqual(StyleASTNodeType.Reference, urlNode.url.type); var refNode = (ConstReferenceNode)urlNode.url; Assert.AreEqual("pathRef", refNode.identifier); Assert.AreEqual(1, refNode.children.Count); Assert.AreEqual(StyleASTNodeType.DotAccess, refNode.children[0].type); var dotAccess = (DotAccessNode)refNode.children[0]; Assert.AreEqual("member", dotAccess.propertyName); }
public void ParseUrl() { var nodes = StyleParser.Parse(@" style withBg { Background = url(path/to/image); } "); Assert.AreEqual(1, nodes.Count); var rootNode = ((StyleRootNode)nodes[0]); Assert.AreEqual("withBg", rootNode.identifier); Assert.AreEqual(null, rootNode.tagName); Assert.AreEqual(1, rootNode.children.Count); var property = (((PropertyNode)rootNode.children[0])); Assert.AreEqual("Background", property.identifier); Assert.AreEqual(StyleASTNodeType.Url, property.children[0].type); var urlNode = (UrlNode)property.children[0]; Assert.AreEqual(StyleASTNodeType.Url, urlNode.type); Assert.AreEqual(StyleASTNodeFactory.IdentifierNode("path/to/image"), urlNode.url); }
public void CompileTransformPosition() { var nodes = StyleParser.Parse(@" export const x = 20sw; export const y = 10cah; style trans1 { TransformPosition = @x @y; } style trans2 { TransformPosition = @x; } style trans3 { TransformPositionX = @x; } style trans4 { TransformPositionY = 15h; } ".Trim()); StyleSheet styleSheet = NewStyleSheetCompiler().Compile("test", nodes); var styleGroup = styleSheet.styleGroupContainers; Assert.AreEqual(4, styleGroup.Length); Assert.AreEqual(new OffsetMeasurement(20, OffsetMeasurementUnit.ScreenWidth), styleGroup[0].groups[0].normal.style.TransformPositionX); Assert.AreEqual(new OffsetMeasurement(10, OffsetMeasurementUnit.ContentAreaHeight), styleGroup[0].groups[0].normal.style.TransformPositionY); Assert.AreEqual(new OffsetMeasurement(20, OffsetMeasurementUnit.ScreenWidth), styleGroup[1].groups[0].normal.style.TransformPositionX); Assert.AreEqual(new OffsetMeasurement(20, OffsetMeasurementUnit.ScreenWidth), styleGroup[1].groups[0].normal.style.TransformPositionY); Assert.AreEqual(new OffsetMeasurement(20, OffsetMeasurementUnit.ScreenWidth), styleGroup[2].groups[0].normal.style.TransformPositionX); Assert.AreEqual(OffsetMeasurement.Unset, styleGroup[2].groups[0].normal.style.TransformPositionY); Assert.AreEqual(OffsetMeasurement.Unset, styleGroup[3].groups[0].normal.style.TransformPositionX); Assert.AreEqual(new OffsetMeasurement(15, OffsetMeasurementUnit.ActualHeight), styleGroup[3].groups[0].normal.style.TransformPositionY); }
public override void ParseNode(HtmlNode htmlNode, XElement resultElement, ParseContext parseContext, XElement baseFormattingElement) { XElement xElement = null; HtmlAttribute htmlAttribute = htmlNode.Attributes["src"]; if (htmlAttribute != null) { MediaItem mediaItem = this.GetMediaItem(htmlAttribute.Value); if (mediaItem != null) { string text; string text2; StyleParser.ParseDimensions(htmlNode, out text, out text2); if (string.IsNullOrEmpty(text)) { text = HtmlParseHelper.ParseDimensionValue(mediaItem.InnerItem["Width"], true); } if (string.IsNullOrEmpty(text2)) { text2 = HtmlParseHelper.ParseDimensionValue(mediaItem.InnerItem["Height"], true); } xElement = this.CreateInlineElement(text, text2); XElement content = this.CreateImageElement(htmlNode, mediaItem, parseContext, text, text2); xElement.Add(content); } } if (xElement != null) { resultElement.Add(xElement); } }
public void StyleSheetContainers() { LightList <StyleASTNode> nodes = StyleParser.Parse(@" export const red = red; style styleRoot { TextColor = @red; TextFontAsset = url(""Gotham-Medium SDF""); TextFontStyle = bold italic superscript underline highlight smallcaps; TextFontSize = 14; TextAlignment = Center; [attr:attr0] { BackgroundColor = #ff0000aa; } [hover] { TextFontSize = 18; } } ".Trim()); StyleSheet styleSheet = NewStyleSheetCompiler().Compile("test", nodes); Assert.AreEqual(1, styleSheet.styleGroupContainers.Length); Assert.AreEqual(2, styleSheet.styleGroupContainers[0].groups.Length); }
public void ReferenceAnimationInStyle() { var nodes = StyleParser.Parse(@" animation anim1 { [options] { duration = 500; } [keyframes] { 0% { BackgroundColor = @regularColor; } 20% { BackgroundColor = yellow; } 80% { BackgroundColor = yellow; } 100% { BackgroundColor = @regularColor;} } } style someStyle { run animation(anim1); [hover] { run animation(anim1); } } const regularColor = red; ".Trim()); StyleSheet styleSheet = NewStyleSheetCompiler().Compile("test", nodes); Assert.AreEqual(1, styleSheet.styleGroupContainers.Length); UIStyleGroupContainer container = styleSheet.styleGroupContainers[0]; Assert.AreEqual("someStyle", container.name); Assert.AreEqual(1, container.groups[0].normal.runCommands.Count); Assert.AreEqual(1, container.groups[0].hover.runCommands.Count); }
public void CreateAttributeGroupsWithMeasurements() { var nodes = StyleParser.Parse(@" export const m1 = 10%; style myStyle { MarginTop = @m1; [hover] { MarginLeft = 20px; } [attr:myAttr=""val""] { MarginTop = 20px; } } ".Trim()); StyleSheet styleSheet = NewStyleSheetCompiler().Compile("test", nodes); var containers = styleSheet.styleGroupContainers; Assert.AreEqual(1, containers.Length); Assert.AreEqual(2, containers[0].groups.Length); Assert.IsTrue(Mathf.Approximately(0.1f, containers[0].groups[0].normal.style.MarginTop.value)); Assert.AreEqual(UIFixedUnit.Percent, containers[0].groups[0].normal.style.MarginTop.unit); Assert.AreEqual(20, containers[0].groups[0].hover.style.MarginLeft.value); Assert.AreEqual(20, containers[0].groups[1].normal.style.MarginTop.value); }
public void CompileGridItemColAndRowProperties() { var nodes = StyleParser.Parse(@" const rowStart = 2; style myStyle { GridItemX = 0; GridItemWidth = 4; GridItemY = @rowStart; GridItemHeight = 5; } ".Trim()); StyleSheet styleSheet = NewStyleSheetCompiler().Compile("test", nodes); var containers = styleSheet.styleGroupContainers; Assert.AreEqual(1, containers.Length); Assert.AreEqual(new GridItemPlacement(0), containers[0].groups[0].normal.style.GridItemX); Assert.AreEqual(new GridItemPlacement(4), containers[0].groups[0].normal.style.GridItemWidth); Assert.AreEqual(new GridItemPlacement(2), containers[0].groups[0].normal.style.GridItemY); Assert.AreEqual(new GridItemPlacement(5), containers[0].groups[0].normal.style.GridItemHeight); }
public void ParseRgbColorProperty() { var nodes = StyleParser.Parse(@" style withBg { BackgroundColor = rgb(10, 20, 30); } "); Assert.AreEqual(1, nodes.Count); var rootNode = ((StyleRootNode)nodes[0]); Assert.AreEqual("withBg", rootNode.identifier); Assert.AreEqual(null, rootNode.tagName); Assert.AreEqual(1, rootNode.children.Count); var property = (((PropertyNode)rootNode.children[0])); Assert.AreEqual("BackgroundColor", property.identifier); Assert.AreEqual(StyleASTNodeType.Rgb, property.children[0].type); var rgbNode = (RgbNode)property.children[0]; Assert.AreEqual(StyleASTNodeType.Rgb, rgbNode.type); Assert.AreEqual(StyleASTNodeFactory.NumericLiteralNode("10"), rgbNode.red); Assert.AreEqual(StyleASTNodeFactory.NumericLiteralNode("20"), rgbNode.green); Assert.AreEqual(StyleASTNodeFactory.NumericLiteralNode("30"), rgbNode.blue); }
public void CompileText() { // note: because of possible spaces in paths we have to support string values for urls var nodes = StyleParser.Parse(@" export const red = red; style teXt { TextColor = @red; TextFontAsset = url(""Fonts/GothamNarrow-Medium SDF""); TextFontStyle = bold italic superscript underline highlight smallcaps; TextFontSize = 14; TextAlignment = Center; } ".Trim()); StyleSheet styleSheet = NewStyleSheetCompiler().Compile("test", nodes); var styleGroup = styleSheet.styleGroupContainers; Assert.AreEqual(Color.red, styleGroup[0].groups[0].normal.style.TextColor); Assert.AreEqual("GothamNarrow-Medium SDF", styleGroup[0].groups[0].normal.style.TextFontAsset.name); Assert.AreEqual(FontStyle.Normal | FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, styleGroup[0].groups[0].normal.style.TextFontStyle); Assert.AreEqual(TextAlignment.Center, styleGroup[0].groups[0].normal.style.TextAlignment); Assert.AreEqual(new UIFixedLength(14), styleGroup[0].groups[0].normal.style.TextFontSize); }
public static IStyleParser CreateParser(this IStyleSystem s, GraphicsDevice graphicsDevice = null) { var parser = new StyleParser(s, graphicsDevice); s.ConfigureStyleSerializer(parser); return(parser); }
public void UseMarginPropertyShorthand() { var nodes = StyleParser.Parse(@" export const m1 = 10%; export const m2 = @m3; export const m3 = 10%; export const m4 = @m2; style myStyle { Margin = @m1 @m2 10px @m4; } ".Trim()); StyleSheet styleSheet = NewStyleSheetCompiler().Compile("test", nodes); var containers = styleSheet.styleGroupContainers; Assert.AreEqual(1, containers.Length); Assert.AreEqual(0.1f, containers[0].groups[0].normal.style.MarginTop.value); Assert.AreEqual(0.1f, containers[0].groups[0].normal.style.MarginRight.value); Assert.AreEqual(10, containers[0].groups[0].normal.style.MarginBottom.value); Assert.AreEqual(0.1f, containers[0].groups[0].normal.style.MarginLeft.value); Assert.AreEqual(UIFixedUnit.Percent, containers[0].groups[0].normal.style.MarginTop.unit); Assert.AreEqual(UIFixedUnit.Percent, containers[0].groups[0].normal.style.MarginRight.unit); Assert.AreEqual(UIFixedUnit.Pixel, containers[0].groups[0].normal.style.MarginBottom.unit); Assert.AreEqual(UIFixedUnit.Percent, containers[0].groups[0].normal.style.MarginLeft.unit); }
public void UsePaddingPropertyShorthand() { var nodes = StyleParser.Parse(@" export const p1 = 10%; export const p2 = @p3; export const p3 = 10%; export const p4 = @p2; style myStyle { Padding = @p1 @p2 20px @p4; } ".Trim()); StyleSheet styleSheet = NewStyleSheetCompiler().Compile("test", nodes); var containers = styleSheet.styleGroupContainers; Assert.AreEqual(1, containers.Length); Assert.IsTrue(Mathf.Approximately(10 * 0.01f, containers[0].groups[0].normal.style.PaddingTop.value)); Assert.IsTrue(Mathf.Approximately(10 * 0.01f, containers[0].groups[0].normal.style.PaddingRight.value)); Assert.AreEqual(20, containers[0].groups[0].normal.style.PaddingBottom.value); Assert.IsTrue(Mathf.Approximately(10 * 0.01f, containers[0].groups[0].normal.style.PaddingLeft.value)); Assert.AreEqual(UIFixedUnit.Percent, containers[0].groups[0].normal.style.PaddingTop.unit); Assert.AreEqual(UIFixedUnit.Percent, containers[0].groups[0].normal.style.PaddingRight.unit); Assert.AreEqual(UIFixedUnit.Pixel, containers[0].groups[0].normal.style.PaddingBottom.unit); Assert.AreEqual(UIFixedUnit.Percent, containers[0].groups[0].normal.style.PaddingLeft.unit); }
public void CompileVisibilty() { var nodes = StyleParser.Parse(@" const v = hidden; style myStyle { Visibility = visible; [attr:disabled=""disabled""] { Visibility = @v; } } ".Trim()); StyleSheet styleSheet = NewStyleSheetCompiler().Compile("test", nodes); var containers = styleSheet.styleGroupContainers; Assert.AreEqual(1, containers.Length); Assert.AreEqual(2, containers[0].groups.Length); Assert.AreEqual(Visibility.Visible, containers[0].groups[0].normal.style.Visibility); Assert.AreEqual(Visibility.Hidden, containers[0].groups[1].normal.style.Visibility); Assert.AreEqual("disabled", containers[0].groups[1].rule.attributeName); Assert.AreEqual("disabled", containers[0].groups[1].rule.attributeValue); Assert.AreEqual(false, containers[0].groups[1].rule.invert); }
public static UIStyle Load(string name, string source) { var p = new StyleParser(); var style = p.Parse(source); return(new UIStyle { Name = name, Style = style }); }
public void CompileAnimation() { var nodes = StyleParser.Parse(@" animation anim1 { [keyframes] { 0% { BackgroundColor = red; BackgroundColor = red; } 50% { TextFontSize = 11; BackgroundColor = green; } 60% { PreferredSize = 40px, 30px; } 100% { BackgroundColor = green; } } } ".Trim()); StyleSheet styleSheet = NewStyleSheetCompiler().Compile("test", nodes); Assert.AreEqual(1, styleSheet.animations.Length); AnimationData animationData = styleSheet.animations[0]; Assert.AreEqual("anim1", animationData.name); Assert.AreEqual(4, animationData.frames.Count); StyleAnimationKeyFrame frame0 = animationData.frames[0]; Assert.AreEqual(1, frame0.properties.Count); Assert.AreEqual(0, frame0.key); Assert.AreEqual(StylePropertyId.BackgroundColor, frame0.properties[0].propertyId); Assert.AreEqual(Color.red, frame0.properties[0].styleProperty.AsColor); StyleAnimationKeyFrame frame1 = animationData.frames[1]; Assert.AreEqual(2, frame1.properties.Count); Assert.AreEqual(0.5f, frame1.key); Assert.AreEqual(StylePropertyId.TextFontSize, frame1.properties[0].propertyId); Assert.AreEqual(StylePropertyId.BackgroundColor, frame1.properties[1].propertyId); StyleAnimationKeyFrame frame2 = animationData.frames[2]; Assert.AreEqual(2, frame2.properties.Count); Assert.AreEqual(0.6f, frame2.key); Assert.AreEqual(StylePropertyId.PreferredWidth, frame2.properties[0].propertyId); Assert.AreEqual(StylePropertyId.PreferredHeight, frame2.properties[1].propertyId); StyleAnimationKeyFrame frame3 = animationData.frames[3]; Assert.AreEqual(1, frame3.properties.Count); Assert.AreEqual(1, frame3.key); Assert.AreEqual(StylePropertyId.BackgroundColor, frame3.properties[0].propertyId); }
public static Paragraph Parse(string text, Style?style = null) { if (text is null) { throw new ArgumentNullException(nameof(text)); } style ??= Style.Plain; var result = new Paragraph(); using var tokenizer = new MarkupTokenizer(text); var stack = new Stack <Style>(); while (tokenizer.MoveNext()) { var token = tokenizer.Current; if (token == null) { break; } if (token.Kind == MarkupTokenKind.Open) { var parsedStyle = StyleParser.Parse(token.Value); stack.Push(parsedStyle); } else if (token.Kind == MarkupTokenKind.Close) { if (stack.Count == 0) { throw new InvalidOperationException($"Encountered closing tag when none was expected near position {token.Position}."); } stack.Pop(); } else if (token.Kind == MarkupTokenKind.Text) { // Get the effective style. var effectiveStyle = style.Combine(stack.Reverse()); result.Append(Emoji.Replace(token.Value), effectiveStyle); } else { throw new InvalidOperationException("Encountered unknown markup token."); } } if (stack.Count > 0) { throw new InvalidOperationException("Unbalanced markup stack. Did you forget to close a tag?"); } return(result); }
protected void ParseChildNode(HtmlNode htmlNode, XElement resultElement, ParseContext parseContext, XElement baseFormattingElement) { if (parseContext.ParseDefinitions.IsEscapedNode(htmlNode)) { return; } ParseDefinition definition = parseContext.ParseDefinitions[htmlNode]; if (definition != null) { Type typeInfo = ReflectionUtil.GetTypeInfo(definition.HtmlParserType); if (typeInfo.Name == "CustomHtmlNodeParser") { var customParser = CustomHtmlParseHelper.GetParser <CustomHtmlNodeParser>(definition); if (customParser == null) { return; } customParser.SpecialCharacterMapper = SpecialCharacterMapper; customParser.ParseNode(htmlNode, resultElement, parseContext, baseFormattingElement); } else { object parser = CustomHtmlParseHelper.GetParser <HtmlNodeParser>(definition); ((HtmlNodeParser)parser)?.ParseNode(htmlNode, resultElement, parseContext, baseFormattingElement); } } else if (HtmlParseHelper.IsPlainTextNode(htmlNode)) { XCData xcData = new XCData(HtmlEntityHelper.DeEntitize(htmlNode.InnerHtml)); if (SpecialCharacterMapper != null) { SpecialCharacterMapper.ParseSpecialCharacters(xcData.Value, baseFormattingElement, ref resultElement); return; } if (baseFormattingElement != null) { XElement xelement = new XElement(baseFormattingElement); xelement.Add((object)xcData); resultElement.Add((object)xelement); } else { resultElement.Add(xcData); } } else { XElement formattingElement = StyleParser.GetFormattingElement(htmlNode, baseFormattingElement, true); this.ParseChildNodes(htmlNode, resultElement, parseContext, formattingElement); } }
public void ParseEmptyAnimationVariableHeader() { LightList <StyleASTNode> nodes = StyleParser.Parse(@" animation anim1 { [variables] {} } "); Assert.AreEqual(1, nodes.Count); Assert.IsInstanceOf <AnimationRootNode>(nodes[0]); }
public void ParseAnimationOptionHeaderEmpty() { LightList <StyleASTNode> nodes = StyleParser.Parse(@" animation anim1 { [options] {} } "); Assert.AreEqual(1, nodes.Count); Assert.IsInstanceOf <AnimationRootNode>(nodes[0]); }
public void ImportFromFile() { var nodes = StyleParser.Parse(@" import ""mypath/to/myfile"" as myconsts; "); Assert.AreEqual(1, nodes.Count); ImportNode importNode = (ImportNode)nodes[0]; Assert.AreEqual("myconsts", importNode.alias); Assert.AreEqual("mypath/to/myfile", importNode.source); }
private void ReadStyle() { StyleParser styleParser = new StyleParser(); Style style = styleParser.ParseStyle(reader); style.InheritFrom(StyleConfig); StyleConfig = style; if (!StyleConfig.IsComplete()) { throw new ConfigException("StyleConfig has to be complete!"); } }
public void ParseBrokenStyle() { try { StyleParser.Parse(@" style s { BrokenUrl = url() } ".Trim()); Assert.Fail("This should not have parsed!"); } catch (ParseException e) { Assert.AreEqual(1, e.token.line); Assert.AreEqual(27, e.token.column); } }
public void ParseExportKeyword() { var nodes = StyleParser.Parse(@" export const color0 = rgba(1, 0, 0, 1); "); // there should be two style nodes Assert.AreEqual(1, nodes.Count); Assert.AreEqual(StyleASTNodeType.Export, nodes[0].type); ExportNode exportNode = (ExportNode)nodes[0]; Assert.AreEqual("color0", exportNode.constNode.constName); Assert.AreEqual(StyleASTNodeType.Rgba, exportNode.constNode.value.type); }
public void CompileImport() { // note: because of possible spaces in paths we have to support string values for urls var nodes = StyleParser.Parse(@" import ""Data/Styles/ImportFromMe.style"" as importedThings; style xyz { BackgroundColor = @importedThings.colorRed; } ".Trim()); StyleSheet styleSheet = NewStyleSheetCompiler().Compile("test", nodes); var styleGroup = styleSheet.styleGroupContainers; Assert.AreEqual(Color.red, styleGroup[0].groups[0].normal.style.BackgroundColor); }
public void CompileTransformProperties() { var nodes = StyleParser.Parse(@" export const x = 1; export const y = 2; style trans1 { TransformScale = @x @y; } style trans2 { TransformScaleX = 3; } style trans3 { TransformScaleY = 4; } const pivot = 10%; style pivot1 { TransformPivot = @pivot 10px; } style pivot2 { TransformPivotX = @pivot; } style pivot3 { TransformPivotY = 20px; } style rotate1 { TransformRotation = 90; } const pivotOffset = PivotOffset; ".Trim()); StyleSheet styleSheet = NewStyleSheetCompiler().Compile("test", nodes); var styleGroup = styleSheet.styleGroupContainers; Assert.AreEqual(1, styleGroup[0].groups[0].normal.style.TransformScaleX); Assert.AreEqual(2, styleGroup[0].groups[0].normal.style.TransformScaleY); Assert.AreEqual(3, styleGroup[1].groups[0].normal.style.TransformScaleX); Assert.AreEqual(float.NaN, styleGroup[1].groups[0].normal.style.TransformScaleY); Assert.AreEqual(float.NaN, styleGroup[2].groups[0].normal.style.TransformScaleX); Assert.AreEqual(4, styleGroup[2].groups[0].normal.style.TransformScaleY); Assert.AreEqual(new UIFixedLength(0.1f, UIFixedUnit.Percent), styleGroup[3].groups[0].normal.style.TransformPivotX); Assert.AreEqual(new UIFixedLength(10), styleGroup[3].groups[0].normal.style.TransformPivotY); Assert.AreEqual(new UIFixedLength(0.1f, UIFixedUnit.Percent), styleGroup[4].groups[0].normal.style.TransformPivotX); Assert.AreEqual(UIFixedLength.Unset, styleGroup[4].groups[0].normal.style.TransformPivotY); Assert.AreEqual(UIFixedLength.Unset, styleGroup[5].groups[0].normal.style.TransformPivotX); Assert.AreEqual(new UIFixedLength(20), styleGroup[5].groups[0].normal.style.TransformPivotY); Assert.AreEqual(90, styleGroup[6].groups[0].normal.style.TransformRotation); }