1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 12:58:33 +01:00

Automatically update all elements when changing a ui system's viewport

This commit is contained in:
Ell 2022-02-06 21:16:35 +01:00
parent ab76ea5ba8
commit ad2784a67e
2 changed files with 11 additions and 4 deletions

View file

@ -36,6 +36,7 @@ Improvements
- Allow setting a default text alignment for paragraphs in UiStyle
- Made custom values of Element.Style persist when a new ui style is set
- Update elements less aggressively when changing a ui system's style
- Automatically update all elements when changing a ui system's viewport
Fixes
- Fixed paragraph links having incorrect hover locations when using special text alignments

View file

@ -23,9 +23,16 @@ namespace MLEM.Ui {
/// <summary>
/// The viewport that this ui system is rendering inside of.
/// This is automatically updated during <see cref="GameWindow.ClientSizeChanged"/>
/// This is automatically updated during <see cref="GameWindow.ClientSizeChanged"/> by default.
/// </summary>
public Rectangle Viewport;
public Rectangle Viewport {
get => this.viewport;
set {
this.viewport = value;
foreach (var root in this.rootElements)
root.Element.ForceUpdateArea();
}
}
/// <summary>
/// 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, <see cref="AutoScaleReferenceSize"/> is used as the size that uses default <see cref="GlobalScale"/>
@ -181,6 +188,7 @@ namespace MLEM.Ui {
private float globalScale = 1;
private bool drewEarly;
private UiStyle style;
private Rectangle viewport;
/// <summary>
/// Creates a new ui system with the given settings.
@ -228,8 +236,6 @@ namespace MLEM.Ui {
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();
};
}