Skip to content

Commit

Permalink
Preserve text sizing when restarting sound
Browse files Browse the repository at this point in the history
  • Loading branch information
micahmo committed Mar 7, 2023
1 parent 22a9d39 commit 8059004
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions SoundBoard/Buttons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ public void CalculateTextMargin()
{
if (AreTransportControlsVisible // We only shrink when playing
&& _viewboxPanel.ActualHeight - _textBlock.ActualHeight < 50 // There's not enough room to comfortable display everything
&& _viewboxPanel.Margin.Bottom < 30) // We haven't done this yet
&& _targetViewboxMarginBottom < 30) // We haven't done this yet
{
_textMarginStoryboard.Stop();
_textMarginStoryboard.Children.Clear();
Expand All @@ -1744,13 +1744,15 @@ public void CalculateTextMargin()
Duration = TimeSpan.FromSeconds(.1)
};

_targetViewboxMarginBottom = 30;

Storyboard.SetTarget(animation, _viewboxPanel);
Storyboard.SetTargetProperty(animation, new PropertyPath(MarginProperty));
_textMarginStoryboard.Children.Add(animation);
_textMarginStoryboard.Begin();
}
else if (!AreTransportControlsVisible // Always reset when not playing
|| (_viewboxPanel.Margin.Bottom > 0 && ((_viewboxPanel.ActualHeight + _viewboxPanel.Margin.Bottom) - _textBlock.ActualHeight) >= 50)) // The bottom margin is set, but the height that it would be without it set is sufficient
|| (_targetViewboxMarginBottom > 0 && ((_viewboxPanel.ActualHeight + _targetViewboxMarginBottom) - _textBlock.ActualHeight) >= 50)) // The bottom margin is set, but the height that it would be without it set is sufficient
{
_textMarginStoryboard.Stop();
_textMarginStoryboard.Children.Clear();
Expand All @@ -1762,6 +1764,8 @@ public void CalculateTextMargin()
Duration = TimeSpan.FromSeconds(.1)
};

_targetViewboxMarginBottom = 0;

Storyboard.SetTarget(animation, _viewboxPanel);
Storyboard.SetTargetProperty(animation, new PropertyPath(MarginProperty));
_textMarginStoryboard.Children.Add(animation);
Expand Down Expand Up @@ -2569,6 +2573,7 @@ public string NextSound

// Related to text resizing
private ViewboxPanel _viewboxPanel;
private int _targetViewboxMarginBottom;
private TextBlock _textBlock;
private readonly Storyboard _textMarginStoryboard = new Storyboard();

Expand Down

0 comments on commit 8059004

Please sign in to comment.