1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 06:28:35 +01:00

Compare commits

..

No commits in common. "3bc5c7f18c7fdc3c90f427ac79ffbedf0ff16072" and "db2a3dfe702ec4920881d2447f719b45ba3a241e" have entirely different histories.

2 changed files with 14 additions and 29 deletions

View file

@ -26,10 +26,6 @@ Fixes
Additions
- Added Panel.IsVisible method to check if a child element is visible
- Added TextField.OnEnterPressed event
- Added Tooltip.IgnoreViewport and allow overriding the default viewport using Tooltip.Viewport
Fixes
- Fixed tooltips not being bounded correctly for viewports that don't start at the origin
## 7.1.1

View file

@ -91,14 +91,6 @@ namespace MLEM.Ui.Elements {
/// Note that, if <see cref="UseAutoNavBehaviorForMouse"/> is <see langword="true"/>, this value is ignored.
/// </summary>
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 />
public override bool IsHidden => this.autoHidden || base.IsHidden;
@ -215,28 +207,25 @@ 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.
/// </summary>
public void SnapPositionToMouse() {
Vector2 snap;
Vector2 snapPosition;
if (this.snapElement != null) {
snap = this.GetSnapOffset(this.AutoNavAnchor, this.snapElement.DisplayArea, this.AutoNavOffset) / this.Scale;
snapPosition = this.GetSnapOffset(this.AutoNavAnchor, this.snapElement.DisplayArea, this.AutoNavOffset);
} else {
var mouseBounds = new RectangleF(this.SnapPosition ?? this.Input.ViewportMousePosition.ToVector2(), Vector2.Zero);
snap = this.GetSnapOffset(this.MouseAnchor, mouseBounds, this.MouseOffset) / this.Scale;
snapPosition = this.GetSnapOffset(this.MouseAnchor, mouseBounds, this.MouseOffset);
}
if (!this.IgnoreViewport) {
var view = this.Viewport ?? this.System.Viewport;
if (snap.X * this.Scale < view.X)
snap.X = view.X / this.Scale;
if (snap.Y * this.Scale < view.Y)
snap.Y = view.Y / this.Scale;
if (snap.X * this.Scale + this.Area.Width >= view.Right)
snap.X = (view.Right - this.Area.Width) / this.Scale;
if (snap.Y * this.Scale + this.Area.Height >= view.Bottom)
snap.Y = (view.Bottom - this.Area.Height) / this.Scale;
}
this.PositionOffset = snap;
var viewport = this.System.Viewport;
var offset = snapPosition / this.Scale;
if (offset.X < viewport.X)
offset.X = viewport.X;
if (offset.Y < viewport.Y)
offset.Y = viewport.Y;
if (offset.X * this.Scale + this.Area.Width >= viewport.Right)
offset.X = (viewport.Right - this.Area.Width) / this.Scale;
if (offset.Y * this.Scale + this.Area.Height >= viewport.Bottom)
offset.Y = (viewport.Bottom - this.Area.Height) / this.Scale;
this.PositionOffset = offset;
}
/// <summary>