Пример #1
0
        public void Nested_Widgets_Revalidate_Styles()
        {
            var style        = LayoutTestStyle.Create();
            var b            = new StyleBuilder(style.StyleSystem);
            var widgetStyles = b.StyleSystem.StylesFor <TestStyleDefinition>();

            style.StyleResolver.StyleRules.Add(
                b.CreateRule(b.SelectForType <Button>().WithCondition(StyleBuilderExtensions.HasClass("Test")), b.CreateStyle().WithValue(widgetStyles.Inherited, "FromButton-With-Test")));
            style.StyleResolver.StyleRules.Add(b.CreateRule(b.SelectForType <Button>(), b.CreateStyle().WithValue(widgetStyles.Inherited, "FromButton")));

            var button = new Button(style);

            style.StyleResolver.AddRoot(button);

            button.ValidateStyle();

            button.Content.Style.GetValue(widgetStyles.Inherited).Should().Be("FromButton");
            button.AddStyleClass("Test");

            button.ValidateStyle();

            button.Style.GetValue(widgetStyles.Inherited).Should().Be("FromButton-With-Test");
            button.Content.Style.GetValue(widgetStyles.Inherited).Should().Be("FromButton-With-Test");
            button.ValidateStyle();
        }
Пример #2
0
        protected virtual IEnumerable <IStyleRule> CreateStyleForTextField(StyleBuilder b)
        {
            var widgetStyles = b.StyleSystem.StylesFor <WidgetStyleDefinition>();
            var textStyles   = b.StyleSystem.StylesFor <TextStyleDefinition>();

            return(new List <IStyleRule>
            {
                b.CreateRule(
                    b.SelectForType <TextField>(),
                    b.CreateStyle()
                    .WithBox(widgetStyles.FrameTexture, "UI/TextField/TextFieldFrame", new Insets(20))
                    .WithValue(widgetStyles.Padding, new Insets(15))
                    .WithFont(textStyles.Font, "Fonts/MediumFont")
                    .WithValue(textStyles.TextColor, Color.White)),
                b.CreateRule(
                    b.SelectForType <TextField>().WithDirectChild(b.SelectForType("Caret")),
                    b.CreateStyle()
                    .WithValue(widgetStyles.Visibility, Visibility.Collapsed)
                    .WithValue(widgetStyles.Color, Color.White)
                    .WithValue(textStyles.SelectionColor, Color.Gray)
                    .WithValue(textStyles.CaretWidth, 1)),
                b.CreateRule(
                    b.SelectForType <TextField>()
                    .WithCondition(StyleBuilderExtensions.HasPseudoClass(WidgetPseudoClasses.FocusedPseudoClass))
                    .WithDirectChild(b.SelectForType("Caret")),
                    b.CreateStyle().WithValue(widgetStyles.Visibility, Visibility.Visible))
            });
        }
Пример #3
0
        protected virtual IEnumerable <IStyleRule> CreateStyleForButton(StyleBuilder b)
        {
            var widgetStyles = b.StyleSystem.StylesFor <WidgetStyleDefinition>();
            var textStyles   = b.StyleSystem.StylesFor <TextStyleDefinition>();

            return(new List <IStyleRule>
            {
                b.CreateRule(
                    b.SelectForType <Button>(),
                    b.CreateStyle()
                    .WithValue(widgetStyles.Padding, new Insets(20, 20))
                    .WithValue(textStyles.Alignment, Alignment.Center)
                    .WithValue(textStyles.TextColor, new Color(224, 224, 224))
                    .WithBox(widgetStyles.FrameTexture, "UI/Button/ButtonFrame", new Insets(20))),
                b.CreateRule(
                    b.SelectForType <Button>().WithDirectChild(b.SelectForType <IconLabel>()).WithDirectChild(b.SelectForType <Label>()),
                    b.CreateStyle().WithValue(textStyles.Alignment, Alignment.Center)),
                b.CreateRule(
                    b.SelectForType <Button>().WithDirectChild(b.SelectForType <IconLabel>()),
                    b.CreateStyle().WithValue(widgetStyles.Padding, new Insets(0))),
                b.CreateRule(
                    b.SelectForType <Button>().WithCondition(StyleBuilderExtensions.HasPseudoClass(WidgetPseudoClasses.HoveredPseudoClass)),
                    b.CreateStyle().WithBox(widgetStyles.HoverOverlayTexture, "UI/Button/ButtonHover", new Insets(20))),
                b.CreateRule(
                    b.SelectForType <Button>().WithCondition(StyleBuilderExtensions.HasPseudoClass(WidgetPseudoClasses.FocusedPseudoClass)),
                    b.CreateStyle().WithBox(widgetStyles.FocusedOverlayTexture, "UI/Button/ButtonFocus", new Insets(20))),
                b.CreateRule(
                    b.SelectForType <Button>().WithCondition(StyleBuilderExtensions.HasPseudoClass(ButtonPseudoClasses.DownPseudoClass)),
                    b.CreateStyle()
                    .WithBox(widgetStyles.FrameTexture, "UI/Button/ButtonFrameDown", new Insets(20))
                    .WithBox(widgetStyles.FrameOverlayTexture, "UI/Button/ButtonPress", new Insets(20)))
            });
        }
Пример #4
0
        protected virtual IEnumerable <IStyleRule> CreateStyleForListView(StyleBuilder b)
        {
            var widgetStyles = b.StyleSystem.StylesFor <WidgetStyleDefinition>();

            return(new List <IStyleRule>
            {
                b.CreateRule(
                    b.SelectForType("ListView").WithDirectChild(b.SelectForType("ScrollPanel")),
                    b.CreateStyle()
                    .WithBox(widgetStyles.FrameTexture, "UI/ListView/ListFrame", new Insets(10))
                    .WithValue(widgetStyles.Padding, new Insets(10))),
                b.CreateRule(
                    b.SelectForType <ListDataItemRenderer>(),
                    b.CreateStyle()
                    .WithBox(widgetStyles.FrameTexture, "UI/ListView/ListRowFrame", new Insets(10))
                    .WithValue(widgetStyles.Padding, new Insets(10))),
                b.CreateRule(
                    b.SelectForType <ListDataItemRenderer>()
                    .WithCondition(StyleBuilderExtensions.HasAttribute(nameof(IListDataItemRenderer.Selected), true)),
                    b.CreateStyle()
                    .WithBox(widgetStyles.FrameTexture, "UI/ListView/ListRowFrameSelected", new Insets(10))
                    .WithValue(widgetStyles.Padding, new Insets(10))),
                b.CreateRule(
                    b.SelectForType <ListDataItemRenderer>().WithCondition(StyleBuilderExtensions.HasPseudoClass(WidgetPseudoClasses.FocusedPseudoClass)),
                    b.CreateStyle().WithBox(widgetStyles.FocusedOverlayTexture, "UI/ListView/ListRowFrameFocused", new Insets(10))),
                b.CreateRule(
                    b.SelectForType <ListDataItemRenderer>().WithCondition(StyleBuilderExtensions.HasPseudoClass(WidgetPseudoClasses.HoveredPseudoClass)),
                    b.CreateStyle().WithBox(widgetStyles.HoverOverlayTexture, "UI/ListView/ListRowFrameHover", new Insets(10)))
            });
        }
Пример #5
0
        public void WriteDescendantRule()
        {
            var uiStyle = LayoutTestStyle.Create();
            var b       = new StyleBuilder(uiStyle.StyleSystem);

            var widgetStyles = b.StyleSystem.StylesFor <WidgetStyleDefinition>();
            var rules        =
                b.CreateRule(
                    b.SelectForType("Button")
                    .WithCondition(StyleBuilderExtensions.HasAttribute("name", "button"))
                    .WithDirectChild(b.SelectForType("IconLabel").WithCondition(StyleBuilderExtensions.HasAttribute("name", "iconlabel")))
                    .WithDirectChild(b.SelectForType("Label").WithCondition(StyleBuilderExtensions.HasAttribute("name", "label"))),
                    b.CreateStyle().WithBox(widgetStyles.FrameTexture, "texture-on-label"));

            var styleWriter = uiStyle.StyleSystem.CreateWriter();
            var document    = styleWriter.Write(new List <IStyleRule> {
                rules
            });
            var w = new StringWriter();

            document.Save(w);
            File.WriteAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "style-descendand-rule.xml"), w.ToString());

            var p      = uiStyle.StyleSystem.CreateParser();
            var parsed = p.Read(document);

            parsed.Count.Should().Be(1);
            parsed[0].Weight.Should().Be(rules.Weight);
            parsed[0].Selector.ToString().Should().Be(rules.Selector.ToString());
        }
