From aa096b01df5894aa5a67c57b6259f11f50f916f6 Mon Sep 17 00:00:00 2001 From: RussKie Date: Sun, 13 May 2018 23:12:43 +1000 Subject: [PATCH] fix HiDPI related issues --- .../DashboardControl/Dashboard.Designer.cs | 30 +++++++++--------- .../DashboardControl/Dashboard.cs | 31 +++++++++---------- .../UserRepositoriesList.Designer.cs | 22 ++++++++++--- .../DashboardControl/UserRepositoriesList.cs | 23 +++----------- 4 files changed, 53 insertions(+), 53 deletions(-) diff --git a/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/Dashboard.Designer.cs b/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/Dashboard.Designer.cs index 70822abbd5e..14d29988b3d 100644 --- a/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/Dashboard.Designer.cs +++ b/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/Dashboard.Designer.cs @@ -34,7 +34,7 @@ private void InitializeComponent() this.lblContribute = new System.Windows.Forms.Label(); this.pnlLogo = new System.Windows.Forms.Panel(); this.pbLogo = new System.Windows.Forms.PictureBox(); - this.recentRepositoriesList1 = new GitUI.CommandsDialogs.BrowseDialog.DashboardControl.UserRepositoriesList(); + this.userRepositoriesList = new GitUI.CommandsDialogs.BrowseDialog.DashboardControl.UserRepositoriesList(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.pnlLeft.SuspendLayout(); this.flpnlContribute.SuspendLayout(); @@ -121,18 +121,18 @@ private void InitializeComponent() // // recentRepositoriesList1 // - this.recentRepositoriesList1.BranchNameColor = System.Drawing.SystemColors.HotTrack; - this.recentRepositoriesList1.Dock = System.Windows.Forms.DockStyle.Fill; - this.recentRepositoriesList1.HeaderBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(160)))), ((int)(((byte)(183)))), ((int)(((byte)(226))))); - this.recentRepositoriesList1.HeaderColor = System.Drawing.Color.Empty; - this.recentRepositoriesList1.HeaderHeight = 70; - this.recentRepositoriesList1.HoverColor = System.Drawing.Color.Empty; - this.recentRepositoriesList1.Location = new System.Drawing.Point(246, 0); - this.recentRepositoriesList1.MainBackColor = System.Drawing.Color.Empty; - this.recentRepositoriesList1.Margin = new System.Windows.Forms.Padding(0); - this.recentRepositoriesList1.Name = "recentRepositoriesList1"; - this.recentRepositoriesList1.Size = new System.Drawing.Size(405, 358); - this.recentRepositoriesList1.TabIndex = 1; + this.userRepositoriesList.BranchNameColor = System.Drawing.SystemColors.HotTrack; + this.userRepositoriesList.Dock = System.Windows.Forms.DockStyle.Fill; + this.userRepositoriesList.HeaderBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(160)))), ((int)(((byte)(183)))), ((int)(((byte)(226))))); + this.userRepositoriesList.HeaderColor = System.Drawing.Color.Empty; + this.userRepositoriesList.HeaderHeight = 70; + this.userRepositoriesList.HoverColor = System.Drawing.Color.Empty; + this.userRepositoriesList.Location = new System.Drawing.Point(246, 0); + this.userRepositoriesList.MainBackColor = System.Drawing.Color.Empty; + this.userRepositoriesList.Margin = new System.Windows.Forms.Padding(0); + this.userRepositoriesList.Name = "userRepositoriesList"; + this.userRepositoriesList.Size = new System.Drawing.Size(405, 358); + this.userRepositoriesList.TabIndex = 1; // // tableLayoutPanel1 // @@ -143,7 +143,7 @@ private void InitializeComponent() this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 85.71428F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 7.142857F)); this.tableLayoutPanel1.Controls.Add(this.pnlLeft, 1, 0); - this.tableLayoutPanel1.Controls.Add(this.recentRepositoriesList1, 2, 0); + this.tableLayoutPanel1.Controls.Add(this.userRepositoriesList, 2, 0); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(0); @@ -182,7 +182,7 @@ private void InitializeComponent() private System.Windows.Forms.FlowLayoutPanel flpnlContribute; private System.Windows.Forms.Label lblContribute; private System.Windows.Forms.Panel pnlLogo; - private UserRepositoriesList recentRepositoriesList1; + private UserRepositoriesList userRepositoriesList; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.PictureBox pbLogo; } diff --git a/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/Dashboard.cs b/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/Dashboard.cs index 9dadedede98..2e33ef6a2e0 100644 --- a/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/Dashboard.cs +++ b/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/Dashboard.cs @@ -44,14 +44,13 @@ public Dashboard() flpnlContribute.Dock = DockStyle.Bottom; flpnlContribute.SendToBack(); - recentRepositoriesList1.GitModuleChanged += OnModuleChanged; + userRepositoriesList.GitModuleChanged += OnModuleChanged; // apply scaling pnlLogo.Padding = DpiUtil.Scale(pnlLogo.Padding); - flpnlStart.Padding = DpiUtil.Scale(flpnlStart.Padding); - flpnlContribute.Padding = DpiUtil.Scale(flpnlContribute.Padding); - tableLayoutPanel1.ColumnStyles[1].Width = DpiUtil.Scale(tableLayoutPanel1.ColumnStyles[1].Width); - recentRepositoriesList1.HeaderHeight = pnlLogo.Height; + userRepositoriesList.HeaderHeight = pnlLogo.Height; + + this.AdjustForDpiScaling(); } // need this to stop flickering of the background images, nothing else works @@ -69,7 +68,7 @@ public void RefreshContent() { InitDashboardLayout(); ApplyTheme(); - recentRepositoriesList1.ShowRecentRepositories(); + userRepositoriesList.ShowRecentRepositories(); void ApplyTheme() { @@ -80,13 +79,13 @@ void ApplyTheme() flpnlStart.BackColor = _selectedTheme.PrimaryLight; flpnlContribute.BackColor = _selectedTheme.PrimaryVeryLight; lblContribute.ForeColor = _selectedTheme.SecondaryHeadingText; - recentRepositoriesList1.BranchNameColor = AppSettings.BranchColor; // _selectedTheme.SecondaryText; - recentRepositoriesList1.FavouriteColor = _selectedTheme.AccentedText; - recentRepositoriesList1.ForeColor = _selectedTheme.PrimaryText; - recentRepositoriesList1.HeaderColor = _selectedTheme.SecondaryHeadingText; - recentRepositoriesList1.HeaderBackColor = _selectedTheme.PrimaryDark; - recentRepositoriesList1.HoverColor = _selectedTheme.PrimaryLight; - recentRepositoriesList1.MainBackColor = _selectedTheme.Primary; + userRepositoriesList.BranchNameColor = AppSettings.BranchColor; // _selectedTheme.SecondaryText; + userRepositoriesList.FavouriteColor = _selectedTheme.AccentedText; + userRepositoriesList.ForeColor = _selectedTheme.PrimaryText; + userRepositoriesList.HeaderColor = _selectedTheme.SecondaryHeadingText; + userRepositoriesList.HeaderBackColor = _selectedTheme.PrimaryDark; + userRepositoriesList.HoverColor = _selectedTheme.PrimaryLight; + userRepositoriesList.MainBackColor = _selectedTheme.Primary; BackgroundImage = _selectedTheme.BackgroundImage; foreach (var item in flpnlContribute.Controls.OfType().Union(flpnlStart.Controls.OfType())) @@ -115,7 +114,7 @@ void InitDashboardLayout() }, (panel, lastControl) => { - var height = DpiUtil.Scale(lastControl.Location.Y + lastControl.Size.Height) + panel.Padding.Bottom; + var height = lastControl.Location.Y + lastControl.Size.Height + panel.Padding.Bottom; panel.Height = height; panel.MinimumSize = new Size(0, height); }); @@ -137,7 +136,7 @@ void InitDashboardLayout() }, (panel, lastControl) => { - var height = DpiUtil.Scale(lastControl.Location.Y + lastControl.Size.Height) + panel.Padding.Bottom; + var height = lastControl.Location.Y + lastControl.Size.Height + panel.Padding.Bottom; panel.MinimumSize = new Size(0, height); }); } @@ -170,7 +169,7 @@ Control CreateLink(Control container, string text, Image icon, EventHandler hand AutoSize = true, AutoEllipsis = true, Font = AppSettings.Font, - Image = icon, + Image = DpiUtil.Scale(icon), ImageAlign = ContentAlignment.MiddleLeft, LinkBehavior = LinkBehavior.NeverUnderline, Margin = new Padding(padding3, 0, padding3, DpiUtil.Scale(8)), diff --git a/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/UserRepositoriesList.Designer.cs b/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/UserRepositoriesList.Designer.cs index c108b174ce9..aee6b31a02a 100644 --- a/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/UserRepositoriesList.Designer.cs +++ b/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/UserRepositoriesList.Designer.cs @@ -48,6 +48,7 @@ private void InitializeComponent() this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator(); this.pnlHeader = new System.Windows.Forms.Panel(); + this.pnlBody = new System.Windows.Forms.Panel(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.lblRecentRepositories = new System.Windows.Forms.Label(); this.tsmiCategories = new System.Windows.Forms.ToolStripMenuItem(); @@ -65,6 +66,7 @@ private void InitializeComponent() this.mnuTop = new System.Windows.Forms.ToolStripMenuItem(); this.mnuConfigure = new System.Windows.Forms.ToolStripMenuItem(); this.pnlHeader.SuspendLayout(); + this.pnlBody.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout(); this.contextMenuStrip.SuspendLayout(); this.menuStripRecentMenu.SuspendLayout(); @@ -92,6 +94,17 @@ private void InitializeComponent() this.pnlHeader.Size = new System.Drawing.Size(451, 73); this.pnlHeader.TabIndex = 0; // + // pnlBody + // + this.pnlBody.Controls.Add(this.listView1); + this.pnlBody.Dock = System.Windows.Forms.DockStyle.Fill; + this.pnlBody.Location = new System.Drawing.Point(0, 0); + this.pnlBody.Margin = new System.Windows.Forms.Padding(0); + this.pnlBody.Name = "pnlBody"; + this.pnlBody.Padding = new System.Windows.Forms.Padding(20); + this.pnlBody.Size = new System.Drawing.Size(451, 73); + this.pnlBody.TabIndex = 1; + // // tableLayoutPanel1 // this.tableLayoutPanel1.AutoSize = true; @@ -178,15 +191,13 @@ private void InitializeComponent() // listView1 // this.listView1.Activation = System.Windows.Forms.ItemActivation.OneClick; - this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); this.listView1.BorderStyle = System.Windows.Forms.BorderStyle.None; this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.clmhdrPath, this.clmhdrBranch, this.clmhdrCategory}); this.listView1.ContextMenuStrip = this.contextMenuStrip; + this.listView1.Dock = System.Windows.Forms.DockStyle.Fill; this.listView1.FullRowSelect = true; listViewGroup1.Header = "Most Recent"; listViewGroup1.Name = "lvgMostRecent"; @@ -267,8 +278,8 @@ private void InitializeComponent() // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; - this.Controls.Add(this.listView1); this.Controls.Add(this.menuStripRecentMenu); + this.Controls.Add(this.pnlBody); this.Controls.Add(this.pnlHeader); this.DoubleBuffered = true; this.Name = "RecentRepositoriesList"; @@ -276,6 +287,8 @@ private void InitializeComponent() this.Load += new System.EventHandler(this.RecentRepositoriesList_Load); this.pnlHeader.ResumeLayout(false); this.pnlHeader.PerformLayout(); + this.pnlBody.ResumeLayout(false); + this.pnlBody.PerformLayout(); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); this.contextMenuStrip.ResumeLayout(false); @@ -289,6 +302,7 @@ private void InitializeComponent() #endregion private System.Windows.Forms.Panel pnlHeader; + private System.Windows.Forms.Panel pnlBody; private System.Windows.Forms.Label lblRecentRepositories; private System.Windows.Forms.ContextMenuStrip contextMenuStrip; private System.Windows.Forms.ToolStripMenuItem tsmiRemoveFromList; diff --git a/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/UserRepositoriesList.cs b/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/UserRepositoriesList.cs index c1e6e7b3f59..41c57bfd474 100644 --- a/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/UserRepositoriesList.cs +++ b/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/UserRepositoriesList.cs @@ -51,17 +51,17 @@ public UserRepositoriesList() _foreColorBrush = new SolidBrush(base.ForeColor); - _secondaryFont = new Font(AppSettings.Font.FontFamily, AppSettings.Font.SizeInPoints - DpiUtil.Scale(1f)); - lblRecentRepositories.Font = new Font(AppSettings.Font.FontFamily, AppSettings.Font.SizeInPoints + DpiUtil.Scale(5.5f)); + _secondaryFont = new Font(AppSettings.Font.FontFamily, AppSettings.Font.SizeInPoints - 1f); + lblRecentRepositories.Font = new Font(AppSettings.Font.FontFamily, AppSettings.Font.SizeInPoints + 5.5f); listView1.Items.Clear(); listView1.ContextMenuStrip = contextMenuStrip; - ApplyScaling(); - imageList1.Images.Clear(); imageList1.Images.Add(Resources.folder_git); imageList1.Images.Add(Resources.folder_error); + + this.AdjustForDpiScaling(); } [Category("Appearance")] @@ -275,24 +275,11 @@ protected virtual void OnModuleChanged(GitModuleEventArgs args) handler?.Invoke(this, args); } - private void ApplyScaling() - { - tableLayoutPanel1.ColumnStyles[1].Width *= DpiUtil.ScaleX; - pnlHeader.Padding = DpiUtil.Scale(pnlHeader.Padding); - - var padding4 = DpiUtil.Scale(4); - var padding36 = DpiUtil.Scale(36); - listView1.Width = Width - (2 * padding36); - listView1.Location = new Point(padding36, pnlHeader.Height + padding4); - listView1.Size = new Size(Width - (2 * padding36), Height - pnlHeader.Height - (2 * padding4)); - } - private static T FindControl(IEnumerable controls, Func predicate) where T : Control { foreach (Control control in controls) { - var result = control as T; - if (result != null && predicate(result)) + if (control is T result && predicate(result)) { return result; }