Tastudio - Branches - fix width calculation when expanding to fix user text

This commit is contained in:
adelikat 2019-12-03 20:03:10 -06:00
parent b87f14f962
commit eb63fa5a92
2 changed files with 25 additions and 27 deletions

View File

@ -126,6 +126,25 @@ namespace BizHawk.Client.EmuHawk
base.Dispose(disposing);
}
public void ExpandColumnToFitText(string columnName, string text)
{
var column = AllColumns.SingleOrDefault(c => c.Name == columnName);
if (column != null)
{
using var g = CreateGraphics();
using (_renderer.LockGraphics(g, Width, Height))
{
var strLength = (int)_renderer.MeasureString(text, Font).Width + (CellWidthPadding * 2);
if (column.Width < strLength)
{
column.Width = strLength;
AllColumns.ColumnsChanged();
Refresh();
}
}
}
}
protected override void OnDoubleClick(EventArgs e)
{
if (IsHoveringOnColumnEdge)

View File

@ -21,7 +21,6 @@ namespace BizHawk.Client.EmuHawk
private TasMovie Movie => Tastudio.CurrentTasMovie;
private TasBranch _backupBranch;
private BranchUndo _branchUndo = BranchUndo.None;
private int _longestBranchText;
private enum BranchUndo
{
@ -520,34 +519,14 @@ namespace BizHawk.Client.EmuHawk
public void UpdateTextColumnWidth()
{
int temp = 0;
foreach (TasBranch b in Movie.Branches)
if (Movie.Branches.Any())
{
if (string.IsNullOrEmpty(b.UserText))
{
continue;
}
var longestBranchText = Movie.Branches
.OrderBy(b => b.UserText?.Length ?? 0)
.Last()
.UserText;
if (temp < b.UserText.Length)
{
temp = b.UserText.Length;
}
}
_longestBranchText = temp;
int textWidth = (_longestBranchText * 12) + 14; // sorry for magic numbers. see TAStudio.SetUpColumns()
var column = BranchView.AllColumns.Single(c => c.Name == UserTextColumnName);
if (textWidth < 90)
{
textWidth = 90;
}
if (column.Width != textWidth)
{
column.Width = textWidth;
BranchView.AllColumns.ColumnsChanged();
BranchView.ExpandColumnToFitText(UserTextColumnName, longestBranchText);
}
}