Skip to content

Commit

Permalink
fix: OutlinedTextBlock throwing when too small
Browse files Browse the repository at this point in the history
  • Loading branch information
azeier committed Nov 14, 2024
1 parent 3d4641a commit ed7bb3f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions HDTTests/OutlinedTextBlockTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Windows;
using Hearthstone_Deck_Tracker;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace HDTTests
{
[TestClass]
public class OutlinedTextBlockTests
{
[TestMethod]
public void MeasureOverride_BadSize_DoesNotThrow()
{
var textBlock = new TestTextBlock
{
TextWrapping = TextWrapping.NoWrap,
Text = "Test",
FontSize = 0.1
};
try
{
textBlock.CallMeasureOverride(new Size(0, 0));
}
catch(Exception e)
{
Assert.Fail(e.Message);
}
}

private class TestTextBlock : OutlinedTextBlock
{
public void CallMeasureOverride(Size availableSize)
{
MeasureOverride(availableSize);
}
}
}
}
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/Controls/OutlinedTextBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected override Size MeasureOverride(Size availableSize)
var maxWidth = Math.Min(3579139, Math.Max(0.0001d, availableSize.Width));
var ratio = maxWidth / _formattedText.Width;
if(ratio < 1 && (TextWrapping == TextWrapping.NoWrap || ratio > 0.8))
_formattedText.SetFontSize((int)(FontSize * ratio));
_formattedText.SetFontSize(Math.Max(1, (int)FontSize * ratio));
_formattedText.MaxTextWidth = maxWidth;
_formattedText.MaxTextHeight = Math.Max(0.0001d, availableSize.Height);

Expand Down

0 comments on commit ed7bb3f

Please sign in to comment.