Controller config - take label width into account when generating columns

This commit is contained in:
adelikat 2020-06-22 17:48:36 -05:00
parent 1ce0905deb
commit 93c47b87b9
1 changed files with 10 additions and 7 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
@ -20,9 +21,9 @@ namespace BizHawk.Client.EmuHawk
private readonly int _inputMarginLeft = UIHelper.ScaleX(0); private readonly int _inputMarginLeft = UIHelper.ScaleX(0);
private readonly int _labelPadding = UIHelper.ScaleX(5); private readonly int _labelPadding = UIHelper.ScaleX(5);
private readonly int _marginTop = UIHelper.ScaleY(0); private readonly int _marginTop = UIHelper.ScaleY(0);
private readonly int _spacing = UIHelper.ScaleY(24); private readonly int _ySpacing = UIHelper.ScaleY(24);
private readonly int _inputSize = UIHelper.ScaleX(170); private readonly int _inputSize = UIHelper.ScaleX(170);
private readonly int _columnWidth = UIHelper.ScaleX(280); private readonly int _charWidth = UIHelper.ScaleX(9);
public ToolTip Tooltip { get; set; } public ToolTip Tooltip { get; set; }
@ -103,15 +104,17 @@ namespace BizHawk.Client.EmuHawk
private void Startup() private void Startup()
{ {
var labelWidth = _buttons.Max(b => b.Length) * _charWidth;
var columnWidth = _inputSize + (_labelPadding * 2) + labelWidth;
int x = _inputMarginLeft; int x = _inputMarginLeft;
int y = _marginTop - _spacing; int y = _marginTop - _ySpacing;
for (int i = 0; i < _buttons.Count; i++) for (int i = 0; i < _buttons.Count; i++)
{ {
y += _spacing; y += _ySpacing;
if (y > (_panelSize.Height - UIHelper.ScaleY(62))) if (y > (_panelSize.Height - UIHelper.ScaleY(62)))
{ {
y = _marginTop; y = _marginTop;
x += _columnWidth; x += columnWidth;
} }
var iw = new InputCompositeWidget var iw = new InputCompositeWidget
@ -130,11 +133,11 @@ namespace BizHawk.Client.EmuHawk
var label = new Label var label = new Label
{ {
Location = new Point(x + _inputSize + _labelPadding, y + UIHelper.ScaleY(3)), Location = new Point(x + _inputSize + _labelPadding, y + UIHelper.ScaleY(3)),
Size = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)), Size = new Size(UIHelper.ScaleX(labelWidth), UIHelper.ScaleY(15)),
Text = _buttons[i].Replace('_', ' ').Trim() Text = _buttons[i].Replace('_', ' ').Trim()
}; };
////Tooltip.SetToolTip(label, null); //??? not supported yet Tooltip.SetToolTip(label, label.Text);
Controls.Add(label); Controls.Add(label);
} }