1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 12:58:33 +01:00

Fixed buttons and checkboxes changing their CanBeSelected and CanBePressed values when being disabled

This commit is contained in:
Ell 2022-03-11 13:25:18 +01:00
parent 2c90ca9b89
commit f166c3d256
4 changed files with 22 additions and 28 deletions

View file

@ -55,6 +55,7 @@ Fixes
- Fixed the graphics device's viewport being ignored for mouse and touch queries - 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 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 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 Removals
- Marked StyleProp equality members as obsolete - Marked StyleProp equality members as obsolete

View file

@ -51,14 +51,7 @@ namespace MLEM.Ui.Elements {
/// Set this property to true to mark the button as disabled. /// Set this property to true to mark the button as disabled.
/// A disabled button cannot be moused over, selected or pressed. /// A disabled button cannot be moused over, selected or pressed.
/// </summary> /// </summary>
public bool IsDisabled { public virtual bool IsDisabled { get; set; }
get => this.isDisabled;
set {
this.isDisabled = value;
this.CanBePressed = !value;
this.CanBeSelected = !value;
}
}
/// <summary> /// <summary>
/// Whether this button's <see cref="Text"/> should be truncated if it exceeds this button's width. /// Whether this button's <see cref="Text"/> should be truncated if it exceeds this button's width.
/// Defaults to false. /// Defaults to false.
@ -71,7 +64,10 @@ namespace MLEM.Ui.Elements {
} }
} }
private bool isDisabled; /// <inheritdoc />
public override bool CanBeSelected => base.CanBeSelected && !this.IsDisabled;
/// <inheritdoc />
public override bool CanBePressed => base.CanBePressed && !this.IsDisabled;
/// <summary> /// <summary>
/// Creates a new button with the given settings /// Creates a new button with the given settings

View file

