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

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 radio buttons not unchecking all other radio buttons with the same root element
- Fixed elements not being deselected when removed through RemoveChild - Fixed elements not being deselected when removed through RemoveChild
- Fixed elements sometimes staying hidden when they shouldn't in scrolling panels - 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 Removals
- Marked old Draw and DrawTransformed overloads as obsolete in favor of SpriteBatchContext ones - 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. /// 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 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> /// <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>
@ -429,6 +436,7 @@ namespace MLEM.Ui.Elements {
private int priority; private int priority;
private StyleProp<UiStyle> style; private StyleProp<UiStyle> style;
private StyleProp<Padding> childPadding; private StyleProp<Padding> childPadding;
private bool canBeSelected = true;
/// <summary> /// <summary>
/// Creates a new element with the given anchor and size and sets up some default event reactions. /// 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) if (root == null)
return null; return null;
this.selectedElements.TryGetValue(root.Name, out var element); this.selectedElements.TryGetValue(root.Name, out var element);
if (element != null && !element.CanBeSelected)
return null;
return element; return element;
} }