Debugger: Fixed code scroll issues when changing font size

This commit is contained in:
Souryo 2016-11-24 17:35:59 -05:00
parent da1112ddf4
commit 6dbacc4797
3 changed files with 18 additions and 14 deletions

View file

@ -60,6 +60,7 @@ namespace Mesen.GUI.Debugger
{
if(value >= 6 && value <= 20) {
this.ctrlTextbox.Font = new Font("Consolas", value);
UpdateHorizontalScrollbar();
this.ctrlTextbox.Invalidate();
if(this.FontSizeChanged != null) {

View file

@ -54,6 +54,7 @@ namespace Mesen.GUI.Debugger
private Font _noteFont = null;
private int _marginWidth = 6;
private float _maxLineWidth = 0;
private int _maxLineWidthIndex = 0;
public ctrlTextbox()
{
@ -67,7 +68,8 @@ namespace Mesen.GUI.Debugger
set
{
int maxLength = 0;
int maxLengthIndex = 0;
_maxLineWidthIndex = 0;
_contents = new string[value.Length];
_lineMargins = new int[value.Length];
@ -75,14 +77,11 @@ namespace Mesen.GUI.Debugger
_contents[i] = value[i].TrimStart();
if(_contents[i].Length > maxLength) {
maxLength = _contents[i].Length;
maxLengthIndex = i;
_maxLineWidthIndex = i;
}
_lineMargins[i] = (value[i].Length - _contents[i].Length) * 10;
}
using(Graphics g = this.CreateGraphics()) {
_maxLineWidth = g.MeasureString(_contents[maxLengthIndex], this.Font).Width;
}
UpdateHorizontalScrollWidth();
_lineNumbers = new int[_contents.Length];
@ -102,6 +101,7 @@ namespace Mesen.GUI.Debugger
{
base.Font = value;
_noteFont = new Font(value.FontFamily, value.Size * 0.75f);
UpdateHorizontalScrollWidth();
}
}
@ -455,8 +455,11 @@ namespace Mesen.GUI.Debugger
private void UpdateHorizontalScrollWidth()
{
using(Graphics g = this.CreateGraphics()) {
HorizontalScrollWidth = (int)(Math.Max(0, 8 + _maxLineWidth - (this.Width - GetMargin(g))) / HorizontalScrollFactor);
if(_contents.Length > _maxLineWidthIndex) {
using(Graphics g = this.CreateGraphics()) {
_maxLineWidth = g.MeasureString(_contents[_maxLineWidthIndex], this.Font).Width;
HorizontalScrollWidth = (int)(Math.Max(0, HorizontalScrollFactor + _maxLineWidth - (this.Width - GetMargin(g))) / HorizontalScrollFactor);
}
}
}

View file

@ -41,8 +41,7 @@
//
// baseConfigPanel
//
this.baseConfigPanel.Location = new System.Drawing.Point(0, 210);
this.baseConfigPanel.Size = new System.Drawing.Size(352, 29);
this.baseConfigPanel.Size = new System.Drawing.Size(377, 29);
//
// tableLayoutPanel1
//
@ -65,7 +64,7 @@
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.Size = new System.Drawing.Size(352, 210);
this.tableLayoutPanel1.Size = new System.Drawing.Size(377, 233);
this.tableLayoutPanel1.TabIndex = 2;
//
// txtComment
@ -74,7 +73,8 @@
this.txtComment.Location = new System.Drawing.Point(63, 82);
this.txtComment.Multiline = true;
this.txtComment.Name = "txtComment";
this.txtComment.Size = new System.Drawing.Size(286, 133);
this.txtComment.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.txtComment.Size = new System.Drawing.Size(311, 148);
this.txtComment.TabIndex = 3;
//
// lblLabel
@ -91,7 +91,7 @@
//
this.lblComment.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.lblComment.AutoSize = true;
this.lblComment.Location = new System.Drawing.Point(3, 142);
this.lblComment.Location = new System.Drawing.Point(3, 149);
this.lblComment.Name = "lblComment";
this.lblComment.Size = new System.Drawing.Size(54, 13);
this.lblComment.TabIndex = 1;
@ -102,7 +102,7 @@
this.txtLabel.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtLabel.Location = new System.Drawing.Point(63, 56);
this.txtLabel.Name = "txtLabel";
this.txtLabel.Size = new System.Drawing.Size(286, 20);
this.txtLabel.Size = new System.Drawing.Size(311, 20);
this.txtLabel.TabIndex = 2;
//
// lblRegion
@ -146,7 +146,7 @@
this.AcceptButton = null;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(352, 239);
this.ClientSize = new System.Drawing.Size(377, 262);
this.Controls.Add(this.tableLayoutPanel1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "frmEditLabel";