mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
Only set a paragraph's area dirty when a text change would cause it to change size
This commit is contained in:
parent
a61d7a9722
commit
b46975391b
3 changed files with 22 additions and 7 deletions
|
@ -23,6 +23,7 @@ Fixes
|
||||||
### MLEM.Ui
|
### MLEM.Ui
|
||||||
Improvements
|
Improvements
|
||||||
- Allow for checkboxes and radio buttons to be disabled
|
- 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
|
### MLEM.Data
|
||||||
Improvements
|
Improvements
|
||||||
|
|
|
@ -398,6 +398,11 @@ namespace MLEM.Ui.Elements {
|
||||||
/// The input handler that this element's <see cref="Controls"/> use
|
/// The input handler that this element's <see cref="Controls"/> use
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected InputHandler Input => this.Controls.Input;
|
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 readonly List<Element> children = new List<Element>();
|
||||||
private bool sortedChildrenDirty;
|
private bool sortedChildrenDirty;
|
||||||
|
@ -554,7 +559,7 @@ namespace MLEM.Ui.Elements {
|
||||||
return;
|
return;
|
||||||
this.System.Stopwatch.Restart();
|
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 parentCenterX = parentArea.X + parentArea.Width / 2;
|
||||||
var parentCenterY = parentArea.Y + parentArea.Height / 2;
|
var parentCenterY = parentArea.Y + parentArea.Height / 2;
|
||||||
var actualSize = this.CalcActualSize(parentArea);
|
var actualSize = this.CalcActualSize(parentArea);
|
||||||
|
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using MLEM.Extensions;
|
||||||
using MLEM.Font;
|
using MLEM.Font;
|
||||||
using MLEM.Formatting;
|
using MLEM.Formatting;
|
||||||
using MLEM.Formatting.Codes;
|
using MLEM.Formatting.Codes;
|
||||||
|
@ -24,8 +25,7 @@ namespace MLEM.Ui.Elements {
|
||||||
get => this.regularFont;
|
get => this.regularFont;
|
||||||
set {
|
set {
|
||||||
this.regularFont = value;
|
this.regularFont = value;
|
||||||
this.SetAreaDirty();
|
this.SetTextDirty();
|
||||||
this.TokenizedText = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -59,8 +59,7 @@ namespace MLEM.Ui.Elements {
|
||||||
if (this.text != value) {
|
if (this.text != value) {
|
||||||
this.text = value;
|
this.text = value;
|
||||||
this.IsHidden = string.IsNullOrWhiteSpace(this.text);
|
this.IsHidden = string.IsNullOrWhiteSpace(this.text);
|
||||||
this.SetAreaDirty();
|
this.SetTextDirty();
|
||||||
this.TokenizedText = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,8 +94,7 @@ namespace MLEM.Ui.Elements {
|
||||||
get => this.alignment;
|
get => this.alignment;
|
||||||
set {
|
set {
|
||||||
this.alignment = value;
|
this.alignment = value;
|
||||||
this.SetAreaDirty();
|
this.SetTextDirty();
|
||||||
this.TokenizedText = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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() {
|
private void QueryTextCallback() {
|
||||||
if (this.GetTextCallback != null)
|
if (this.GetTextCallback != null)
|
||||||
this.Text = this.GetTextCallback(this);
|
this.Text = this.GetTextCallback(this);
|
||||||
|
|
Loading…
Reference in a new issue