public static VarmintWidget LoadFromText(IVarmintWidgetInjector injector, string vwml, string defaultName) { var widgetSpace = new VarmintWidgetSpace(injector); widgetSpace.AddContent(defaultName, vwml); return(widgetSpace.FindWidgetByName(defaultName)); }
public void StylingPrecedenceIsEnforced() { var styleText = @" <Style Name=""Style1"" FooProp=""ShouldNotCrash"" Size=""{SizeProperty}"" ForegroundColor=""Red"" > <Style Name=""SubStyle"" /> </Style>"; var globalStyleText = @" <Style Name=""Style2"" BackgroundColor=""Yellow"" > <Style ApplyTo=""TestWidget"" /> <Style ApplyTo=""TW"" Margin=""7"" /> </Style>"; var layoutText = @" <TestWidget Style=""SubStyle"" ForegroundColor=""Blue"" > <Label Name=""MyLabel"" BackgroundColor=""Gray"" /> </TestWidget>"; var bindToMe = new BindingThing(); var widgetSpace = new VarmintWidgetSpace(new MockRenderer(100, 100)); widgetSpace.AddContent("Fooz", styleText); widgetSpace.AddContent("Freee", globalStyleText); widgetSpace.AddContent("StyleTest", layoutText); var target = widgetSpace.FindWidgetByName("StyleTest"); target.BindingContext = bindToMe; target.Prepare(widgetSpace.StyleLibrary); target.UpdateFormatting(new Vector2(100, 100)); Assert.AreEqual("StyleTest", target.Name); Assert.AreEqual(Color.Blue, target.ForegroundColor); Assert.AreEqual(Color.Yellow, target.BackgroundColor); Assert.AreEqual(7, target.Margin.Left); Assert.AreEqual(new Vector2(2, 3), target.Size); var label = target.FindWidgetByName("MyLabel"); Assert.AreEqual(Color.Gray, label.BackgroundColor); // Global style should only apply to certain types Assert.AreEqual(null, label.Margin.Left); }