diff --git a/CHANGELOG.md b/CHANGELOG.md index ed53b2d..a9ecdac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ Improvements - Ensure that a panel gets notified of all relevant changes by calling OnChildAreaDirty for all grandchildren - Avoid unnecessary panel updates by using an Epsilon comparison when scrolling children - Allow setting a default text alignment for paragraphs in UiStyle +- Made custom values of Element.Style persist when a new ui style is set Fixes - Fixed paragraph links having incorrect hover locations when using special text alignments diff --git a/Demos/UiDemo.cs b/Demos/UiDemo.cs index 5830420..00164e7 100644 --- a/Demos/UiDemo.cs +++ b/Demos/UiDemo.cs @@ -81,7 +81,7 @@ namespace Demos { this.root.AddChild(new Button(Anchor.AutoCenter, new Vector2(1, 10), "Change Style") { OnPressed = element => this.UiSystem.Style = this.UiSystem.Style == untexturedStyle ? style : untexturedStyle, PositionOffset = new Vector2(0, 1), - Texture = this.testPatch + Style = untexturedStyle }); this.root.AddChild(new VerticalSpace(3)); diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index 7a44ebf..221084c 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -32,22 +32,7 @@ namespace MLEM.Ui.Elements { internal set { this.system = value; this.Controls = value?.Controls; - this.Style = value?.Style; - } - } - /// - /// This Element's current . - /// When this value is changed, is called. - /// Note that this value is automatically set to the 's ui style when it is changed. - /// - public UiStyle Style { - get => this.style; - set { - if (this.style != value) { - this.style = value; - if (value != null) - this.InitStyle(value); - } + this.Style = this.Style.OrStyle(value?.Style); } } /// @@ -261,6 +246,18 @@ namespace MLEM.Ui.Elements { /// public bool AreaDirty { get; private set; } + /// + /// This Element's current . + /// When this property is set, is called. + /// + public StyleProp Style { + get => this.style; + set { + this.style = value; + if (this.style.HasValue()) + this.InitStyle(this.style); + } + } /// /// A style property that contains the selection indicator that is displayed on this element if it is the /// @@ -418,7 +415,7 @@ namespace MLEM.Ui.Elements { private RectangleF area; private bool isHidden; private int priority; - private UiStyle style; + private StyleProp style; private StyleProp childPadding; /// @@ -1062,8 +1059,8 @@ namespace MLEM.Ui.Elements { this.SelectionIndicator = this.SelectionIndicator.OrStyle(style.SelectionIndicator); this.ActionSound = this.ActionSound.OrStyle(style.ActionSound); this.SecondActionSound = this.SecondActionSound.OrStyle(style.ActionSound); - - this.System.InvokeOnElementStyleInit(this); + + this.System?.InvokeOnElementStyleInit(this); } ///