mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 05:58:35 +01:00
Compare commits
3 commits
f445f59078
...
be26a2ebc2
Author | SHA1 | Date | |
---|---|---|---|
be26a2ebc2 | |||
45afd9ac79 | |||
ad29b46df3 |
4 changed files with 25 additions and 13 deletions
|
@ -14,8 +14,12 @@ Additions
|
||||||
- Added consuming variants of IsPressed methods to InputHandler
|
- Added consuming variants of IsPressed methods to InputHandler
|
||||||
|
|
||||||
### MLEM.Ui
|
### MLEM.Ui
|
||||||
|
Additions
|
||||||
|
- Added Element.AutoNavGroup which allows forming groups for auto-navigation
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
- Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode
|
- Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode
|
||||||
|
- Fixed radio buttons not unchecking all other radio buttons with the same root element
|
||||||
|
|
||||||
## 5.3.0
|
## 5.3.0
|
||||||
### MLEM
|
### MLEM
|
||||||
|
|
|
@ -249,6 +249,12 @@ namespace MLEM.Ui.Elements {
|
||||||
/// 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>
|
||||||
public bool AreaDirty { get; private set; }
|
public bool AreaDirty { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// An optional string that represents a group of elements for automatic (keyboard and gamepad) navigation.
|
||||||
|
/// All elements that share the same auto-nav group will be able to be navigated between, and all other elements will not be reachable from elements of other groups.
|
||||||
|
/// Note that, if no element is previously selected and auto-navigation is invoked, this element can always be navigated to if it is the first one chosen by auto-navigation.
|
||||||
|
/// </summary>
|
||||||
|
public virtual string AutoNavGroup { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This Element's current <see cref="UiStyle"/>.
|
/// This Element's current <see cref="UiStyle"/>.
|
||||||
|
|
|
@ -4,7 +4,7 @@ using MLEM.Ui.Style;
|
||||||
namespace MLEM.Ui.Elements {
|
namespace MLEM.Ui.Elements {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A radio button element to use inside of a <see cref="UiSystem"/>.
|
/// A radio button element to use inside of a <see cref="UiSystem"/>.
|
||||||
/// A radio button is a variation of a <see cref="Checkbox"/> that causes all other radio buttons in the same <see cref="Group"/> to be deselected upon selection.
|
/// A radio button is a variation of a <see cref="Checkbox"/> that causes all other radio buttons in the same <see cref="RootElement"/> to be deselected upon selection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RadioButton : Checkbox {
|
public class RadioButton : Checkbox {
|
||||||
|
|
||||||
|
@ -26,13 +26,13 @@ namespace MLEM.Ui.Elements {
|
||||||
base(anchor, size, label, defaultChecked) {
|
base(anchor, size, label, defaultChecked) {
|
||||||
this.Group = group;
|
this.Group = group;
|
||||||
|
|
||||||
// don't += because we want to override the checking + unchecking behavior of Checkbox
|
// don't += because we want to override the checking/unchecking behavior of Checkbox
|
||||||
this.OnPressed = element => {
|
this.OnPressed = element => {
|
||||||
this.Checked = true;
|
this.Checked = true;
|
||||||
foreach (var sib in this.GetSiblings()) {
|
this.Root.Element.AndChildren(e => {
|
||||||
if (sib is RadioButton radio && radio.Group == this.Group)
|
if (e != this && e is RadioButton r && r.Group == this.Group)
|
||||||
radio.Checked = false;
|
r.Checked = false;
|
||||||
}
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -353,15 +353,15 @@ namespace MLEM.Ui {
|
||||||
protected virtual Element GetTabNextElement(bool backward) {
|
protected virtual Element GetTabNextElement(bool backward) {
|
||||||
if (this.ActiveRoot == null)
|
if (this.ActiveRoot == null)
|
||||||
return null;
|
return null;
|
||||||
var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Append(this.ActiveRoot.Element);
|
var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Append(this.ActiveRoot.Element)
|
||||||
|
// we can't add these checks to GetChildren because it ignores false grandchildren
|
||||||
|
.Where(c => c.CanBeSelected && c.AutoNavGroup == this.SelectedElement?.AutoNavGroup);
|
||||||
if (this.SelectedElement?.Root != this.ActiveRoot) {
|
if (this.SelectedElement?.Root != this.ActiveRoot) {
|
||||||
return backward ? children.LastOrDefault(c => c.CanBeSelected) : children.FirstOrDefault(c => c.CanBeSelected);
|
return backward ? children.LastOrDefault() : children.FirstOrDefault();
|
||||||
} else {
|
} else {
|
||||||
var foundCurr = false;
|
var foundCurr = false;
|
||||||
Element lastFound = null;
|
Element lastFound = null;
|
||||||
foreach (var child in children) {
|
foreach (var child in children) {
|
||||||
if (!child.CanBeSelected)
|
|
||||||
continue;
|
|
||||||
if (child == this.SelectedElement) {
|
if (child == this.SelectedElement) {
|
||||||
// when going backwards, return the last element found before the current one
|
// when going backwards, return the last element found before the current one
|
||||||
if (backward)
|
if (backward)
|
||||||
|
@ -386,14 +386,16 @@ namespace MLEM.Ui {
|
||||||
protected virtual Element GetGamepadNextElement(Direction2 direction) {
|
protected virtual Element GetGamepadNextElement(Direction2 direction) {
|
||||||
if (this.ActiveRoot == null)
|
if (this.ActiveRoot == null)
|
||||||
return null;
|
return null;
|
||||||
var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Append(this.ActiveRoot.Element);
|
var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Append(this.ActiveRoot.Element)
|
||||||
|
// we can't add these checks to GetChildren because it ignores false grandchildren
|
||||||
|
.Where(c => c.CanBeSelected && c.AutoNavGroup == this.SelectedElement?.AutoNavGroup);
|
||||||
if (this.SelectedElement?.Root != this.ActiveRoot) {
|
if (this.SelectedElement?.Root != this.ActiveRoot) {
|
||||||
return children.FirstOrDefault(c => c.CanBeSelected);
|
return children.FirstOrDefault();
|
||||||
} else {
|
} else {
|
||||||
Element closest = null;
|
Element closest = null;
|
||||||
float closestPriority = 0;
|
float closestPriority = 0;
|
||||||
foreach (var child in children) {
|
foreach (var child in children) {
|
||||||
if (!child.CanBeSelected || child == this.SelectedElement)
|
if (child == this.SelectedElement)
|
||||||
continue;
|
continue;
|
||||||
var (xOffset, yOffset) = child.Area.Center - this.SelectedElement.Area.Center;
|
var (xOffset, yOffset) = child.Area.Center - this.SelectedElement.Area.Center;
|
||||||
var angle = Math.Abs(direction.Angle() - (float) Math.Atan2(yOffset, xOffset));
|
var angle = Math.Abs(direction.Angle() - (float) Math.Atan2(yOffset, xOffset));
|
||||||
|
|
Loading…
Reference in a new issue