mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-24 13:38:34 +01:00
Compare commits
No commits in common. "1bbb12a1fae0aa9b08f0ad460b0c11604d689ebf" and "05e320d4f484f6d385cef68b44aa2e91c10b76f1" have entirely different histories.
1bbb12a1fa
...
05e320d4f4
4 changed files with 15 additions and 35 deletions
|
@ -36,7 +36,6 @@ Improvements
|
|||
Fixes
|
||||
- Fixed a crash if a paragraph has a link formatting code, but no font
|
||||
- Fixed tooltips with custom text scale not snapping to the mouse correctly in their first displayed frame
|
||||
- Fixed tooltips not displaying correctly with auto-hiding paragraphs
|
||||
|
||||
### MLEM.Extended
|
||||
Improvements
|
||||
|
|
|
@ -8,7 +8,6 @@ using MLEM.Extensions;
|
|||
using MLEM.Font;
|
||||
using MLEM.Formatting;
|
||||
using MLEM.Formatting.Codes;
|
||||
using MLEM.Input;
|
||||
using MLEM.Misc;
|
||||
using MLEM.Startup;
|
||||
using MLEM.Textures;
|
||||
|
@ -142,10 +141,6 @@ namespace Demos {
|
|||
this.root.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), "Toggle Mouse Tooltip") {
|
||||
OnPressed = element => tooltip.IsHidden = !tooltip.IsHidden
|
||||
});
|
||||
var delayed = this.root.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), "Delayed Tooltip") {PositionOffset = new Vector2(0, 1)});
|
||||
delayed.AddTooltip(50, "This tooltip appears with a half second delay!").Delay = TimeSpan.FromSeconds(0.5);
|
||||
var condition = this.root.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), "Hold Ctrl for Tooltip") {PositionOffset = new Vector2(0, 1)});
|
||||
condition.AddTooltip(50, p => this.InputHandler.IsModifierKeyDown(ModifierKey.Control) ? "This tooltip only appears when holding control!" : string.Empty);
|
||||
|
||||
var slider = new Slider(Anchor.AutoLeft, new Vector2(1, 10), 5, 1) {
|
||||
StepPerScroll = 0.01F
|
||||
|
|
|
@ -649,8 +649,8 @@ namespace MLEM.Ui.Elements {
|
|||
autoSize.Y = lowest.UnscrolledArea.Bottom - pos.Y + this.ScaledChildPadding.Bottom;
|
||||
foundChild = lowest;
|
||||
} else {
|
||||
if (this.Children.Any(e => !e.IsHidden))
|
||||
throw new InvalidOperationException($"{this} with root {this.Root.Name} sets its height based on children but it only has visible children anchored too low ({string.Join(", ", this.Children.Where(c => !c.IsHidden).Select(c => c.Anchor))})");
|
||||
if (this.Children.Count > 0)
|
||||
throw new InvalidOperationException($"{this} with root {this.Root.Name} sets its height based on children but it only has children anchored too low ({string.Join(", ", this.Children.Select(c => c.Anchor))})");
|
||||
autoSize.Y = 0;
|
||||
}
|
||||
}
|
||||
|
@ -661,8 +661,8 @@ namespace MLEM.Ui.Elements {
|
|||
autoSize.X = rightmost.UnscrolledArea.Right - pos.X + this.ScaledChildPadding.Right;
|
||||
foundChild = rightmost;
|
||||
} else {
|
||||
if (this.Children.Any(e => !e.IsHidden))
|
||||
throw new InvalidOperationException($"{this} with root {this.Root.Name} sets its width based on children but it only has visible children anchored too far right ({string.Join(", ", this.Children.Where(c => !c.IsHidden).Select(c => c.Anchor))})");
|
||||
if (this.Children.Count > 0)
|
||||
throw new InvalidOperationException($"{this} with root {this.Root.Name} sets its width based on children but it only has children anchored too far right ({string.Join(", ", this.Children.Select(c => c.Anchor))})");
|
||||
autoSize.X = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ namespace MLEM.Ui.Elements {
|
|||
public Paragraph Paragraph;
|
||||
|
||||
private TimeSpan delayCountdown;
|
||||
private bool autoHidden;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new tooltip with the given settings
|
||||
|
@ -56,14 +55,10 @@ namespace MLEM.Ui.Elements {
|
|||
base.Update(time);
|
||||
this.SnapPositionToMouse();
|
||||
|
||||
if (this.delayCountdown > TimeSpan.Zero) {
|
||||
if (this.IsHidden && this.delayCountdown > TimeSpan.Zero) {
|
||||
this.delayCountdown -= time.ElapsedGameTime;
|
||||
if (this.delayCountdown <= TimeSpan.Zero) {
|
||||
if (this.delayCountdown <= TimeSpan.Zero)
|
||||
this.IsHidden = false;
|
||||
this.UpdateAutoHidden();
|
||||
}
|
||||
} else {
|
||||
this.UpdateAutoHidden();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,7 +111,6 @@ namespace MLEM.Ui.Elements {
|
|||
this.IsHidden = true;
|
||||
this.delayCountdown = this.Delay;
|
||||
}
|
||||
this.autoHidden = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -133,7 +127,15 @@ namespace MLEM.Ui.Elements {
|
|||
/// </summary>
|
||||
/// <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) {
|
||||
elementToHover.OnMouseEnter += element => this.Display(element.System, element.GetType().Name + "Tooltip");
|
||||
elementToHover.OnMouseEnter += element => {
|
||||
// only display the tooltip if there is anything in it
|
||||
foreach (var c in this.Children) {
|
||||
if (!c.IsHidden) {
|
||||
this.Display(element.System, element.GetType().Name + "Tooltip");
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
elementToHover.OnMouseExit += element => this.Remove();
|
||||
}
|
||||
|
||||
|
@ -150,21 +152,5 @@ namespace MLEM.Ui.Elements {
|
|||
this.AddToElement(elementToHover);
|
||||
}
|
||||
|
||||
private void UpdateAutoHidden() {
|
||||
var shouldBeHidden = true;
|
||||
foreach (var child in this.Children) {
|
||||
if (!child.IsHidden) {
|
||||
shouldBeHidden = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this.autoHidden != shouldBeHidden) {
|
||||
// only auto-hide if IsHidden wasn't changed manually
|
||||
if (this.IsHidden == this.autoHidden)
|
||||
this.IsHidden = shouldBeHidden;
|
||||
this.autoHidden = shouldBeHidden;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue