Exemple #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();
        }
        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)))
            });
        }
        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)))
            });
        }
        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)))
            });
        }
        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))
            });
        }
        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))
            });
        }
        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)))
            });
        }
Exemple #8
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)));
        }