mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
Fixed RootElement.CanSelectContent returning incorrect results when CanBeSelected changes in children
This commit is contained in:
parent
bb22bbdf75
commit
4aff5a2875
3 changed files with 5 additions and 19 deletions
|
@ -61,6 +61,7 @@ Fixes
|
|||
- 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
|
||||
- Fixed children of Panel scroll bars also being scrolled
|
||||
- Fixed RootElement.CanSelectContent returning incorrect results when CanBeSelected changes in children
|
||||
|
||||
Removals
|
||||
- Marked StyleProp equality members as obsolete
|
||||
|
|
|
@ -156,7 +156,7 @@ namespace MLEM.Ui {
|
|||
public virtual void Update() {
|
||||
if (this.IsInputOurs)
|
||||
this.Input.Update();
|
||||
this.ActiveRoot = this.System.GetRootElements().FirstOrDefault(root => root.CanSelectContent && !root.Element.IsHidden);
|
||||
this.ActiveRoot = this.System.GetRootElements().FirstOrDefault(root => !root.Element.IsHidden && root.CanSelectContent);
|
||||
|
||||
// MOUSE INPUT
|
||||
if (this.HandleMouse) {
|
||||
|
@ -274,7 +274,7 @@ namespace MLEM.Ui {
|
|||
/// <param name="element">The element to select, or null to deselect the selected element.</param>
|
||||
/// <param name="autoNav">Whether automatic navigation should be forced on</param>
|
||||
public void SelectElement(RootElement root, Element element, bool? autoNav = null) {
|
||||
if (root == null || !root.CanSelectContent)
|
||||
if (root == null)
|
||||
return;
|
||||
if (element != null && !element.CanBeSelected)
|
||||
return;
|
||||
|
@ -337,7 +337,7 @@ namespace MLEM.Ui {
|
|||
/// <param name="root">The root element whose selected element to return</param>
|
||||
/// <returns>The given root's selected element, or null if the root doesn't exist, or if there is no selected element for that root.</returns>
|
||||
public Element GetSelectedElement(RootElement root) {
|
||||
if (root == null || !root.CanSelectContent)
|
||||
if (root == null)
|
||||
return null;
|
||||
this.selectedElements.TryGetValue(root.Name, out var element);
|
||||
if (element != null && !element.CanBeSelected)
|
||||
|
|
|
@ -535,7 +535,7 @@ namespace MLEM.Ui {
|
|||
/// Determines whether this root element contains any children that <see cref="Elements.Element.CanBeSelected"/>.
|
||||
/// This value is automatically calculated.
|
||||
/// </summary>
|
||||
public bool CanSelectContent { get; private set; }
|
||||
public bool CanSelectContent => this.Element.CanBeSelected || this.Element.GetChildren(c => c.CanBeSelected, true).Any();
|
||||
|
||||
/// <summary>
|
||||
/// Event that is invoked when a <see cref="Element"/> is added to this root element or any of its children.
|
||||
|
@ -558,21 +558,6 @@ namespace MLEM.Ui {
|
|||
this.Name = name;
|
||||
this.Element = element;
|
||||
this.System = system;
|
||||
|
||||
this.OnElementAdded += e => {
|
||||
if (e.CanBeSelected)
|
||||
this.CanSelectContent = true;
|
||||
};
|
||||
this.OnElementRemoved += e => {
|
||||
if (e.CanBeSelected) {
|
||||
// check if removing this element removed all other selectable elements
|
||||
foreach (var c in this.Element.GetChildren(regardGrandchildren: true)) {
|
||||
if (c.CanBeSelected)
|
||||
return;
|
||||
}
|
||||
this.CanSelectContent = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in a new issue