Пример #6
0
        protected virtual IEnumerable <IStyleRule> CreateStyleForNotebook(StyleBuilder b)
        {
            var widgetStyles   = b.StyleSystem.StylesFor <WidgetStyleDefinition>();
            var notebookStyles = b.StyleSystem.StylesFor <NotebookStyleDefinition>();

            return(new List <IStyleRule>
            {
                b.CreateRule(b.SelectForType <Notebook>(), b.CreateStyle().WithValue(notebookStyles.NotebookTabOverlapY, 15)),
                b.CreateRule(
                    b.SelectForType <Notebook>().WithDirectChild(b.SelectForType <ScrollPanel>()),
                    b.CreateStyle().WithBox(widgetStyles.FrameTexture, "UI/Notebook/NotebookFrame", new Insets(15)).WithValue(notebookStyles.NotebookTabOverlapY, 5)),
                b.CreateRule(
                    b.SelectForType <NotebookTabList>(),
                    b.CreateStyle().WithValue(widgetStyles.Padding, new Insets(0, 20, 0, 20)).WithValue(notebookStyles.NotebookTabOverlapX, 15)),
                b.CreateRule(
                    b.SelectForType <NotebookTab>(),
                    b.CreateStyle()
                    .WithValue(widgetStyles.Padding, new Insets(0, 20, 0, 20))
                    .WithBox(widgetStyles.FrameTexture, "UI/Notebook/Tab", new Insets(15))
                    .WithBox(widgetStyles.HoverOverlayTexture, "UI/Notebook/TabHover", new Insets(15))),
                b.CreateRule(
                    b.SelectForType <NotebookTab>().WithCondition(StyleBuilderExtensions.HasAttribute(nameof(NotebookTab.IsActive), "true")),
                    b.CreateStyle().WithBox(widgetStyles.FrameTexture, "UI/Notebook/ActiveTab", new Insets(15))),
                b.CreateRule(
                    b.SelectForType <NotebookTab>().WithCondition(StyleBuilderExtensions.HasPseudoClass(WidgetPseudoClasses.FocusedPseudoClass)),
                    b.CreateStyle().WithBox(widgetStyles.FocusedOverlayTexture, "UI/Notebook/TabFocus", new Insets(15))),
                b.CreateRule(
                    b.SelectForType <NotebookTab>()
                    .WithCondition(
                        StyleBuilderExtensions.HasAttribute(nameof(NotebookTab.IsActive), "true")
                        .And(StyleBuilderExtensions.HasPseudoClass(WidgetPseudoClasses.FocusedPseudoClass))),
                    b.CreateStyle().WithBox(widgetStyles.FocusedOverlayTexture, "UI/Notebook/ActiveTabFocused", new Insets(15))),
                b.CreateRule(
                    b.SelectForType <Button>().WithCondition(StyleBuilderExtensions.HasClass(NotebookTab.CloseButtonStyleClass)),
                    b.CreateStyle()
                    .WithValue(widgetStyles.Padding, new Insets(0, 20, 0, 20))
                    .WithBox(widgetStyles.FrameTexture, "UI/Notebook/TabClose", new Insets(15))),
                b.CreateRule(
                    b.SelectForType <Button>()
                    .WithCondition(
                        StyleBuilderExtensions.HasClass(NotebookTab.CloseButtonStyleClass)
                        .And(StyleBuilderExtensions.HasPseudoClass(WidgetPseudoClasses.HoveredPseudoClass))),
                    b.CreateStyle()
                    .WithValue(widgetStyles.Padding, new Insets(0, 20, 0, 20))
                    .WithBox(widgetStyles.HoverOverlayTexture, "UI/Notebook/TabCloseHover", new Insets(15))),
                b.CreateRule(
                    b.SelectForType <Button>()
                    .WithCondition(
                        StyleBuilderExtensions.HasClass(NotebookTab.CloseButtonStyleClass)
                        .And(StyleBuilderExtensions.HasPseudoClass(ButtonPseudoClasses.DownPseudoClass))),
                    b.CreateStyle()
                    .WithValue(widgetStyles.Padding, new Insets(0, 20, 0, 20))
                    .WithBox(widgetStyles.HoverOverlayTexture, "UI/Notebook/TabCloseDown", new Insets(15)))
            });
        }
