diff --git a/MLEM.Ui/Elements/Tooltip.cs b/MLEM.Ui/Elements/Tooltip.cs
index 168ea4a..0282368 100644
--- a/MLEM.Ui/Elements/Tooltip.cs
+++ b/MLEM.Ui/Elements/Tooltip.cs
@@ -84,16 +84,16 @@ namespace MLEM.Ui.Elements {
/// Causes this tooltip's position to be snapped to the mouse position.
///
public void SnapPositionToMouse() {
- var (w, h) = this.System.Viewport.Size;
+ var viewport = this.System.Viewport;
var offset = (this.Input.MousePosition.ToVector2() + this.MouseOffset.Value) / this.Scale;
- if (offset.X < 0)
- offset.X = 0;
- if (offset.Y < 0)
- offset.Y = 0;
- if (offset.X * this.Scale + this.Area.Width >= w)
- offset.X = (w - this.Area.Width) / this.Scale;
- if (offset.Y * this.Scale + this.Area.Height >= h)
- offset.Y = (h - this.Area.Height) / 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;
}
diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs
index 8ea0465..d935730 100644
--- a/MLEM.Ui/UiSystem.cs
+++ b/MLEM.Ui/UiSystem.cs
@@ -25,17 +25,13 @@ namespace MLEM.Ui {
/// The graphics device that this ui system uses for its size calculations
///
public readonly GraphicsDevice GraphicsDevice;
- ///
- /// The game window that this ui system renders within
- ///
- public readonly GameWindow Window;
private readonly List rootElements = new List();
///
/// The viewport that this ui system is rendering inside of.
/// This is automatically updated during
///
- public Rectangle Viewport { get; private set; }
+ public Rectangle Viewport;
///
/// Set this field to true to cause the ui system and all of its elements to automatically scale up or down with greater and lower resolution, respectively.
/// If this field is true, is used as the size that uses default
@@ -184,22 +180,24 @@ namespace MLEM.Ui {
/// The graphics device that should be used for viewport calculations
/// The style settings that this ui should have. Use for the default, untextured style.
/// The input handler that this ui's should use. If none is supplied, a new input handler is created for this ui.
- public UiSystem(Game game, GraphicsDevice device, UiStyle style, InputHandler inputHandler = null) : base(game) {
+ /// If this value is set to true, the ui system's will be set automatically based on the 's size. Defaults to true.
+ public UiSystem(Game game, GraphicsDevice device, UiStyle style, InputHandler inputHandler = null, bool automaticViewport = true) : base(game) {
this.Controls = new UiControls(this, inputHandler);
this.GraphicsDevice = device;
- this.Window = game.Window;
this.style = style;
- this.Viewport = new Rectangle(Point.Zero, this.Window.ClientBounds.Size);
- this.AutoScaleReferenceSize = this.Viewport.Size;
- this.Window.ClientSizeChanged += (sender, args) => {
- this.Viewport = new Rectangle(Point.Zero, this.Window.ClientBounds.Size);
- foreach (var root in this.rootElements)
- root.Element.ForceUpdateArea();
- };
+ if (automaticViewport) {
+ this.Viewport = new Rectangle(Point.Zero, game.Window.ClientBounds.Size);
+ this.AutoScaleReferenceSize = this.Viewport.Size;
+ game.Window.ClientSizeChanged += (sender, args) => {
+ this.Viewport = new Rectangle(Point.Zero, game.Window.ClientBounds.Size);
+ foreach (var root in this.rootElements)
+ root.Element.ForceUpdateArea();
+ };
+ }
if (TextInputWrapper.Current != null)
- TextInputWrapper.Current.AddListener(this.Window, (sender, key, character) => this.ApplyToAll(e => e.OnTextInput?.Invoke(e, key, character)));
+ TextInputWrapper.Current.AddListener(game.Window, (sender, key, character) => this.ApplyToAll(e => e.OnTextInput?.Invoke(e, key, character)));
this.OnMousedElementChanged = e => this.ApplyToAll(t => t.OnMousedElementChanged?.Invoke(t, e));
this.OnTouchedElementChanged = e => this.ApplyToAll(t => t.OnTouchedElementChanged?.Invoke(t, e));
this.OnSelectedElementChanged = e => this.ApplyToAll(t => t.OnSelectedElementChanged?.Invoke(t, e));