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))) }); }
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()); }
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> 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))) }); }
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))); }
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")) }); }