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.
c5b2b8798e
...
fa34258bbe
6 changed files with 26 additions and 13 deletions
|
@ -60,9 +60,6 @@ Fixes
|
|||
- 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 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
|
||||
- Marked StyleProp equality members as obsolete
|
||||
|
|
|
@ -63,10 +63,10 @@ namespace MLEM.Ui.Elements {
|
|||
if (dir == Direction2.Left || dir == Direction2.Right)
|
||||
return null;
|
||||
if (dir == Direction2.Up) {
|
||||
var prev = element.GetOlderSibling(e => e.CanBeSelected);
|
||||
var prev = element.GetOlderSibling();
|
||||
return prev ?? this;
|
||||
} 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;
|
||||
};
|
||||
|
|
|
@ -241,9 +241,9 @@ namespace MLEM.Ui.Elements {
|
|||
/// </summary>
|
||||
public bool IsMouseOver { get; protected set; }
|
||||
/// <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>
|
||||
public bool IsSelected => this.Root.SelectedElement == this;
|
||||
public bool IsSelected { get; protected set; }
|
||||
/// <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"/>.
|
||||
/// </summary>
|
||||
|
@ -436,6 +436,8 @@ namespace MLEM.Ui.Elements {
|
|||
this.OnMouseExit += element => this.IsMouseOver = false;
|
||||
this.OnTouchEnter += element => this.IsMouseOver = true;
|
||||
this.OnTouchExit += element => this.IsMouseOver = false;
|
||||
this.OnSelected += element => this.IsSelected = true;
|
||||
this.OnDeselected += element => this.IsSelected = false;
|
||||
this.GetTabNextElement += (backward, next) => next;
|
||||
this.GetGamepadNextElement += (dir, next) => next;
|
||||
|
||||
|
|
|
@ -119,8 +119,7 @@ namespace MLEM.Ui.Elements {
|
|||
if (!this.scrollOverflow)
|
||||
return;
|
||||
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, true)) {
|
||||
foreach (var child in this.GetChildren(c => c != this.ScrollBar, true)) {
|
||||
if (!child.ScrollOffset.Equals(offset, Epsilon)) {
|
||||
child.ScrollOffset = offset;
|
||||
this.relevantChildrenDirty = true;
|
||||
|
|
|
@ -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.Element.IsHidden && root.CanSelectContent);
|
||||
this.ActiveRoot = this.System.GetRootElements().FirstOrDefault(root => root.CanSelectContent && !root.Element.IsHidden);
|
||||
|
||||
// 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)
|
||||
if (root == null || !root.CanSelectContent)
|
||||
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)
|
||||
if (root == null || !root.CanSelectContent)
|
||||
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 => this.Element.CanBeSelected || this.Element.GetChildren(c => c.CanBeSelected, true).Any();
|
||||
public bool CanSelectContent { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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.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