Skip to content

Commit

Permalink
Merge #4255 Make LabeledProgressBar work on Mono
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Nov 10, 2024
2 parents c2f756b + 5c51b66 commit b8726a9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 96 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ All notable changes to this project will be documented in this file.
- [GUI] Minor tray icon improvements (#4231 by: HebaruSan)
- [Multiple] Translation updates from Crowdin (#4233 by: vixnig38, ambition, tinygrox; reviewed: HebaruSan)
- [Multiple] Cache migration and other fixes (#4240 by: HebaruSan)
- [Multiple] Start installing mods while downloads are still in progress (#4249 by: HebaruSan)
- [Multiple] Start installing mods while downloads are still in progress (#4249, #4255 by: HebaruSan)
- [Multiple] Sort dependencies first in modpacks (#4252 by: HebaruSan)
- [Multiple] Allow installs and removals to be cancelled (#4253 by: HebaruSan)

Expand Down
51 changes: 25 additions & 26 deletions GUI/Controls/LabeledProgressBar.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
#if NET5_0_OR_GREATER
using System.Runtime.Versioning;
#endif
Expand All @@ -18,19 +19,9 @@ public class LabeledProgressBar : ProgressBar
public LabeledProgressBar()
: base()
{
SuspendLayout();

label = new TransparentLabel()
{
ForeColor = SystemColors.ControlText,
Dock = DockStyle.Fill,
TextAlign = ContentAlignment.MiddleCenter,
Text = "",
};
Controls.Add(label);

ResumeLayout(false);
PerformLayout();
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
Font = SystemFonts.DefaultFont;
Text = "";
}

[Bindable(false)]
Expand All @@ -39,25 +30,33 @@ public LabeledProgressBar()
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[EditorBrowsable(EditorBrowsableState.Always)]
// If we use override instead of new, the nullability never matches (!)
public new string? Text
{
get => label.Text;
set => label.Text = value;
public new string Text {
get => text;
[MemberNotNull(nameof(text), nameof(textSize))]
set
{
text = value;
textSize = TextRenderer.MeasureText(text, Font);
}
}

[Bindable(false)]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[EditorBrowsable(EditorBrowsableState.Always)]
// If we use override instead of new, the nullability never matches (!)
public new Font Font
{
get => label.Font;
set => label.Font = value;
}
public new Font Font { get; set; }

public ContentAlignment TextAlign
protected override void OnPaint(PaintEventArgs e)
{
get => label.TextAlign;
set => label.TextAlign = value;
base.OnPaint(e);
TextRenderer.DrawText(e.Graphics, Text, Font,
new Point((Width - textSize.Width) / 2,
(Height - textSize.Height) / 2),
SystemColors.ControlText);
}

private readonly TransparentLabel label;
private string text;
private Size textSize;
}
}
69 changes: 0 additions & 69 deletions GUI/Controls/TransparentLabel.cs

This file was deleted.

0 comments on commit b8726a9

Please sign in to comment.