From fb2048075cf657155a9b1e4d703062a5f2c78620 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 19 Oct 2019 11:21:34 -0500 Subject: [PATCH] InputRoll - cutoff text if it overflows the cell --- .../CustomControls/InputRoll.Drawing.cs | 50 ++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/BizHawk.Client.EmuHawk/CustomControls/InputRoll.Drawing.cs b/BizHawk.Client.EmuHawk/CustomControls/InputRoll.Drawing.cs index b5a2556f7b..068908729e 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/InputRoll.Drawing.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/InputRoll.Drawing.cs @@ -44,6 +44,38 @@ namespace BizHawk.Client.EmuHawk } } + private string Cap(string text, int? width) + { + if (string.IsNullOrEmpty(text) || width == null) + { + return text; + } + + var max = width.Value / (_charSize.Width - CellWidthPadding); + return text.Length < max + ? text + : text.Substring(0, max); + } + + private void DrawString(string text, int? width, Point point) + { + if (string.IsNullOrWhiteSpace(text)) + { + return; + } + + if (width.HasValue) + { + var max = (width.Value - CellWidthPadding) / _charSize.Width; + if (text.Length >= max) + { + text = text.Substring(0, max); + } + } + + _gdi.DrawString(text, point); + } + protected override void OnPaintBackground(PaintEventArgs pevent) { // Do nothing, and this should never be called @@ -105,12 +137,12 @@ namespace BizHawk.Client.EmuHawk if (IsHoveringOnColumnCell && column == CurrentCell.Column) { _gdi.PrepDrawString(_normalFont, SystemColors.HighlightText); - _gdi.DrawString(column.Text, point); + DrawString(column.Text, column.Width, point); _gdi.PrepDrawString(_normalFont, _foreColor); } else { - _gdi.DrawString(column.Text, point); + DrawString(column.Text, column.Width, point); } start += CellHeight; @@ -127,12 +159,12 @@ namespace BizHawk.Client.EmuHawk if (IsHoveringOnColumnCell && column == CurrentCell.Column) { _gdi.PrepDrawString(_normalFont, SystemColors.HighlightText); - _gdi.DrawString(column.Text, point); + DrawString(column.Text, column.Width, point); _gdi.PrepDrawString(_normalFont, _foreColor); } else { - _gdi.DrawString(column.Text, point); + DrawString(column.Text, column.Width, point); } } } @@ -198,10 +230,7 @@ namespace BizHawk.Client.EmuHawk _gdi.PrepDrawString(_rotatedFont, _foreColor); } - if (!string.IsNullOrWhiteSpace(text)) - { - _gdi.DrawString(text, point); - } + DrawString(text, ColumnWidth, point); if (rePrep) { @@ -250,10 +279,7 @@ namespace BizHawk.Client.EmuHawk rePrep = true; } - if (!string.IsNullOrWhiteSpace(text)) - { - _gdi.DrawString(text, new Point(point.X + strOffsetX, point.Y + strOffsetY)); - } + DrawString(text, col.Width, new Point(point.X + strOffsetX, point.Y + strOffsetY)); if (rePrep) {