Skip to content
Permalink
Browse files

[UI] don't invalidate text UI if we set it to the same thing

  • Loading branch information
phr00t authored and xen2 committed May 28, 2019
1 parent 11059c0 commit 0c5a67c0b4e36489c01f0014465457ebc12b8074
Showing with 4 additions and 1 deletion.
  1. +4 −1 sources/engine/Xenko.UI/Controls/TextBlock.cs
@@ -51,6 +51,7 @@ public string Text
get { return text; }
set
{
if (text == value) return;
text = value;
OnTextChanged();
}
@@ -92,7 +93,9 @@ public float TextSize
get { return textSize; }
set
{
textSize = MathUtil.Clamp(value, 0.0f, float.MaxValue);
float clamped = MathUtil.Clamp(value, 0.0f, float.MaxValue);
if (textSize == clamped) return;

This comment has been minimized.

Copy link
@Kryptos-FR

Kryptos-FR Jul 26, 2019

Collaborator

Testing float for equality is not going to work in some cases. Better use an epsilon delta:

if (Math.Abs(textSize - clamped) < 0.001f)

This comment has been minimized.

Copy link
@xen2

xen2 Jul 26, 2019

Member

If float computation is done same way, it should output same result.
i.e. running block.TextSize = 2.0f * 3.0f; in a loop should skip second time.
I think it's fine to recompute if value is slightly different, I prefer not to have any magic epsilon if not necessary.

This comment has been minimized.

Copy link
@xen2

xen2 Jul 26, 2019

Member

Quick example of what I want to avoid:
block.TextSize += 0.00001f => no more update!
Also it would also result in case where:
block.TextSize = y; Assert(block.TextSize == y); (assuming y > 0.0f) to fail depending on previous value, which I would prefer not to happen.

This comment has been minimized.

Copy link
@Kryptos-FR

Kryptos-FR Jul 27, 2019

Collaborator

Fair point.

textSize = clamped;
InvalidateMeasure();
}
}

0 comments on commit 0c5a67c

Please sign in to comment.
You can’t perform that action at this time.