1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-01 05:10:50 +01:00

Added Tooltip.IgnoreViewport and allow overriding the default viewport using Tooltip.Viewport

This commit is contained in:
Ell 2024-10-08 18:07:38 +02:00
parent db2a3dfe70
commit d2774ad7d2
2 changed files with 26 additions and 14 deletions

View file

@ -26,6 +26,7 @@ Fixes
Additions Additions
- Added Panel.IsVisible method to check if a child element is visible - Added Panel.IsVisible method to check if a child element is visible
- Added TextField.OnEnterPressed event - Added TextField.OnEnterPressed event
- Added Tooltip.IgnoreViewport and allow overriding the default viewport using Tooltip.Viewport
## 7.1.1 ## 7.1.1

View file

@ -91,6 +91,14 @@ namespace MLEM.Ui.Elements {
/// Note that, if <see cref="UseAutoNavBehaviorForMouse"/> is <see langword="true"/>, this value is ignored. /// Note that, if <see cref="UseAutoNavBehaviorForMouse"/> is <see langword="true"/>, this value is ignored.
/// </summary> /// </summary>
public virtual Vector2? SnapPosition { get; set; } public virtual Vector2? SnapPosition { get; set; }
/// <summary>
/// Determines whether this tooltip should ignore its viewport, which is either this tooltip's <see cref="Viewport"/> or the underlying <see cref="Element.System"/>'s <see cref="UiSystem.Viewport"/>. If this is <see langword="true"/>, the tooltip is allowed to display outside of the viewport, without being bounded in <see cref="SnapPositionToMouse"/>.
/// </summary>
public virtual bool IgnoreViewport { get; set; }
/// <summary>
/// The viewport that this tooltip should be bound to. If this value is unset, the underlying <see cref="Element.System"/>'s <see cref="UiSystem.Viewport"/> will be used. Note that, if <see cref="IgnoreViewport"/> is <see langword="true"/>, this value is ignored.
/// </summary>
public virtual Rectangle? Viewport { get; set; }
/// <inheritdoc /> /// <inheritdoc />
public override bool IsHidden => this.autoHidden || base.IsHidden; public override bool IsHidden => this.autoHidden || base.IsHidden;
@ -207,25 +215,28 @@ namespace MLEM.Ui.Elements {
/// Causes this tooltip's position to be snapped to the mouse position, or the element to snap to if <see cref="DisplayInAutoNavMode"/> is true, or the <see cref="SnapPosition"/> if set. /// Causes this tooltip's position to be snapped to the mouse position, or the element to snap to if <see cref="DisplayInAutoNavMode"/> is true, or the <see cref="SnapPosition"/> if set.
/// </summary> /// </summary>
public void SnapPositionToMouse() { public void SnapPositionToMouse() {
Vector2 snapPosition; Vector2 snap;
if (this.snapElement != null) { if (this.snapElement != null) {
snapPosition = this.GetSnapOffset(this.AutoNavAnchor, this.snapElement.DisplayArea, this.AutoNavOffset); snap = this.GetSnapOffset(this.AutoNavAnchor, this.snapElement.DisplayArea, this.AutoNavOffset) / this.Scale;
} else { } else {
var mouseBounds = new RectangleF(this.SnapPosition ?? this.Input.ViewportMousePosition.ToVector2(), Vector2.Zero); var mouseBounds = new RectangleF(this.SnapPosition ?? this.Input.ViewportMousePosition.ToVector2(), Vector2.Zero);
snapPosition = this.GetSnapOffset(this.MouseAnchor, mouseBounds, this.MouseOffset); snap = this.GetSnapOffset(this.MouseAnchor, mouseBounds, this.MouseOffset) / this.Scale;
} }
var viewport = this.System.Viewport; if (!this.IgnoreViewport) {
var offset = snapPosition / this.Scale; var view = this.Viewport ?? this.System.Viewport;
if (offset.X < viewport.X) if (snap.X < view.X)
offset.X = viewport.X; snap.X = view.X;
if (offset.Y < viewport.Y) if (snap.Y < view.Y)
offset.Y = viewport.Y; snap.Y = view.Y;
if (offset.X * this.Scale + this.Area.Width >= viewport.Right) if (snap.X * this.Scale + this.Area.Width >= view.Right)
offset.X = (viewport.Right - this.Area.Width) / this.Scale; snap.X = (view.Right - this.Area.Width) / this.Scale;
if (offset.Y * this.Scale + this.Area.Height >= viewport.Bottom) if (snap.Y * this.Scale + this.Area.Height >= view.Bottom)
offset.Y = (viewport.Bottom - this.Area.Height) / this.Scale; snap.Y = (view.Bottom - this.Area.Height) / this.Scale;
this.PositionOffset = offset; }
this.PositionOffset = snap;
} }
/// <summary> /// <summary>