Пример #7
0
        protected virtual IEnumerable <IStyleRule> CreateStyleForRadioButtons(StyleBuilder b)
        {
            var widgetStyles = b.StyleSystem.StylesFor <WidgetStyleDefinition>();
            var textStyles   = b.StyleSystem.StylesFor <TextStyleDefinition>();

            return(new List <IStyleRule>
            {
                b.CreateRule(b.SelectForType("RadioButtonSet"), b.CreateStyle().WithValue(widgetStyles.Padding, new Insets())),
                b.CreateRule(
                    b.SelectForType <Button>().WithCondition(StyleBuilderExtensions.HasClass(RadioButtonSetContent.StyleClass)),
                    b.CreateStyle()
                    .WithBox(widgetStyles.FrameTexture, "UI/RadioButtonSet/ButtonFrameMiddle", new Insets(20))
                    .WithBox(widgetStyles.HoverOverlayTexture, null)
                    .WithValue(textStyles.TextColor, Color.White)),
                b.CreateRule(
                    b.SelectForType <Button>()
                    .WithCondition(
                        StyleBuilderExtensions.HasPseudoClass(WidgetPseudoClasses.FirstChildPseudoClass)
                        .And(StyleBuilderExtensions.HasClass(RadioButtonSetContent.StyleClass))),
                    b.CreateStyle()
                    .WithBox(widgetStyles.FrameTexture, "UI/RadioButtonSet/ButtonFrameLeft", new Insets(20))
                    .WithBox(widgetStyles.HoverOverlayTexture, null)),
                b.CreateRule(
                    b.SelectForType <Button>()
                    .WithCondition(
                        StyleBuilderExtensions.HasPseudoClass(WidgetPseudoClasses.LastChildPseudoClass)
                        .And(StyleBuilderExtensions.HasClass(RadioButtonSetContent.StyleClass))),
                    b.CreateStyle()
                    .WithBox(widgetStyles.FrameTexture, "UI/RadioButtonSet/ButtonFrameRight", new Insets(20))
                    .WithBox(widgetStyles.HoverOverlayTexture, null)),
                b.CreateRule(
                    b.SelectForType <Button>()
                    .WithCondition(
                        StyleBuilderExtensions.HasClass(RadioButtonSetContent.StyleClass)
                        .And(StyleBuilderExtensions.HasPseudoClass(ButtonPseudoClasses.DownPseudoClass))),
                    b.CreateStyle()
                    .WithBox(widgetStyles.FrameTexture, "UI/RadioButtonSet/ButtonFrameMiddleDown", new Insets(20))
                    .WithValue(textStyles.TextColor, Color.Black)),
                b.CreateRule(
                    b.SelectForType <Button>()
                    .WithCondition(
                        StyleBuilderExtensions.HasPseudoClass(WidgetPseudoClasses.FirstChildPseudoClass)
                        .And(StyleBuilderExtensions.HasClass(RadioButtonSetContent.StyleClass))
                        .And(StyleBuilderExtensions.HasPseudoClass(ButtonPseudoClasses.DownPseudoClass))),
                    b.CreateStyle().WithBox(widgetStyles.FrameTexture, "UI/RadioButtonSet/ButtonFrameLeftDown", new Insets(20))),
                b.CreateRule(
                    b.SelectForType <Button>()
                    .WithCondition(
                        StyleBuilderExtensions.HasPseudoClass(WidgetPseudoClasses.LastChildPseudoClass)
                        .And(StyleBuilderExtensions.HasClass(RadioButtonSetContent.StyleClass))
                        .And(StyleBuilderExtensions.HasPseudoClass(ButtonPseudoClasses.DownPseudoClass))),
                    b.CreateStyle().WithBox(widgetStyles.FrameTexture, "UI/RadioButtonSet/ButtonFrameRightDown", new Insets(20)))
            });
        }
Пример #8
0
        protected virtual IEnumerable <IStyleRule> CreateStyleForSlider(StyleBuilder b)
        {
            var widgetStyles = b.StyleSystem.StylesFor <WidgetStyleDefinition>();

            return(new List <IStyleRule>
            {
                b.CreateRule(
                    b.SelectForType <Slider>()
                    .WithDirectChild(b.SelectForType <Button>().WithCondition(StyleBuilderExtensions.HasClass(Slider.SliderHandleStyleClass))),
                    b.CreateStyle().WithValue(widgetStyles.Padding, new Insets(15))),
                b.CreateRule(b.SelectForType <Slider>(), b.CreateStyle().WithBox(widgetStyles.FrameTexture, "UI/Slider/SliderFrame", new Insets(10)))
            });
        }
Пример #9
0
        protected virtual IEnumerable <IStyleRule> CreateStyleForSpinningWheel(StyleBuilder b)
        {
            var imageStyles = b.StyleSystem.StylesFor <ImageStyleDefinition>();

            return(new List <IStyleRule>
            {
                b.CreateRule(
                    b.SelectForType <SpinningWheel>(),
                    b.CreateStyle().WithTexture(imageStyles.Texture, "UI/SpinningWheel/SpinningWheel").WithValue(imageStyles.TextureScale, ScaleMode.None)),
                b.CreateRule(
                    b.SelectForType <SpinningWheel>().WithCondition(StyleBuilderExtensions.HasClass("Small")),
                    b.CreateStyle().WithTexture(imageStyles.Texture, "UI/SpinningWheel/SmallSpinningWheel").WithValue(imageStyles.TextureScale, ScaleMode.None))
            });
        }
Пример #10
0
        protected virtual IEnumerable <IStyleRule> CreateStyleForDropDown(StyleBuilder b)
        {
            var imageStyles    = b.StyleSystem.StylesFor <ImageStyleDefinition>();
            var listViewStyles = b.StyleSystem.StylesFor <ListViewStyleDefinition>();

            return(new List <IStyleRule>
            {
                b.CreateRule(
                    b.SelectForType <Image>().WithCondition(StyleBuilderExtensions.HasClass(DropDownBox.DropDownArrowStyleClass)),
                    b.CreateStyle().WithTexture(imageStyles.Texture, "UI/DropDown/DropDownArrow")),
                b.CreateRule(
                    b.SelectForType("ListView").WithCondition(StyleBuilderExtensions.HasClass(DropDownBox.DropDownBoxListStyleClass)),
                    b.CreateStyle().WithValue(listViewStyles.MaxHeight, 300))
            });
        }
Пример #11
0
        protected virtual IEnumerable <IStyleRule> CreateStyleForCheckBox(StyleBuilder b)
        {
            var widgetStyles    = b.StyleSystem.StylesFor <WidgetStyleDefinition>();
            var buttonStyles    = b.StyleSystem.StylesFor <ButtonStyleDefinition>();
            var iconLabelStyles = b.StyleSystem.StylesFor <IconLabelStyleDefinition>();

            return(new List <IStyleRule>
            {
                b.CreateRule(b.SelectForType <CheckBox>(), b.CreateStyle().WithValue(widgetStyles.Padding, new Insets(10, 15))),
                b.CreateRule(
                    b.SelectForType <CheckBox>()
                    .WithDescendent(b.SelectForType <Label>().WithCondition(StyleBuilderExtensions.HasClass(CheckBox.CheckBoxLabelStyleClass))),
                    b.CreateStyle().WithValue(iconLabelStyles.IconTextGap, 10)),
                b.CreateRule(
                    b.SelectForType <CheckBox>().WithDescendent(b.SelectForType <Button>()),
                    b.CreateStyle()
                    .WithValue(widgetStyles.Padding, new Insets(20))
                    .WithBox(widgetStyles.FrameTexture, "UI/CheckBox/CheckBoxFrame", new Insets(20))),
                b.CreateRule(
                    b.SelectForType <CheckBox>()
                    .WithDescendent(b.SelectForType <Button>().WithCondition(StyleBuilderExtensions.HasPseudoClass(WidgetPseudoClasses.FocusedPseudoClass))),
                    b.CreateStyle().WithBox(widgetStyles.FocusedOverlayTexture, "UI/CheckBox/CheckBoxFrameFocus", new Insets(20))),
                b.CreateRule(
                    b.SelectForType <CheckBox>()
                    .WithDescendent(b.SelectForType <Button>().WithCondition(StyleBuilderExtensions.HasPseudoClass(WidgetPseudoClasses.HoveredPseudoClass))),
                    b.CreateStyle().WithBox(widgetStyles.HoverOverlayTexture, "UI/CheckBox/CheckBoxFrameHover", new Insets(20))),
                b.CreateRule(
                    b.SelectForType <CheckBox>()
                    .WithDescendent(
                        b.SelectForType <Button>().WithCondition(StyleBuilderExtensions.HasAttribute(nameof(Button.Selected), SelectionState.Selected))),
                    b.CreateStyle().WithBox(widgetStyles.WidgetStateOverlay, "UI/CheckBox/Checked", new Insets(20))),
                b.CreateRule(
                    b.SelectForType <CheckBox>()
                    .WithDescendent(
                        b.SelectForType <Button>().WithCondition(StyleBuilderExtensions.HasAttribute(nameof(Button.Selected), SelectionState.Unselected))),
                    b.CreateStyle().WithBox(widgetStyles.WidgetStateOverlay, "UI/CheckBox/Unchecked", new Insets(20))),
                b.CreateRule(
                    b.SelectForType <CheckBox>()
                    .WithDescendent(
                        b.SelectForType <Button>().WithCondition(StyleBuilderExtensions.HasAttribute(nameof(Button.Selected), SelectionState.Indeterminate))),
                    b.CreateStyle().WithBox(widgetStyles.WidgetStateOverlay, "UI/CheckBox/Indeterminate", new Insets(20)))
            });
        }
