1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-25 14:08:34 +01:00

Compare commits

..

No commits in common. "c5b2b8798e3e8fc35944dcf685170a261ecc07aa" and "fa34258bbefe879fb1f297a9eb5351b1e13c424a" have entirely different histories.

6 changed files with 26 additions and 13 deletions

View file

@ -60,9 +60,6 @@ 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(e => e.CanBeSelected); var prev = element.GetOlderSibling();
return prev ?? this; return prev ?? this;
} else if (dir == Direction2.Down) { } else if (dir == Direction2.Down) {
return element.GetSiblings(e => e.CanBeSelected && e.GetOlderSibling(s => s.CanBeSelected) == element).FirstOrDefault(); return element.GetSiblings(e => e.GetOlderSibling() == 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>
/// Returns whether this element is its <see cref="Root"/>'s <see cref="RootElement.SelectedElement"/>. /// Stores whether this element is its <see cref="Root"/>'s <see cref="RootElement.SelectedElement"/>.
/// </summary> /// </summary>
public bool IsSelected => this.Root.SelectedElement == this; public bool IsSelected { get; protected set; }
/// <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,6 +436,8 @@ 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,8 +119,7 @@ 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);
// 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)) {
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.Element.IsHidden && root.CanSelectContent); this.ActiveRoot = this.System.GetRootElements().FirstOrDefault(root => root.CanSelectContent && !root.Element.IsHidden);
// 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) if (root == null || !root.CanSelectContent)
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) if (root == null || !root.CanSelectContent)
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 => this.Element.CanBeSelected || this.Element.GetChildren(c => c.CanBeSelected, true).Any(); public bool CanSelectContent { get; private set; }
/// <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,6 +558,21 @@ 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>