Fixed elements' OnDeselected events not being raised when CanBeSelected is set to false while selected

This commit is contained in:
Ell 2022-05-21 20:42:54 +02:00
parent bd9d3f970b
commit fcca5300ae
3 changed files with 10 additions and 3 deletions

View File

@ -42,6 +42,7 @@ Fixes
- Fixed radio buttons not unchecking all other radio buttons with the same root element
- Fixed elements not being deselected when removed through RemoveChild
- Fixed elements sometimes staying hidden when they shouldn't in scrolling panels
- Fixed elements' OnDeselected events not being raised when CanBeSelected is set to false while selected
Removals
- Marked old Draw and DrawTransformed overloads as obsolete in favor of SpriteBatchContext ones

View File

@ -193,7 +193,14 @@ 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 <see cref="OnSelected"/> callback will never be called.
/// </summary>
public virtual bool CanBeSelected { get; set; } = true;
public virtual bool CanBeSelected {
get => this.canBeSelected;
set {
this.canBeSelected = value;
if (!this.canBeSelected && this.Root?.SelectedElement == this)
this.Root.SelectElement(null);
}
}
/// <summary>
/// Set this field to false to disallow the element from reacting to being moused over.
/// </summary>
@ -429,6 +436,7 @@ namespace MLEM.Ui.Elements {
private int priority;
private StyleProp<UiStyle> style;
private StyleProp<Padding> childPadding;
private bool canBeSelected = true;
/// <summary>
/// Creates a new element with the given anchor and size and sets up some default event reactions.

View File

@ -355,8 +355,6 @@ namespace MLEM.Ui {
if (root == null)
return null;
this.selectedElements.TryGetValue(root.Name, out var element);
if (element != null && !element.CanBeSelected)
return null;
return element;
}