diff --git a/Core/Other/FormPlugins.Designer.cs b/Core/Other/FormPlugins.Designer.cs index 03a22a01..e1dcecf5 100644 --- a/Core/Other/FormPlugins.Designer.cs +++ b/Core/Other/FormPlugins.Designer.cs @@ -23,10 +23,12 @@ protected override void Dispose(bool disposing) { /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.btnClose = new System.Windows.Forms.Button(); this.btnReload = new System.Windows.Forms.Button(); this.btnOpenFolder = new System.Windows.Forms.Button(); this.flowLayoutPlugins = new TweetDuck.Plugins.Controls.PluginListFlowLayout(); + this.timerLayout = new System.Windows.Forms.Timer(this.components); this.SuspendLayout(); // // btnClose @@ -82,6 +84,11 @@ private void InitializeComponent() { this.flowLayoutPlugins.WrapContents = false; this.flowLayoutPlugins.Resize += new System.EventHandler(this.flowLayoutPlugins_Resize); // + // timerLayout + // + this.timerLayout.Interval = 99; + this.timerLayout.Tick += new System.EventHandler(this.timerLayout_Tick); + // // FormPlugins // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -106,5 +113,6 @@ private void InitializeComponent() { private System.Windows.Forms.Button btnReload; private System.Windows.Forms.Button btnOpenFolder; private Plugins.Controls.PluginListFlowLayout flowLayoutPlugins; + private System.Windows.Forms.Timer timerLayout; } } \ No newline at end of file diff --git a/Core/Other/FormPlugins.cs b/Core/Other/FormPlugins.cs index 9ac67e12..186bbdb9 100644 --- a/Core/Other/FormPlugins.cs +++ b/Core/Other/FormPlugins.cs @@ -18,7 +18,7 @@ public FormPlugins(){ public FormPlugins(PluginManager pluginManager) : this(){ this.pluginManager = pluginManager; - + Shown += (sender, args) => { Program.UserConfig.PluginsWindow.Restore(this, false); ReloadPluginList(); @@ -28,6 +28,10 @@ public FormPlugins(PluginManager pluginManager) : this(){ Program.UserConfig.PluginsWindow.Save(this); Program.UserConfig.Save(); }; + + ResizeEnd += (sender, args) => { + timerLayout.Start(); + }; } private int GetPluginOrderIndex(Plugin plugin){ @@ -50,18 +54,26 @@ private void ReloadPluginList(){ flowLayoutPlugins.ResumeLayout(true); - // sorry, I guess... - Padding = new Padding(Padding.Left, Padding.Top, Padding.Right+1, Padding.Bottom); - Padding = new Padding(Padding.Left, Padding.Top, Padding.Right-1, Padding.Bottom); + timerLayout_Tick(null, EventArgs.Empty); + timerLayout.Start(); } - private void flowLayoutPlugins_Resize(object sender, EventArgs e){ - if (flowLayoutPlugins.Controls.Count == 0){ + private void timerLayout_Tick(object sender, EventArgs e){ + timerLayout.Stop(); + + // stupid WinForms scrollbars and panels + Padding = new Padding(Padding.Left, Padding.Top, Padding.Right+1, Padding.Bottom+1); + Padding = new Padding(Padding.Left, Padding.Top, Padding.Right-1, Padding.Bottom-1); + } + + public void flowLayoutPlugins_Resize(object sender, EventArgs e){ + Control lastPlugin = flowLayoutPlugins.Controls.OfType<PluginControl>().LastOrDefault(); + + if (lastPlugin == null){ return; } - Control lastControl = flowLayoutPlugins.Controls[flowLayoutPlugins.Controls.Count-1]; - bool showScrollBar = lastControl.Location.Y+lastControl.Height >= flowLayoutPlugins.Height; + bool showScrollBar = lastPlugin.Location.Y+lastPlugin.Height+1 >= flowLayoutPlugins.Height; int horizontalOffset = showScrollBar ? SystemInformation.VerticalScrollBarWidth : 0; flowLayoutPlugins.AutoScroll = showScrollBar; @@ -71,7 +83,7 @@ private void flowLayoutPlugins_Resize(object sender, EventArgs e){ control.Width = flowLayoutPlugins.Width-control.Margin.Horizontal-horizontalOffset; } - lastControl.Visible = !showScrollBar; + flowLayoutPlugins.Controls[flowLayoutPlugins.Controls.Count-1].Visible = !showScrollBar; flowLayoutPlugins.Focus(); } diff --git a/Plugins/Controls/PluginControl.Designer.cs b/Plugins/Controls/PluginControl.Designer.cs index 7ddfb43f..9fa241b8 100644 --- a/Plugins/Controls/PluginControl.Designer.cs +++ b/Plugins/Controls/PluginControl.Designer.cs @@ -23,6 +23,7 @@ protected override void Dispose(bool disposing) { /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.btnToggleState = new System.Windows.Forms.Button(); this.labelName = new System.Windows.Forms.Label(); this.panelDescription = new System.Windows.Forms.Panel(); @@ -33,6 +34,7 @@ private void InitializeComponent() { this.labelVersion = new System.Windows.Forms.Label(); this.btnConfigure = new System.Windows.Forms.Button(); this.labelType = new TweetDuck.Core.Controls.LabelVertical(); + this.timerLayout = new System.Windows.Forms.Timer(this.components); this.panelDescription.SuspendLayout(); this.flowLayoutInfo.SuspendLayout(); this.SuspendLayout(); @@ -40,9 +42,9 @@ private void InitializeComponent() { // btnToggleState // this.btnToggleState.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.btnToggleState.Location = new System.Drawing.Point(456, 80); + this.btnToggleState.Location = new System.Drawing.Point(453, 59); this.btnToggleState.Name = "btnToggleState"; - this.btnToggleState.Size = new System.Drawing.Size(65, 23); + this.btnToggleState.Size = new System.Drawing.Size(68, 23); this.btnToggleState.TabIndex = 5; this.btnToggleState.Text = "Disable"; this.btnToggleState.UseVisualStyleBackColor = true; @@ -50,11 +52,13 @@ private void InitializeComponent() { // // labelName // + this.labelName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.labelName.AutoSize = true; - this.labelName.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.labelName.Location = new System.Drawing.Point(24, 7); + this.labelName.Font = new System.Drawing.Font("Segoe UI Semibold", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.labelName.Location = new System.Drawing.Point(0, 0); + this.labelName.Margin = new System.Windows.Forms.Padding(0); this.labelName.Name = "labelName"; - this.labelName.Size = new System.Drawing.Size(61, 24); + this.labelName.Size = new System.Drawing.Size(53, 21); this.labelName.TabIndex = 0; this.labelName.Text = "Name"; this.labelName.UseMnemonic = false; @@ -66,10 +70,11 @@ private void InitializeComponent() { | System.Windows.Forms.AnchorStyles.Right))); this.panelDescription.AutoScroll = true; this.panelDescription.Controls.Add(this.labelDescription); - this.panelDescription.Location = new System.Drawing.Point(28, 35); + this.panelDescription.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.panelDescription.Location = new System.Drawing.Point(28, 33); this.panelDescription.Name = "panelDescription"; - this.panelDescription.Size = new System.Drawing.Size(493, 39); - this.panelDescription.TabIndex = 2; + this.panelDescription.Size = new System.Drawing.Size(410, 47); + this.panelDescription.TabIndex = 3; this.panelDescription.Resize += new System.EventHandler(this.panelDescription_Resize); // // labelDescription @@ -80,44 +85,51 @@ private void InitializeComponent() { this.labelDescription.Location = new System.Drawing.Point(0, 0); this.labelDescription.Margin = new System.Windows.Forms.Padding(0); this.labelDescription.Name = "labelDescription"; - this.labelDescription.Size = new System.Drawing.Size(13, 39); + this.labelDescription.Size = new System.Drawing.Size(14, 45); this.labelDescription.TabIndex = 0; this.labelDescription.Text = "a\r\nb\r\nc"; this.labelDescription.UseMnemonic = false; // // labelAuthor // + this.labelAuthor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.labelAuthor.AutoSize = true; - this.labelAuthor.Location = new System.Drawing.Point(3, 0); - this.labelAuthor.Margin = new System.Windows.Forms.Padding(3, 0, 32, 0); + this.labelAuthor.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.labelAuthor.Location = new System.Drawing.Point(53, 5); + this.labelAuthor.Margin = new System.Windows.Forms.Padding(0, 0, 0, 1); this.labelAuthor.Name = "labelAuthor"; - this.labelAuthor.Size = new System.Drawing.Size(38, 13); - this.labelAuthor.TabIndex = 0; + this.labelAuthor.Size = new System.Drawing.Size(44, 15); + this.labelAuthor.TabIndex = 1; this.labelAuthor.Text = "Author"; this.labelAuthor.UseMnemonic = false; // // flowLayoutInfo // - this.flowLayoutInfo.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + this.flowLayoutInfo.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.flowLayoutInfo.Controls.Add(this.labelName); this.flowLayoutInfo.Controls.Add(this.labelAuthor); this.flowLayoutInfo.Controls.Add(this.labelWebsite); - this.flowLayoutInfo.Location = new System.Drawing.Point(28, 85); + this.flowLayoutInfo.Location = new System.Drawing.Point(24, 6); + this.flowLayoutInfo.Margin = new System.Windows.Forms.Padding(0); this.flowLayoutInfo.Name = "flowLayoutInfo"; - this.flowLayoutInfo.Size = new System.Drawing.Size(348, 18); - this.flowLayoutInfo.TabIndex = 3; + this.flowLayoutInfo.Size = new System.Drawing.Size(414, 21); + this.flowLayoutInfo.TabIndex = 1; this.flowLayoutInfo.WrapContents = false; // // labelWebsite // + this.labelWebsite.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.labelWebsite.AutoEllipsis = true; this.labelWebsite.AutoSize = true; this.labelWebsite.Cursor = System.Windows.Forms.Cursors.Hand; - this.labelWebsite.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.labelWebsite.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(238))); this.labelWebsite.ForeColor = System.Drawing.Color.Blue; - this.labelWebsite.Location = new System.Drawing.Point(76, 0); + this.labelWebsite.Location = new System.Drawing.Point(100, 5); + this.labelWebsite.Margin = new System.Windows.Forms.Padding(3, 0, 0, 1); this.labelWebsite.Name = "labelWebsite"; - this.labelWebsite.Size = new System.Drawing.Size(46, 13); - this.labelWebsite.TabIndex = 1; + this.labelWebsite.Size = new System.Drawing.Size(49, 15); + this.labelWebsite.TabIndex = 2; this.labelWebsite.Text = "Website"; this.labelWebsite.UseMnemonic = false; this.labelWebsite.Click += new System.EventHandler(this.labelWebsite_Click); @@ -126,19 +138,21 @@ private void InitializeComponent() { // this.labelVersion.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.labelVersion.Location = new System.Drawing.Point(14, 12); - this.labelVersion.Margin = new System.Windows.Forms.Padding(3, 9, 3, 0); + this.labelVersion.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.labelVersion.Location = new System.Drawing.Point(88, 6); + this.labelVersion.Margin = new System.Windows.Forms.Padding(0, 0, 1, 0); this.labelVersion.Name = "labelVersion"; - this.labelVersion.Size = new System.Drawing.Size(510, 13); - this.labelVersion.TabIndex = 1; + this.labelVersion.Padding = new System.Windows.Forms.Padding(0, 0, 0, 3); + this.labelVersion.Size = new System.Drawing.Size(436, 21); + this.labelVersion.TabIndex = 2; this.labelVersion.Text = "Version"; - this.labelVersion.TextAlign = System.Drawing.ContentAlignment.TopRight; + this.labelVersion.TextAlign = System.Drawing.ContentAlignment.BottomRight; this.labelVersion.UseMnemonic = false; // // btnConfigure // this.btnConfigure.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.btnConfigure.Location = new System.Drawing.Point(382, 80); + this.btnConfigure.Location = new System.Drawing.Point(453, 31); this.btnConfigure.Name = "btnConfigure"; this.btnConfigure.Size = new System.Drawing.Size(68, 23); this.btnConfigure.TabIndex = 4; @@ -152,12 +166,18 @@ private void InitializeComponent() { | System.Windows.Forms.AnchorStyles.Left))); this.labelType.BackColor = System.Drawing.Color.DarkGray; this.labelType.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.labelType.LineHeight = 0; this.labelType.Location = new System.Drawing.Point(0, 0); this.labelType.Name = "labelType"; - this.labelType.Size = new System.Drawing.Size(18, 109); - this.labelType.TabIndex = 6; + this.labelType.Size = new System.Drawing.Size(18, 88); + this.labelType.TabIndex = 0; this.labelType.Text = "TYPE"; // + // timerLayout + // + this.timerLayout.Interval = 1; + this.timerLayout.Tick += new System.EventHandler(this.timerLayout_Tick); + // // PluginControl // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -166,21 +186,18 @@ private void InitializeComponent() { this.Controls.Add(this.btnConfigure); this.Controls.Add(this.flowLayoutInfo); this.Controls.Add(this.panelDescription); - this.Controls.Add(this.labelName); this.Controls.Add(this.btnToggleState); this.Controls.Add(this.labelVersion); this.Margin = new System.Windows.Forms.Padding(0); - this.MaximumSize = new System.Drawing.Size(65535, 109); - this.MinimumSize = new System.Drawing.Size(0, 61); + this.MaximumSize = new System.Drawing.Size(65535, 88); this.Name = "PluginControl"; this.Padding = new System.Windows.Forms.Padding(3, 3, 6, 3); - this.Size = new System.Drawing.Size(530, 109); + this.Size = new System.Drawing.Size(530, 88); this.panelDescription.ResumeLayout(false); this.panelDescription.PerformLayout(); this.flowLayoutInfo.ResumeLayout(false); this.flowLayoutInfo.PerformLayout(); this.ResumeLayout(false); - this.PerformLayout(); } @@ -196,5 +213,6 @@ private void InitializeComponent() { private System.Windows.Forms.Label labelVersion; private System.Windows.Forms.Button btnConfigure; private Core.Controls.LabelVertical labelType; + private System.Windows.Forms.Timer timerLayout; } } diff --git a/Plugins/Controls/PluginControl.cs b/Plugins/Controls/PluginControl.cs index dd884774..f61d9fda 100644 --- a/Plugins/Controls/PluginControl.cs +++ b/Plugins/Controls/PluginControl.cs @@ -9,8 +9,8 @@ namespace TweetDuck.Plugins.Controls{ sealed partial class PluginControl : UserControl{ private readonly PluginManager pluginManager; private readonly Plugin plugin; - - private readonly float dpiScale; + + private int nextHeight; public PluginControl(){ InitializeComponent(); @@ -19,33 +19,52 @@ public PluginControl(){ public PluginControl(PluginManager pluginManager, Plugin plugin) : this(){ this.pluginManager = pluginManager; this.plugin = plugin; - - this.dpiScale = this.GetDPIScale(); - - this.labelName.Text = plugin.Name; - this.labelDescription.Text = plugin.CanRun ? plugin.Description : "This plugin requires TweetDuck "+plugin.RequiredVersion+" or newer."; - this.labelVersion.Text = plugin.Version; - this.labelAuthor.Text = plugin.Author; - this.labelWebsite.Text = plugin.Website; - this.labelType.LineHeight = BrowserUtils.Scale(9, dpiScale); + this.labelName.Text = plugin.Name; + this.labelDescription.Text = plugin.CanRun ? plugin.Description : $"This plugin requires TweetDuck {plugin.RequiredVersion} or newer."; + this.labelAuthor.Text = string.IsNullOrWhiteSpace(plugin.Author) ? string.Empty : $"by {plugin.Author}"; + this.labelWebsite.Text = plugin.Website; + this.labelVersion.Text = plugin.Version; + + this.labelType.LineHeight = BrowserUtils.Scale(9, this.GetDPIScale()); UpdatePluginState(); if (labelDescription.Text.Length == 0){ labelDescription.Visible = false; } - + panelDescription_Resize(panelDescription, EventArgs.Empty); } + private void timerLayout_Tick(object sender, EventArgs e){ + timerLayout.Stop(); + Height = nextHeight; + ResumeLayout(); + } + private void panelDescription_Resize(object sender, EventArgs e){ - if (labelDescription.Text.Length == 0){ - Height = MinimumSize.Height; + SuspendLayout(); + + int maxWidth = panelDescription.Width-(panelDescription.VerticalScroll.Visible ? SystemInformation.VerticalScrollBarWidth : 0); + labelDescription.MaximumSize = new Size(maxWidth, int.MaxValue); + + Font font = labelDescription.Font; + int descriptionLines = TextRenderer.MeasureText(labelDescription.Text, font, new Size(maxWidth, int.MaxValue), TextFormatFlags.WordBreak).Height/(font.Height-1); + + int requiredLines = Math.Max(descriptionLines, 1+(string.IsNullOrEmpty(labelVersion.Text) ? 0 : 1)+(btnConfigure.Visible ? 1 : 0)); + + switch(requiredLines){ + case 1: nextHeight = MaximumSize.Height-2*(font.Height-1); break; + case 2: nextHeight = MaximumSize.Height-(font.Height-1); break; + default: nextHeight = MaximumSize.Height; break; + } + + if (nextHeight != Height){ + timerLayout.Start(); } else{ - labelDescription.MaximumSize = new Size(panelDescription.Width-SystemInformation.VerticalScrollBarWidth, 0); - Height = Math.Min(MinimumSize.Height+BrowserUtils.Scale(9, dpiScale)+labelDescription.Height, MaximumSize.Height); + ResumeLayout(); } } diff --git a/Plugins/Controls/PluginListFlowLayout.cs b/Plugins/Controls/PluginListFlowLayout.cs index ab1f3423..303bf624 100644 --- a/Plugins/Controls/PluginListFlowLayout.cs +++ b/Plugins/Controls/PluginListFlowLayout.cs @@ -9,7 +9,10 @@ public PluginListFlowLayout(){ } protected override void WndProc(ref Message m){ - NativeMethods.ShowScrollBar(Handle, NativeMethods.SB_HORZ, false); // basically fuck the horizontal scrollbar very much + if (m.Msg == 0x85){ // WM_NCPAINT + NativeMethods.ShowScrollBar(Handle, NativeMethods.SB_HORZ, false); // basically fuck the horizontal scrollbar very much + } + base.WndProc(ref m); } }