diff --git a/CHANGELOG.md b/CHANGELOG.md
index b5cbdb0..56940ba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs
index 08f2a0c..596861d 100644
--- a/MLEM.Ui/UiSystem.cs
+++ b/MLEM.Ui/UiSystem.cs
@@ -23,9 +23,16 @@ namespace MLEM.Ui {
///
/// The viewport that this ui system is rendering inside of.
- /// This is automatically updated during
+ /// This is automatically updated during by default.
///
- public Rectangle Viewport;
+ public Rectangle Viewport {
+ get => this.viewport;
+ set {
+ this.viewport = value;
+ foreach (var root in this.rootElements)
+ root.Element.ForceUpdateArea();
+ }
+ }
///
/// 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
@@ -181,6 +188,7 @@ namespace MLEM.Ui {
private float globalScale = 1;
private bool drewEarly;
private UiStyle style;
+ private Rectangle viewport;
///
/// 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();
};
}