Skip to content

Commit e2e5ce8

Browse files
committed
Added UiSystem.OnElementAreaDirty and Element.OnAreaDirty events
1 parent 067aa61 commit e2e5ce8

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Changelog
22
MLEM uses [semantic versioning](https://semver.org/). Potentially breaking changes are written in **bold**. Each newly released version also has a corresponding [tag](https://github.com/Ellpeck/MLEM/tags).
33

4-
## 8.0.1 (In Development)
4+
## 8.1.0 (In Development)
55

6-
No code changes
6+
### MLEM.Ui
7+
Additions
8+
- Added UiSystem.OnElementAreaDirty and Element.OnAreaDirty events
79

810
## 8.0.0
911

MLEM.Ui/Elements/Element.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,10 @@ public StyleProp<Padding> ChildPadding {
439439
/// </summary>
440440
public TextInputCallback OnTextInput;
441441
/// <summary>
442+
/// Event that is called when this element's area is marked dirty using <see cref="Element.SetAreaDirty"/>.
443+
/// </summary>
444+
public GenericCallback OnAreaDirty;
445+
/// <summary>
442446
/// Event that is called when this element's <see cref="DisplayArea"/> is changed.
443447
/// </summary>
444448
public GenericCallback OnAreaUpdated;
@@ -653,6 +657,7 @@ public virtual void ForceUpdateSortedChildren() {
653657
/// </summary>
654658
public void SetAreaDirty() {
655659
this.AreaDirty = true;
660+
this.System?.InvokeOnElementAreaDirty(this);
656661
this.Parent?.OnChildAreaDirty(this, false);
657662
}
658663

MLEM.Ui/UiSystem.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ public UiStyle Style {
141141
/// </summary>
142142
public event Element.GenericCallback OnElementTouchExit;
143143
/// <summary>
144+
/// Event that is invoked when an <see cref="Element"/>'s display area is marked dirty
145+
/// </summary>
146+
public event Element.GenericCallback OnElementAreaDirty;
147+
/// <summary>
144148
/// Event that is invoked when an <see cref="Element"/>'s display area changes
145149
/// </summary>
146150
public event Element.GenericCallback OnElementAreaUpdated;
@@ -204,6 +208,7 @@ public UiSystem(Game game, UiStyle style, InputHandler inputHandler = null, bool
204208
this.OnElementMouseExit += e => e.OnMouseExit?.Invoke(e);
205209
this.OnElementTouchEnter += e => e.OnTouchEnter?.Invoke(e);
206210
this.OnElementTouchExit += e => e.OnTouchExit?.Invoke(e);
211+
this.OnElementAreaDirty += e => e.OnAreaDirty?.Invoke(e);
207212
this.OnElementAreaUpdated += e => e.OnAreaUpdated?.Invoke(e);
208213
this.OnElementStyleInit += e => e.OnStyleInit?.Invoke(e);
209214
this.OnMousedElementChanged += e => this.ApplyToAll(t => t.OnMousedElementChanged?.Invoke(t, e));
@@ -400,6 +405,10 @@ internal void InvokeOnElementUpdated(Element element, GameTime time) {
400405
this.OnElementUpdated?.Invoke(element, time);
401406
}
402407

408+
internal void InvokeOnElementAreaDirty(Element element) {
409+
this.OnElementAreaDirty?.Invoke(element);
410+
}
411+
403412
internal void InvokeOnElementAreaUpdated(Element element) {
404413
this.OnElementAreaUpdated?.Invoke(element);
405414
}

Tests/TestGame.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ protected override void LoadContent() {
3636
#endif
3737
));
3838
// make sure we catch a potential ui stack overflow as part of the tests by ensuring a sufficient execution stack
39+
this.UiSystem.OnElementAreaDirty += _ => RuntimeHelpers.EnsureSufficientExecutionStack();
3940
this.UiSystem.OnElementAreaUpdated += _ => RuntimeHelpers.EnsureSufficientExecutionStack();
4041
}
4142

build.cake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#tool dotnet:?package=docfx&version=2.78.3
33

44
// this is the upcoming version, for prereleases
5-
var version = Argument("version", "8.0.1");
5+
var version = Argument("version", "8.1.0");
66
var target = Argument("target", "Default");
77
var gitRef = Argument("ref", "refs/heads/main");
88
var buildNum = Argument("buildNum", "");

0 commit comments

Comments
 (0)