Пример #12
0
        void DefineDocumentationStyleExample()
        {
            var uiStyle = LayoutTestStyle.Create();
            var b       = new StyleBuilder(uiStyle.StyleSystem);

            var widgetStyles = b.StyleSystem.StylesFor <WidgetStyleDefinition>();
            var textStyles   = b.StyleSystem.StylesFor <TextStyleDefinition>();
            var rules        =
                b.CreateRule(
                    b.SelectForType(nameof(Button), nameof(Label))
                    .WithCondition(
                        StyleBuilderExtensions.HasAttribute(nameof(Label.Text))
                        .And(StyleBuilderExtensions.HasId("hovered"))
                        .And(StyleBuilderExtensions.HasClass("StyleClass"))
                        )
                    .WithDescendent(b.SelectForType(nameof(DockPanel))),
                    b.CreateStyle()
                    .WithValue(widgetStyles.FrameOverlayColor, new Color(0x4f, 0x4f, 0x4f))
                    .WithValue(widgetStyles.Color, new Color(0x6f, 0x6f, 0x6f))
                    .WithValue(textStyles.TextColor, new Color(0xe0, 0xe0, 0xe0)));
        }
Пример #13
0
        protected virtual IEnumerable <IStyleRule> CreateStyleForSplitter(StyleBuilder b)
        {
            var widgetStyles = b.StyleSystem.StylesFor <WidgetStyleDefinition>();

            return(new List <IStyleRule>
            {
                b.CreateRule(
                    b.SelectForType <Splitter>()
                    .WithCondition(StyleBuilderExtensions.HasAttribute(nameof(Splitter.IsDragging), true))
                    .WithDirectChild(b.SelectForType <SplitterBar>()),
                    b.CreateStyle().WithValue(widgetStyles.Color, Color.White)),
                b.CreateRule(
                    b.SelectForType <SplitterBar>(),
                    b.CreateStyle()
                    .WithBox(widgetStyles.FrameOverlayTexture, "UI/Splitter/SplitterDragHandle")
                    .WithBox(widgetStyles.FrameTexture, "UI/Splitter/SplitterFrame", new Insets(5))
                    .WithValue(widgetStyles.Padding, new Insets(5))
                    .WithValue(widgetStyles.Color, Color.White)),
                b.CreateRule(
                    b.SelectForType <SplitterBar>().WithCondition(StyleBuilderExtensions.HasAttribute(nameof(SplitterBar.Collapsable), true)),
                    b.CreateStyle().WithBox(widgetStyles.FrameOverlayTexture, "UI/Splitter/SplitterCollapseArrow"))
            });
        }