From 866aec871de74cc05be6fe43035c740d045ca6da Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 17 Dec 2024 21:57:06 +0100 Subject: [PATCH] Added the ability to specify Dropdown paragraph colors through style properties --- CHANGELOG.md | 1 + MLEM.Ui/Elements/Dropdown.cs | 20 +++++++++++++++++--- MLEM.Ui/Style/UiStyle.cs | 10 ++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a71dbb..e45c25c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ Additions - Added TextField.OnEnterPressed event - Added Tooltip.IgnoreViewport and allow overriding the default viewport using Tooltip.Viewport - Added the ability for Dropdown to display an arrow texture based on its open state +- Added the ability to specify Dropdown paragraph colors through style properties Fixes - Fixed tooltips not being bounded correctly for viewports that don't start at the origin diff --git a/MLEM.Ui/Elements/Dropdown.cs b/MLEM.Ui/Elements/Dropdown.cs index ab839c8..89053cc 100644 --- a/MLEM.Ui/Elements/Dropdown.cs +++ b/MLEM.Ui/Elements/Dropdown.cs @@ -8,11 +8,13 @@ namespace MLEM.Ui.Elements { /// /// A dropdown component to use inside of a . /// A dropdown is a component that contains a hidden panel which is displayed upon pressing the dropdown button. + /// Elements can be added to the dropdown's through or one of its overloads, which additionally causes them to have correct gamepad navigation behavior. /// public class Dropdown : Button { /// /// The panel that this dropdown contains. It will be displayed upon pressing the dropdown button. + /// To add elements to this panel, you can use or one of its overloads, which additionally causes them to have correct gamepad navigation behavior. /// public Panel Panel { get; private set; } /// @@ -65,6 +67,16 @@ namespace MLEM.Ui.Elements { this.UpdateArrowStyle(); } } + /// + /// A style property containing the that a paragraph added to this dropdown through should have by default. + /// For elements added through other overloads of , this property has no effect. + /// + public StyleProp TextColor; + /// + /// A style property containing the that a paragraph added to this dropdown through should have when hovered. + /// For elements added through other overloads of , this property has no effect. + /// + public StyleProp HoveredTextColor; private StyleProp openedArrowTexture; private StyleProp closedArrowTexture; @@ -144,7 +156,7 @@ namespace MLEM.Ui.Elements { /// /// Adds a pressable element to this dropdown's . - /// By default, the paragraph's text color will change from to when hovering over it. + /// By default, the paragraph's text color will change from to when hovering over it. /// /// The text to display /// The resulting paragraph's event @@ -157,8 +169,8 @@ namespace MLEM.Ui.Elements { }; if (pressed != null) paragraph.OnPressed += pressed; - paragraph.OnMouseEnter += e => paragraph.TextColor = Color.LightGray; - paragraph.OnMouseExit += e => paragraph.TextColor = Color.White; + paragraph.OnMouseEnter += e => paragraph.TextColor = this.HoveredTextColor; + paragraph.OnMouseExit += e => paragraph.TextColor = this.TextColor; this.AddElement(paragraph, index); return paragraph; } @@ -198,6 +210,8 @@ namespace MLEM.Ui.Elements { this.ArrowPadding = this.ArrowPadding.OrStyle(style.DropdownArrowPadding); this.ClosedArrowTexture = this.ClosedArrowTexture.OrStyle(style.DropdownClosedArrowTexture); this.OpenedArrowTexture = this.OpenedArrowTexture.OrStyle(style.DropdownOpenedArrowTexture); + this.TextColor = this.TextColor.OrStyle(style.DropdownTextColor); + this.HoveredTextColor = this.HoveredTextColor.OrStyle(style.DropdownHoveredTextColor); this.UpdateArrowStyle(); } diff --git a/MLEM.Ui/Style/UiStyle.cs b/MLEM.Ui/Style/UiStyle.cs index cb37e48..ab6f582 100644 --- a/MLEM.Ui/Style/UiStyle.cs +++ b/MLEM.Ui/Style/UiStyle.cs @@ -257,6 +257,16 @@ namespace MLEM.Ui.Style { /// This value is passed to . /// public TextureRegion DropdownOpenedArrowTexture; + /// + /// The color that a 's paragraphs should have by default. + /// This value is passed to . + /// + public Color DropdownTextColor = Color.White; + /// + /// The color that a 's paragraphs should have when hovered. + /// This value is passed to . + /// + public Color DropdownHoveredTextColor = Color.LightGray; /// /// A set of additional fonts that can be used for the <f FontName> formatting code