Fix OutputPanel.SetMessage causing the panel to bounce if setting a message other than the last one (#6163)

This commit is contained in:
DrSmugleaf
2025-09-06 15:56:55 -07:00
committed by DrSmugleaf
parent b7dd9cd813
commit bbc86eb7fc
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.Contracts;
using System.Numerics;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.RichText;
@@ -154,6 +155,7 @@ namespace Robust.Client.UserInterface.Controls
public void SetMessage(Index index, FormattedMessage message, Type[]? tagsAllowed = null, Color? defaultColor = null)
{
var atBottom = !_scrollDownButton.Visible;
var oldEntry = _entries[index];
var font = _getFont();
_totalContentHeight -= oldEntry.Height + font.GetLineSeparation(UIScale);
@@ -164,6 +166,10 @@ namespace Robust.Client.UserInterface.Controls
_entries[index] = entry;
AddNewItemHeight(font, in entry);
_scrollBar.MaxValue = Math.Max(_scrollBar.Page, _totalContentHeight);
if (atBottom)
_scrollBar.Value = _scrollBar.MaxValue;
}
private void AddNewItemHeight(Font font, in RichTextEntry entry)
@@ -278,7 +284,7 @@ namespace Robust.Client.UserInterface.Controls
}
}
[System.Diagnostics.Contracts.Pure]
[Pure]
private Font _getFont()
{
if (TryGetStyleProperty<Font>("font", out var font))
@@ -289,7 +295,7 @@ namespace Robust.Client.UserInterface.Controls
return UserInterfaceManager.ThemeDefaults.DefaultFont;
}
[System.Diagnostics.Contracts.Pure]
[Pure]
private StyleBox? _getStyleBox()
{
if (StyleBoxOverride != null)
@@ -301,14 +307,14 @@ namespace Robust.Client.UserInterface.Controls
return box;
}
[System.Diagnostics.Contracts.Pure]
[Pure]
private float _getScrollSpeed()
{
// The scroll speed depends on the UI scale because the scroll bar is working with physical pixels.
return GetScrollSpeed(_getFont(), UIScale);
}
[System.Diagnostics.Contracts.Pure]
[Pure]
private UIBox2 _getContentBox()
{
var style = _getStyleBox();