diff --git a/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs b/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs index 666d829bc3..3b672cb088 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs @@ -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) diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index fd44fc3715..23754e472a 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -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); } }