From f166c3d25607692d65a4b10a06ca8dfc0b22b0ea Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 11 Mar 2022 13:25:18 +0100 Subject: [PATCH] Fixed buttons and checkboxes changing their CanBeSelected and CanBePressed values when being disabled --- CHANGELOG.md | 1 + MLEM.Ui/Elements/Button.cs | 14 +++++--------- MLEM.Ui/Elements/Checkbox.cs | 15 ++++++--------- MLEM.Ui/Elements/Element.cs | 20 ++++++++++---------- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fba1b1..56f0315 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ Fixes - Fixed the graphics device's viewport being ignored for mouse and touch queries - Fixed auto-navigating panels not scrolling to the center of elements properly - Fixed UiControls allowing for non-selectable or non-mouseable elements to be marked as selected or moused +- Fixed buttons and checkboxes changing their CanBeSelected and CanBePressed values when being disabled Removals - Marked StyleProp equality members as obsolete diff --git a/MLEM.Ui/Elements/Button.cs b/MLEM.Ui/Elements/Button.cs index c44e404..92a38e1 100644 --- a/MLEM.Ui/Elements/Button.cs +++ b/MLEM.Ui/Elements/Button.cs @@ -51,14 +51,7 @@ namespace MLEM.Ui.Elements { /// Set this property to true to mark the button as disabled. /// A disabled button cannot be moused over, selected or pressed. /// - public bool IsDisabled { - get => this.isDisabled; - set { - this.isDisabled = value; - this.CanBePressed = !value; - this.CanBeSelected = !value; - } - } + public virtual bool IsDisabled { get; set; } /// /// Whether this button's should be truncated if it exceeds this button's width. /// Defaults to false. @@ -71,7 +64,10 @@ namespace MLEM.Ui.Elements { } } - private bool isDisabled; + /// + public override bool CanBeSelected => base.CanBeSelected && !this.IsDisabled; + /// + public override bool CanBePressed => base.CanBePressed && !this.IsDisabled; /// /// Creates a new button with the given settings diff --git a/MLEM.Ui/Elements/Checkbox.cs b/MLEM.Ui/Elements/Checkbox.cs index b1de9e7..99c0583 100644 --- a/MLEM.Ui/Elements/Checkbox.cs +++ b/MLEM.Ui/Elements/Checkbox.cs @@ -62,21 +62,18 @@ namespace MLEM.Ui.Elements { /// Set this property to true to mark the checkbox as disabled. /// A disabled checkbox cannot be moused over, selected or toggled. /// - public bool IsDisabled { - get => this.isDisabled; - set { - this.isDisabled = value; - this.CanBePressed = !value; - this.CanBeSelected = !value; - } - } + public virtual bool IsDisabled { get; set; } /// /// An event that is invoked when this checkbox's property changes /// public CheckStateChange OnCheckStateChange; + /// + public override bool CanBeSelected => base.CanBeSelected && !this.IsDisabled; + /// + public override bool CanBePressed => base.CanBePressed && !this.IsDisabled; + private bool isChecked; - private bool isDisabled; /// /// Creates a new checkbox with the given settings diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index 0de46fa..d78a6d5 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -191,51 +191,51 @@ namespace MLEM.Ui.Elements { /// Set this field to false to disallow the element from being selected. /// An unselectable element is skipped by automatic navigation and its callback will never be called. /// - public bool CanBeSelected = true; + public virtual bool CanBeSelected { get; set; } = true; /// /// Set this field to false to disallow the element from reacting to being moused over. /// - public bool CanBeMoused = true; + public virtual bool CanBeMoused { get; set; } = true; /// /// Set this field to false to disallow this element's and events to be called. /// - public bool CanBePressed = true; + public virtual bool CanBePressed { get; set; } = true; /// /// Set this field to false to cause auto-anchored siblings to ignore this element as a possible anchor point. /// - public bool CanAutoAnchorsAttach = true; + public virtual bool CanAutoAnchorsAttach { get; set; } = true; /// /// Set this field to true to cause this element's width to be automatically calculated based on the area that its take up. /// To use this element's 's X coordinate as a minimum or maximum width rather than ignoring it, set or to true. /// - public bool SetWidthBasedOnChildren; + public virtual bool SetWidthBasedOnChildren { get; set; } /// /// Set this field to true to cause this element's height to be automatically calculated based on the area that its take up. /// To use this element's 's Y coordinate as a minimum or maximum height rather than ignoring it, set or to true. /// - public bool SetHeightBasedOnChildren; + public virtual bool SetHeightBasedOnChildren { get; set; } /// /// If this field is set to true, and or are enabled, the resulting width or height will always be greather than or equal to this element's . /// For example, if an element's 's Y coordinate is set to 20, but there is only one child with a height of 10 in it, the element's height would be shrunk to 10 if this value was false, but would remain at 20 if it was true. /// Note that this value only has an effect if or are enabled. /// - public bool TreatSizeAsMinimum; + public virtual bool TreatSizeAsMinimum { get; set; } /// /// If this field is set to true, and or are enabled, the resulting width or height weill always be less than or equal to this element's . /// Note that this value only has an effect if or are enabled. /// - public bool TreatSizeAsMaximum; + public virtual bool TreatSizeAsMaximum { get; set; } /// /// Set this field to true to cause this element's final display area to never exceed that of its . /// If the resulting area is too large, the size of this element is shrunk to fit the target area. /// This can be useful if an element should fill the remaining area of a parent exactly. /// - public bool PreventParentSpill; + public virtual bool PreventParentSpill { get; set; } /// /// The transparency (alpha value) that this element is rendered with. /// Note that, when is called, this alpha value is multiplied with the 's alpha value and passed down to this element's . /// - public float DrawAlpha = 1; + public virtual float DrawAlpha { get; set; } = 1; /// /// Stores whether this element is currently being moused over or touched. ///