1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-25 05:58:35 +01:00

Compare commits

...

4 commits

6 changed files with 13 additions and 26 deletions

View file

@ -60,6 +60,9 @@ Fixes
- 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 - 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 and Element.IsSelected returning incorrect results when CanBeSelected changes
- Fixed dropdowns with some non-selectable children failing to navigate when using gamepad controls
Removals Removals
- Marked StyleProp equality members as obsolete - Marked StyleProp equality members as obsolete

View file

@ -63,10 +63,10 @@ namespace MLEM.Ui.Elements {
if (dir == Direction2.Left || dir == Direction2.Right) if (dir == Direction2.Left || dir == Direction2.Right)
return null; return null;
if (dir == Direction2.Up) { if (dir == Direction2.Up) {
var prev = element.GetOlderSibling(); var prev = element.GetOlderSibling(e => e.CanBeSelected);
return prev ?? this; return prev ?? this;
} else if (dir == Direction2.Down) { } else if (dir == Direction2.Down) {
return element.GetSiblings(e => e.GetOlderSibling() == element).FirstOrDefault(); return element.GetSiblings(e => e.CanBeSelected && e.GetOlderSibling(s => s.CanBeSelected) == element).FirstOrDefault();
} }
return usualNext; return usualNext;
}; };

View file

@ -241,9 +241,9 @@ namespace MLEM.Ui.Elements {
/// </summary> /// </summary>
public bool IsMouseOver { get; protected set; } public bool IsMouseOver { get; protected set; }
/// <summary> /// <summary>
/// Stores whether this element is its <see cref="Root"/>'s <see cref="RootElement.SelectedElement"/>. /// Returns whether this element is its <see cref="Root"/>'s <see cref="RootElement.SelectedElement"/>.
/// </summary> /// </summary>
public bool IsSelected { get; protected set; } public bool IsSelected => this.Root.SelectedElement == this;
/// <summary> /// <summary>
/// Returns whether this element's <see cref="SetAreaDirty"/> method has been recently called and its area has not been updated since then using <see cref="UpdateAreaIfDirty"/> or <see cref="ForceUpdateArea"/>. /// Returns whether this element's <see cref="SetAreaDirty"/> method has been recently called and its area has not been updated since then using <see cref="UpdateAreaIfDirty"/> or <see cref="ForceUpdateArea"/>.
/// </summary> /// </summary>
@ -436,8 +436,6 @@ namespace MLEM.Ui.Elements {
this.OnMouseExit += element => this.IsMouseOver = false; this.OnMouseExit += element => this.IsMouseOver = false;
this.OnTouchEnter += element => this.IsMouseOver = true; this.OnTouchEnter += element => this.IsMouseOver = true;
this.OnTouchExit += element => this.IsMouseOver = false; this.OnTouchExit += element => this.IsMouseOver = false;
this.OnSelected += element => this.IsSelected = true;
this.OnDeselected += element => this.IsSelected = false;
this.GetTabNextElement += (backward, next) => next; this.GetTabNextElement += (backward, next) => next;
this.GetGamepadNextElement += (dir, next) => next; this.GetGamepadNextElement += (dir, next) => next;

View file

@ -119,7 +119,8 @@ namespace MLEM.Ui.Elements {
if (!this.scrollOverflow) if (!this.scrollOverflow)
return; return;
var offset = new Vector2(0, -this.ScrollBar.CurrentValue); var offset = new Vector2(0, -this.ScrollBar.CurrentValue);
foreach (var child in this.GetChildren(c => c != this.ScrollBar, true)) { // we ignore false grandchildren so that the children of the scroll bar stay in place
foreach (var child in this.GetChildren(c => c != this.ScrollBar, true, true)) {
if (!child.ScrollOffset.Equals(offset, Epsilon)) { if (!child.ScrollOffset.Equals(offset, Epsilon)) {
child.ScrollOffset = offset; child.ScrollOffset = offset;
this.relevantChildrenDirty = true; this.relevantChildrenDirty = true;

View file

@ -156,7 +156,7 @@ namespace MLEM.Ui {
public virtual void Update() { public virtual void Update() {
if (this.IsInputOurs) if (this.IsInputOurs)
this.Input.Update(); 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 // MOUSE INPUT
if (this.HandleMouse) { 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="element">The element to select, or null to deselect the selected element.</param>
/// <param name="autoNav">Whether automatic navigation should be forced on</param> /// <param name="autoNav">Whether automatic navigation should be forced on</param>
public void SelectElement(RootElement root, Element element, bool? autoNav = null) { public void SelectElement(RootElement root, Element element, bool? autoNav = null) {
if (root == null || !root.CanSelectContent) if (root == null)
return; return;
if (element != null && !element.CanBeSelected) if (element != null && !element.CanBeSelected)
return; return;
@ -337,7 +337,7 @@ namespace MLEM.Ui {
/// <param name="root">The root element whose selected element to return</param> /// <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> /// <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) { public Element GetSelectedElement(RootElement root) {
if (root == null || !root.CanSelectContent) 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) if (element != null && !element.CanBeSelected)

View file

@ -535,7 +535,7 @@ namespace MLEM.Ui {
/// Determines whether this root element contains any children that <see cref="Elements.Element.CanBeSelected"/>. /// Determines whether this root element contains any children that <see cref="Elements.Element.CanBeSelected"/>.
/// This value is automatically calculated. /// This value is automatically calculated.
/// </summary> /// </summary>
public bool CanSelectContent { get; private set; } public bool CanSelectContent => this.Element.CanBeSelected || this.Element.GetChildren(c => c.CanBeSelected, true).Any();
/// <summary> /// <summary>
/// Event that is invoked when a <see cref="Element"/> is added to this root element or any of its children. /// 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.Name = name;
this.Element = element; this.Element = element;
this.System = system; 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> /// <summary>