mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
Ensure that a panel gets notified of all relevant changes by calling OnChildAreaDirty for all grandchildren
This commit is contained in:
parent
68fc02b170
commit
c28f6d858c
5 changed files with 26 additions and 11 deletions
|
@ -24,6 +24,7 @@ Fixes
|
||||||
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
|
- Only set a paragraph's area dirty when a text change would cause it to change size
|
||||||
|
- Ensure that a panel gets notified of all relevant changes by calling OnChildAreaDirty for all grandchildren
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
- Fixed paragraph links having incorrect hover locations when using special text alignments
|
- Fixed paragraph links having incorrect hover locations when using special text alignments
|
||||||
|
|
|
@ -530,7 +530,7 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SetAreaDirty() {
|
public void SetAreaDirty() {
|
||||||
this.AreaDirty = true;
|
this.AreaDirty = true;
|
||||||
this.Parent?.OnChildAreaDirty(this);
|
this.Parent?.OnChildAreaDirty(this, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1061,14 +1061,18 @@ namespace MLEM.Ui.Elements {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A method that gets called by this element's <see cref="Children"/> when their <see cref="SetAreaDirty"/> methods get called.
|
/// A method that gets called by this element's <see cref="Children"/> or any of its grandchildren when their <see cref="SetAreaDirty"/> methods get called.
|
||||||
/// Note that the element's area might already be dirty, which will not stop this method from being called.
|
/// Note that the element's area might already be dirty, which will not stop this method from being called.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="child">The child whose area is being set dirty</param>
|
/// <param name="child">The child whose area is being set dirty.</param>
|
||||||
protected virtual void OnChildAreaDirty(Element child) {
|
/// <param name="grandchild">Whether the <paramref name="child"/> is a grandchild of this element, rather than a direct child.</param>
|
||||||
|
protected virtual void OnChildAreaDirty(Element child, bool grandchild) {
|
||||||
|
if (!grandchild) {
|
||||||
if (child.Anchor >= Anchor.AutoLeft || this.SetWidthBasedOnChildren || this.SetHeightBasedOnChildren)
|
if (child.Anchor >= Anchor.AutoLeft || this.SetWidthBasedOnChildren || this.SetHeightBasedOnChildren)
|
||||||
this.SetAreaDirty();
|
this.SetAreaDirty();
|
||||||
}
|
}
|
||||||
|
this.Parent?.OnChildAreaDirty(child, true);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Transforms the given <paramref name="position"/> by the inverse of this element's <see cref="Transform"/> matrix.
|
/// Transforms the given <paramref name="position"/> by the inverse of this element's <see cref="Transform"/> matrix.
|
||||||
|
|
|
@ -157,6 +157,15 @@ namespace MLEM.Ui.Elements {
|
||||||
return relevant;
|
return relevant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void OnChildAreaDirty(Element child, bool grandchild) {
|
||||||
|
base.OnChildAreaDirty(child, grandchild);
|
||||||
|
// we only need to scroll when a grandchild changes, since all of our children are forced
|
||||||
|
// to be auto-anchored and so will automatically propagate their changes up to us
|
||||||
|
if (grandchild)
|
||||||
|
this.ScrollChildren();
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, Effect effect, Matrix matrix) {
|
public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, Effect effect, Matrix matrix) {
|
||||||
if (this.Texture.HasValue())
|
if (this.Texture.HasValue())
|
||||||
|
|
|
@ -191,8 +191,8 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected void SetTextDirty() {
|
protected void SetTextDirty() {
|
||||||
this.TokenizedText = null;
|
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
|
// only set our area dirty if our size changed as a result of this action
|
||||||
if (!this.AreaDirty && (!this.CalcActualSize(this.ParentArea).Equals(this.DisplayArea.Size, Epsilon) || this.Children.Count > 0))
|
if (!this.AreaDirty && !this.CalcActualSize(this.ParentArea).Equals(this.DisplayArea.Size, Epsilon))
|
||||||
this.SetAreaDirty();
|
this.SetAreaDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,9 @@ namespace MLEM.Ui.Elements {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void OnChildAreaDirty(Element child) {
|
protected override void OnChildAreaDirty(Element child, bool grandchild) {
|
||||||
base.OnChildAreaDirty(child);
|
base.OnChildAreaDirty(child, grandchild);
|
||||||
|
if (!grandchild)
|
||||||
this.SetAreaDirty();
|
this.SetAreaDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue