1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-25 01:39:23 +01:00

Only set a paragraph's area dirty when a text change would cause it to change size

This commit is contained in:
Ell 2022-01-06 23:26:14 +01:00
parent a61d7a9722
commit b46975391b
3 changed files with 22 additions and 7 deletions

View file

@ -23,6 +23,7 @@ Fixes
### MLEM.Ui
Improvements
- Allow for checkboxes and radio buttons to be disabled
- Only set a paragraph's area dirty when a text change would cause it to change size
### MLEM.Data
Improvements

View file

@ -398,6 +398,11 @@ namespace MLEM.Ui.Elements {
/// The input handler that this element's <see cref="Controls"/> use
/// </summary>
protected InputHandler Input => this.Controls.Input;
/// <summary>
/// The <see cref="ChildPaddedArea"/> of this element's <see cref="Parent"/>, or the <see cref="UiSystem.Viewport"/> if this element has no parent.
/// This value is the one that is passed to <see cref="CalcActualSize"/> during <see cref="ForceUpdateArea"/>.
/// </summary>
protected RectangleF ParentArea => this.Parent?.ChildPaddedArea ?? (RectangleF) this.system.Viewport;
private readonly List<Element> children = new List<Element>();
private bool sortedChildrenDirty;
@ -554,7 +559,7 @@ namespace MLEM.Ui.Elements {
return;
this.System.Stopwatch.Restart();
var parentArea = this.Parent != null ? this.Parent.ChildPaddedArea : (RectangleF) this.system.Viewport;
var parentArea = this.ParentArea;
var parentCenterX = parentArea.X + parentArea.Width / 2;
var parentCenterY = parentArea.Y + parentArea.Height / 2;
var actualSize = this.CalcActualSize(parentArea);

View file

@ -2,6 +2,7 @@ using System;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions;
using MLEM.Font;
using MLEM.Formatting;
using MLEM.Formatting.Codes;
@ -24,8 +25,7 @@ namespace MLEM.Ui.Elements {
get => this.regularFont;
set {
this.regularFont = value;
this.SetAreaDirty();
this.TokenizedText = null;
this.SetTextDirty();
}
}
/// <summary>
@ -59,8 +59,7 @@ namespace MLEM.Ui.Elements {
if (this.text != value) {
this.text = value;
this.IsHidden = string.IsNullOrWhiteSpace(this.text);
this.SetAreaDirty();
this.TokenizedText = null;
this.SetTextDirty();
}
}
}
@ -95,8 +94,7 @@ namespace MLEM.Ui.Elements {
get => this.alignment;
set {
this.alignment = value;
this.SetAreaDirty();
this.TokenizedText = null;
this.SetTextDirty();
}
}
@ -187,6 +185,17 @@ namespace MLEM.Ui.Elements {
}
}
/// <summary>
/// A helper method that causes the <see cref="TokenizedText"/> to be reset.
/// Additionally, <see cref="Element.SetAreaDirty"/> if this paragraph's area has changed enough to warrant it, or if it has any <see cref="Link"/> children.
/// </summary>
protected void SetTextDirty() {
this.TokenizedText = null;
// only set our area dirty if our size changed as a result of this action or if we have link children we need to update
if (!this.AreaDirty && (this.Children.Count > 0 || !this.CalcActualSize(this.ParentArea).Equals(this.DisplayArea.Size, Epsilon)))
this.SetAreaDirty();
}
private void QueryTextCallback() {
if (this.GetTextCallback != null)
this.Text = this.GetTextCallback(this);