mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 04:53:29 +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
|
||||
- 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
|
||||
- Ensure that a panel gets notified of all relevant changes by calling OnChildAreaDirty for all grandchildren
|
||||
|
||||
Fixes
|
||||
- Fixed paragraph links having incorrect hover locations when using special text alignments
|
||||
|
|
|
@ -530,7 +530,7 @@ namespace MLEM.Ui.Elements {
|
|||
/// </summary>
|
||||
public void SetAreaDirty() {
|
||||
this.AreaDirty = true;
|
||||
this.Parent?.OnChildAreaDirty(this);
|
||||
this.Parent?.OnChildAreaDirty(this, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1061,13 +1061,17 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
|
||||
/// <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.
|
||||
/// </summary>
|
||||
/// <param name="child">The child whose area is being set dirty</param>
|
||||
protected virtual void OnChildAreaDirty(Element child) {
|
||||
if (child.Anchor >= Anchor.AutoLeft || this.SetWidthBasedOnChildren || this.SetHeightBasedOnChildren)
|
||||
this.SetAreaDirty();
|
||||
/// <param name="child">The child whose area is being set dirty.</param>
|
||||
/// <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)
|
||||
this.SetAreaDirty();
|
||||
}
|
||||
this.Parent?.OnChildAreaDirty(child, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -157,6 +157,15 @@ namespace MLEM.Ui.Elements {
|
|||
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 />
|
||||
public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, Effect effect, Matrix matrix) {
|
||||
if (this.Texture.HasValue())
|
||||
|
|
|
@ -191,8 +191,8 @@ namespace MLEM.Ui.Elements {
|
|||
/// </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.CalcActualSize(this.ParentArea).Equals(this.DisplayArea.Size, Epsilon) || this.Children.Count > 0))
|
||||
// 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.SetAreaDirty();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,9 +30,10 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnChildAreaDirty(Element child) {
|
||||
base.OnChildAreaDirty(child);
|
||||
this.SetAreaDirty();
|
||||
protected override void OnChildAreaDirty(Element child, bool grandchild) {
|
||||
base.OnChildAreaDirty(child, grandchild);
|
||||
if (!grandchild)
|
||||
this.SetAreaDirty();
|
||||
}
|
||||
|
||||
private static bool SquishChild(Element element, out RectangleF squishedArea) {
|
||||
|
|
Loading…
Reference in a new issue