@ -62,21 +62,18 @@ namespace MLEM.Ui.Elements {
/// Set this property to true to mark the checkbox as disabled. /// Set this property to true to mark the checkbox as disabled.
/// A disabled checkbox cannot be moused over, selected or toggled. /// A disabled checkbox cannot be moused over, selected or toggled.
/// </summary> /// </summary>
public bool IsDisabled { public virtual bool IsDisabled { get; set; }
get => this.isDisabled;
set {
this.isDisabled = value;
this.CanBePressed = !value;
this.CanBeSelected = !value;
}
}
/// <summary> /// <summary>
/// An event that is invoked when this checkbox's <see cref="Checked"/> property changes /// An event that is invoked when this checkbox's <see cref="Checked"/> property changes
/// </summary> /// </summary>
public CheckStateChange OnCheckStateChange; public CheckStateChange OnCheckStateChange;
/// <inheritdoc />
public override bool CanBeSelected => base.CanBeSelected && !this.IsDisabled;
/// <inheritdoc />
public override bool CanBePressed => base.CanBePressed && !this.IsDisabled;
private bool isChecked; private bool isChecked;
private bool isDisabled;
/// <summary> /// <summary>
/// Creates a new checkbox with the given settings /// Creates a new checkbox with the given settings

View file

@ -191,51 +191,51 @@ namespace MLEM.Ui.Elements {
/// Set this field to false to disallow the element from being selected. /// Set this field to false to disallow the element from being selected.
/// An unselectable element is skipped by automatic navigation and its <see cref="OnSelected"/> callback will never be called. /// An unselectable element is skipped by automatic navigation and its <see cref="OnSelected"/> callback will never be called.
/// </summary> /// </summary>
public bool CanBeSelected = true; public virtual bool CanBeSelected { get; set; } = true;
/// <summary> /// <summary>
/// Set this field to false to disallow the element from reacting to being moused over. /// Set this field to false to disallow the element from reacting to being moused over.
/// </summary> /// </summary>
public bool CanBeMoused = true; public virtual bool CanBeMoused { get; set; } = true;
/// <summary> /// <summary>
/// Set this field to false to disallow this element's <see cref="OnPressed"/> and <see cref="OnSecondaryPressed"/> events to be called. /// Set this field to false to disallow this element's <see cref="OnPressed"/> and <see cref="OnSecondaryPressed"/> events to be called.
/// </summary> /// </summary>
public bool CanBePressed = true; public virtual bool CanBePressed { get; set; } = true;
/// <summary> /// <summary>
/// Set this field to false to cause auto-anchored siblings to ignore this element as a possible anchor point. /// Set this field to false to cause auto-anchored siblings to ignore this element as a possible anchor point.
/// </summary> /// </summary>
public bool CanAutoAnchorsAttach = true; public virtual bool CanAutoAnchorsAttach { get; set; } = true;
/// <summary> /// <summary>
/// Set this field to true to cause this element's width to be automatically calculated based on the area that its <see cref="Children"/> take up. /// Set this field to true to cause this element's width to be automatically calculated based on the area that its <see cref="Children"/> take up.
/// To use this element's <see cref="Size"/>'s X coordinate as a minimum or maximum width rather than ignoring it, set <see cref="TreatSizeAsMinimum"/> or <see cref="TreatSizeAsMaximum"/> to true. /// To use this element's <see cref="Size"/>'s X coordinate as a minimum or maximum width rather than ignoring it, set <see cref="TreatSizeAsMinimum"/> or <see cref="TreatSizeAsMaximum"/> to true.
/// </summary> /// </summary>
public bool SetWidthBasedOnChildren; public virtual bool SetWidthBasedOnChildren { get; set; }
/// <summary> /// <summary>
/// Set this field to true to cause this element's height to be automatically calculated based on the area that its <see cref="Children"/> take up. /// Set this field to true to cause this element's height to be automatically calculated based on the area that its <see cref="Children"/> take up.
/// To use this element's <see cref="Size"/>'s Y coordinate as a minimum or maximum height rather than ignoring it, set <see cref="TreatSizeAsMinimum"/> or <see cref="TreatSizeAsMaximum"/> to true. /// To use this element's <see cref="Size"/>'s Y coordinate as a minimum or maximum height rather than ignoring it, set <see cref="TreatSizeAsMinimum"/> or <see cref="TreatSizeAsMaximum"/> to true.
/// </summary> /// </summary>
public bool SetHeightBasedOnChildren; public virtual bool SetHeightBasedOnChildren { get; set; }
/// <summary> /// <summary>
/// If this field is set to true, and <see cref="SetWidthBasedOnChildren"/> or <see cref="SetHeightBasedOnChildren"/> are enabled, the resulting width or height will always be greather than or equal to this element's <see cref="Size"/>. /// If this field is set to true, and <see cref="SetWidthBasedOnChildren"/> or <see cref="SetHeightBasedOnChildren"/> are enabled, the resulting width or height will always be greather than or equal to this element's <see cref="Size"/>.
/// For example, if an element's <see cref="Size"/>'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. /// For example, if an element's <see cref="Size"/>'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 <see cref="SetWidthBasedOnChildren"/> or <see cref="SetHeightBasedOnChildren"/> are enabled. /// Note that this value only has an effect if <see cref="SetWidthBasedOnChildren"/> or <see cref="SetHeightBasedOnChildren"/> are enabled.
/// </summary> /// </summary>
public bool TreatSizeAsMinimum; public virtual bool TreatSizeAsMinimum { get; set; }
/// <summary> /// <summary>
/// If this field is set to true, and <see cref="SetWidthBasedOnChildren"/> or <see cref="SetHeightBasedOnChildren"/>are enabled, the resulting width or height weill always be less than or equal to this element's <see cref="Size"/>. /// If this field is set to true, and <see cref="SetWidthBasedOnChildren"/> or <see cref="SetHeightBasedOnChildren"/>are enabled, the resulting width or height weill always be less than or equal to this element's <see cref="Size"/>.
/// Note that this value only has an effect if <see cref="SetWidthBasedOnChildren"/> or <see cref="SetHeightBasedOnChildren"/> are enabled. /// Note that this value only has an effect if <see cref="SetWidthBasedOnChildren"/> or <see cref="SetHeightBasedOnChildren"/> are enabled.
/// </summary> /// </summary>
public bool TreatSizeAsMaximum; public virtual bool TreatSizeAsMaximum { get; set; }
/// <summary> /// <summary>
/// Set this field to true to cause this element's final display area to never exceed that of its <see cref="Parent"/>. /// Set this field to true to cause this element's final display area to never exceed that of its <see cref="Parent"/>.
/// If the resulting area is too large, the size of this element is shrunk to fit the target area. /// 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. /// This can be useful if an element should fill the remaining area of a parent exactly.
/// </summary> /// </summary>
public bool PreventParentSpill; public virtual bool PreventParentSpill { get; set; }
/// <summary> /// <summary>
/// The transparency (alpha value) that this element is rendered with. /// The transparency (alpha value) that this element is rendered with.
/// Note that, when <see cref="Draw"/> is called, this alpha value is multiplied with the <see cref="Parent"/>'s alpha value and passed down to this element's <see cref="Children"/>. /// Note that, when <see cref="Draw"/> is called, this alpha value is multiplied with the <see cref="Parent"/>'s alpha value and passed down to this element's <see cref="Children"/>.
/// </summary> /// </summary>
public float DrawAlpha = 1; public virtual float DrawAlpha { get; set; } = 1;
/// <summary> /// <summary>
/// Stores whether this element is currently being moused over or touched. /// Stores whether this element is currently being moused over or touched.
/// </summary> /// </summary>