mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 05:58:35 +01:00
Compare commits
4 commits
37f0470e4f
...
4854d420e0
Author | SHA1 | Date | |
---|---|---|---|
4854d420e0 | |||
393bd9ffe5 | |||
30b4d5fc43 | |||
df0ad68837 |
7 changed files with 72 additions and 13 deletions
|
@ -59,6 +59,7 @@ Improvements
|
||||||
- Improved gamepad navigation by employing angles between elements
|
- Improved gamepad navigation by employing angles between elements
|
||||||
- Prefer elements that have the same parent as the currently selected element when using gamepad navigation
|
- Prefer elements that have the same parent as the currently selected element when using gamepad navigation
|
||||||
- Allow specifying a custom position for a tooltip to snap to
|
- Allow specifying a custom position for a tooltip to snap to
|
||||||
|
- Allow tooltips to display for elements when selected in auto-nav mode
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
- Fixed paragraph links having incorrect hover locations when using special text alignments
|
- Fixed paragraph links having incorrect hover locations when using special text alignments
|
||||||
|
@ -70,6 +71,8 @@ Fixes
|
||||||
- Fixed RootElement.CanSelectContent and Element.IsSelected returning incorrect results when CanBeSelected changes
|
- 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
|
- Fixed dropdowns with some non-selectable children failing to navigate when using gamepad controls
|
||||||
- Fixed UiMetrics.ForceAreaUpdateTime being inaccurate for nested elements
|
- Fixed UiMetrics.ForceAreaUpdateTime being inaccurate for nested elements
|
||||||
|
- Fixed tooltips sometimes ignoring manually set IsHidden values
|
||||||
|
- Fixed delayed tooltips sometimes displaying in the wrong location for one frame
|
||||||
|
|
||||||
Removals
|
Removals
|
||||||
- Marked StyleProp equality members as obsolete
|
- Marked StyleProp equality members as obsolete
|
||||||
|
|
|
@ -208,6 +208,12 @@ namespace Demos {
|
||||||
this.root.AddChild(new VerticalSpace(3));
|
this.root.AddChild(new VerticalSpace(3));
|
||||||
this.root.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), "Disabled button", "This button can't be clicked or moved to using automatic navigation") {IsDisabled = true}).PositionOffset = new Vector2(0, 1);
|
this.root.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), "Disabled button", "This button can't be clicked or moved to using automatic navigation") {IsDisabled = true}).PositionOffset = new Vector2(0, 1);
|
||||||
this.root.AddChild(new Checkbox(Anchor.AutoLeft, new Vector2(1, 10), "Disabled checkbox") {IsDisabled = true}).PositionOffset = new Vector2(0, 1);
|
this.root.AddChild(new Checkbox(Anchor.AutoLeft, new Vector2(1, 10), "Disabled checkbox") {IsDisabled = true}).PositionOffset = new Vector2(0, 1);
|
||||||
|
this.root.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), "Disabled tooltip button", "This button can't be clicked, but can be moved to using automatic navigation, and will display its tooltip even when done so.") {
|
||||||
|
CanSelectDisabled = true,
|
||||||
|
IsDisabled = true,
|
||||||
|
Tooltip = {DisplayInAutoNavMode = true},
|
||||||
|
PositionOffset = new Vector2(0, 1)
|
||||||
|
});
|
||||||
|
|
||||||
const string alignText = "Paragraphs can have <l Left>left</l> aligned text, <l Right>right</l> aligned text and <l Center>center</l> aligned text.";
|
const string alignText = "Paragraphs can have <l Left>left</l> aligned text, <l Right>right</l> aligned text and <l Center>center</l> aligned text.";
|
||||||
this.root.AddChild(new VerticalSpace(3));
|
this.root.AddChild(new VerticalSpace(3));
|
||||||
|
|
|
@ -63,9 +63,14 @@ namespace MLEM.Ui.Elements {
|
||||||
this.Text.TruncateIfLong = value;
|
this.Text.TruncateIfLong = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Whether this button should be able to be selected even if it <see cref="IsDisabled"/>.
|
||||||
|
/// If this is true, <see cref="CanBeSelected"/> will be able to return true even if <see cref="IsDisabled"/> is true.
|
||||||
|
/// </summary>
|
||||||
|
public bool CanSelectDisabled;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool CanBeSelected => base.CanBeSelected && !this.IsDisabled;
|
public override bool CanBeSelected => base.CanBeSelected && (this.CanSelectDisabled || !this.IsDisabled);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool CanBePressed => base.CanBePressed && !this.IsDisabled;
|
public override bool CanBePressed => base.CanBePressed && !this.IsDisabled;
|
||||||
|
|
||||||
|
|
|
@ -67,9 +67,14 @@ namespace MLEM.Ui.Elements {
|
||||||
/// An event that is invoked when this checkbox's <see cref="Checked"/> property changes
|
/// An event that is invoked when this checkbox's <see cref="Checked"/> property changes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public CheckStateChange OnCheckStateChange;
|
public CheckStateChange OnCheckStateChange;
|
||||||
|
/// <summary>
|
||||||
|
/// Whether this checkbox should be able to be selected even if it <see cref="IsDisabled"/>.
|
||||||
|
/// If this is true, <see cref="CanBeSelected"/> will be able to return true even if <see cref="IsDisabled"/> is true.
|
||||||
|
/// </summary>
|
||||||
|
public bool CanSelectDisabled;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool CanBeSelected => base.CanBeSelected && !this.IsDisabled;
|
public override bool CanBeSelected => base.CanBeSelected && (this.CanSelectDisabled || !this.IsDisabled);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool CanBePressed => base.CanBePressed && !this.IsDisabled;
|
public override bool CanBePressed => base.CanBePressed && !this.IsDisabled;
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,7 @@ namespace MLEM.Ui.Elements {
|
||||||
/// Set this property to <c>true</c> to cause this element to be hidden.
|
/// Set this property to <c>true</c> to cause this element to be hidden.
|
||||||
/// Hidden elements don't receive input events, aren't rendered and don't factor into auto-anchoring.
|
/// Hidden elements don't receive input events, aren't rendered and don't factor into auto-anchoring.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsHidden {
|
public virtual bool IsHidden {
|
||||||
get => this.isHidden;
|
get => this.isHidden;
|
||||||
set {
|
set {
|
||||||
if (this.isHidden == value)
|
if (this.isHidden == value)
|
||||||
|
|
|
@ -16,6 +16,10 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public StyleProp<Vector2> MouseOffset;
|
public StyleProp<Vector2> MouseOffset;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// The offset that this tooltip's top center coordinate should have from the bottom center of the element snapped to when <see cref="DisplayInAutoNavMode"/> is true.
|
||||||
|
/// </summary>
|
||||||
|
public StyleProp<Vector2> AutoNavOffset;
|
||||||
|
/// <summary>
|
||||||
/// The amount of time that the mouse has to be over an element before it appears
|
/// The amount of time that the mouse has to be over an element before it appears
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public StyleProp<TimeSpan> Delay;
|
public StyleProp<TimeSpan> Delay;
|
||||||
|
@ -24,14 +28,23 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Paragraph Paragraph;
|
public Paragraph Paragraph;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Determines whether this tooltip should display when <see cref="UiControls.IsAutoNavMode"/> is true, which is when the UI is being controlled using a keyboard or gamepad.
|
||||||
|
/// If this tooltip is displayed in auto-nav mode, it will display below the selected element with the <see cref="AutoNavOffset"/> applied.
|
||||||
|
/// </summary>
|
||||||
|
public bool DisplayInAutoNavMode;
|
||||||
|
/// <summary>
|
||||||
/// The position that this tooltip should be following (or snapped to) instead of the <see cref="InputHandler.ViewportMousePosition"/>.
|
/// The position that this tooltip should be following (or snapped to) instead of the <see cref="InputHandler.ViewportMousePosition"/>.
|
||||||
/// If this value is unset, <see cref="InputHandler.ViewportMousePosition"/> will be used as the snap position.
|
/// If this value is unset, <see cref="InputHandler.ViewportMousePosition"/> will be used as the snap position.
|
||||||
/// Note that <see cref="MouseOffset"/> is still applied with this value set.
|
/// Note that <see cref="MouseOffset"/> is still applied with this value set.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual Vector2? SnapPosition { get; set; }
|
public virtual Vector2? SnapPosition { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override bool IsHidden => this.autoHidden || base.IsHidden;
|
||||||
|
|
||||||
private TimeSpan delayCountdown;
|
private TimeSpan delayCountdown;
|
||||||
private bool autoHidden;
|
private bool autoHidden;
|
||||||
|
private Element snapElement;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new tooltip with the given settings
|
/// Creates a new tooltip with the given settings
|
||||||
|
@ -66,6 +79,7 @@ namespace MLEM.Ui.Elements {
|
||||||
if (this.delayCountdown <= TimeSpan.Zero) {
|
if (this.delayCountdown <= TimeSpan.Zero) {
|
||||||
this.IsHidden = false;
|
this.IsHidden = false;
|
||||||
this.UpdateAutoHidden();
|
this.UpdateAutoHidden();
|
||||||
|
this.SnapPositionToMouse();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.UpdateAutoHidden();
|
this.UpdateAutoHidden();
|
||||||
|
@ -85,6 +99,7 @@ namespace MLEM.Ui.Elements {
|
||||||
base.InitStyle(style);
|
base.InitStyle(style);
|
||||||
this.Texture = this.Texture.OrStyle(style.TooltipBackground);
|
this.Texture = this.Texture.OrStyle(style.TooltipBackground);
|
||||||
this.MouseOffset = this.MouseOffset.OrStyle(style.TooltipOffset);
|
this.MouseOffset = this.MouseOffset.OrStyle(style.TooltipOffset);
|
||||||
|
this.AutoNavOffset = this.AutoNavOffset.OrStyle(style.TooltipAutoNavOffset);
|
||||||
this.Delay = this.Delay.OrStyle(style.TooltipDelay);
|
this.Delay = this.Delay.OrStyle(style.TooltipDelay);
|
||||||
this.ChildPadding = this.ChildPadding.OrStyle(style.TooltipChildPadding);
|
this.ChildPadding = this.ChildPadding.OrStyle(style.TooltipChildPadding);
|
||||||
if (this.Paragraph != null) {
|
if (this.Paragraph != null) {
|
||||||
|
@ -94,12 +109,20 @@ namespace MLEM.Ui.Elements {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Causes this tooltip's position to be snapped to the mouse position.
|
/// Causes this tooltip's position to be snapped to the mouse position, or the <see cref="snapElement"/> if <see cref="DisplayInAutoNavMode"/> is true, or the <see cref="SnapPosition"/> if set.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SnapPositionToMouse() {
|
public void SnapPositionToMouse() {
|
||||||
|
Vector2 snapPosition;
|
||||||
|
if (this.snapElement != null) {
|
||||||
|
// center our snap position below the snap element
|
||||||
|
snapPosition = new Vector2(this.snapElement.DisplayArea.Center.X, this.snapElement.DisplayArea.Bottom) + this.AutoNavOffset;
|
||||||
|
snapPosition.X -= this.DisplayArea.Width / 2F;
|
||||||
|
} else {
|
||||||
|
snapPosition = (this.SnapPosition ?? this.Input.ViewportMousePosition.ToVector2()) + this.MouseOffset.Value;
|
||||||
|
}
|
||||||
|
|
||||||
var viewport = this.System.Viewport;
|
var viewport = this.System.Viewport;
|
||||||
var snapPosition = this.SnapPosition ?? this.Input.ViewportMousePosition.ToVector2();
|
var offset = snapPosition / this.Scale;
|
||||||
var offset = (snapPosition + this.MouseOffset.Value) / this.Scale;
|
|
||||||
if (offset.X < viewport.X)
|
if (offset.X < viewport.X)
|
||||||
offset.X = viewport.X;
|
offset.X = viewport.X;
|
||||||
if (offset.Y < viewport.Y)
|
if (offset.Y < viewport.Y)
|
||||||
|
@ -116,8 +139,10 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="system">The system to add this tooltip to</param>
|
/// <param name="system">The system to add this tooltip to</param>
|
||||||
/// <param name="name">The name that this tooltip should use</param>
|
/// <param name="name">The name that this tooltip should use</param>
|
||||||
public void Display(UiSystem system, string name) {
|
/// <returns>Whether this tooltip was successfully added, which is not the case if it is already being displayed currently.</returns>
|
||||||
system.Add(name, this);
|
public bool Display(UiSystem system, string name) {
|
||||||
|
if (system.Add(name, this) == null)
|
||||||
|
return false;
|
||||||
if (this.Delay <= TimeSpan.Zero) {
|
if (this.Delay <= TimeSpan.Zero) {
|
||||||
this.IsHidden = false;
|
this.IsHidden = false;
|
||||||
this.SnapPositionToMouse();
|
this.SnapPositionToMouse();
|
||||||
|
@ -126,6 +151,7 @@ namespace MLEM.Ui.Elements {
|
||||||
this.delayCountdown = this.Delay;
|
this.delayCountdown = this.Delay;
|
||||||
}
|
}
|
||||||
this.autoHidden = false;
|
this.autoHidden = false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -142,8 +168,20 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="elementToHover">The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively</param>
|
/// <param name="elementToHover">The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively</param>
|
||||||
public void AddToElement(Element elementToHover) {
|
public void AddToElement(Element elementToHover) {
|
||||||
elementToHover.OnMouseEnter += element => this.Display(element.System, element.GetType().Name + "Tooltip");
|
elementToHover.OnMouseEnter += e => this.Display(e.System, $"{e.GetType().Name}Tooltip");
|
||||||
elementToHover.OnMouseExit += element => this.Remove();
|
elementToHover.OnMouseExit += e => this.Remove();
|
||||||
|
elementToHover.OnSelected += e => {
|
||||||
|
if (this.DisplayInAutoNavMode) {
|
||||||
|
this.snapElement = e;
|
||||||
|
this.Display(e.System, $"{e.GetType().Name}Tooltip");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
elementToHover.OnDeselected += e => {
|
||||||
|
if (this.DisplayInAutoNavMode) {
|
||||||
|
this.Remove();
|
||||||
|
this.snapElement = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Init(Element elementToHover) {
|
private void Init(Element elementToHover) {
|
||||||
|
@ -167,10 +205,8 @@ namespace MLEM.Ui.Elements {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.autoHidden != shouldBeHidden) {
|
if (this.autoHidden != shouldBeHidden) {
|
||||||
// only auto-hide if IsHidden wasn't changed manually
|
|
||||||
if (this.IsHidden == this.autoHidden)
|
|
||||||
this.IsHidden = shouldBeHidden;
|
|
||||||
this.autoHidden = shouldBeHidden;
|
this.autoHidden = shouldBeHidden;
|
||||||
|
this.SetAreaDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,6 +151,10 @@ namespace MLEM.Ui.Style {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Vector2 TooltipOffset = new Vector2(8, 16);
|
public Vector2 TooltipOffset = new Vector2(8, 16);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// The offset of the <see cref="Tooltip"/> element's top center coordinate from the bottom center of the element snapped to when <see cref="Tooltip.DisplayInAutoNavMode"/> is true.
|
||||||
|
/// </summary>
|
||||||
|
public Vector2 TooltipAutoNavOffset = new Vector2(0, 8);
|
||||||
|
/// <summary>
|
||||||
/// The color that the text of a <see cref="Tooltip"/> should have
|
/// The color that the text of a <see cref="Tooltip"/> should have
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color TooltipTextColor = Color.White;
|
public Color TooltipTextColor = Color.White;
|
||||||
|
|
Loading…
Reference in a new issue