mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 08:56:15 +02:00
Make sure the clock doesn't shift around when using non mono space fonts
This commit is contained in:
@@ -11,13 +11,15 @@ namespace DesktopMagic.BuiltInWindowElements;
|
|||||||
internal class TimePlugin : Plugin
|
internal class TimePlugin : Plugin
|
||||||
{
|
{
|
||||||
[Setting("Display Seconds")]
|
[Setting("Display Seconds")]
|
||||||
private readonly CheckBox displaySecondscheckBox = new CheckBox(true);
|
private readonly CheckBox displaySecondsCheckBox = new CheckBox(true);
|
||||||
|
|
||||||
public override int UpdateInterval => 1000;
|
public override int UpdateInterval => 1000;
|
||||||
|
|
||||||
|
private string? oldFont = null;
|
||||||
|
private float maxWidth = 0;
|
||||||
public override Bitmap Main()
|
public override Bitmap Main()
|
||||||
{
|
{
|
||||||
string time = displaySecondscheckBox.Value ? DateTime.Now.ToLongTimeString() : DateTime.Now.ToShortTimeString();
|
string time = displaySecondsCheckBox.Value ? DateTime.Now.ToLongTimeString() : DateTime.Now.ToShortTimeString();
|
||||||
|
|
||||||
Font font = new Font(Application.Theme.Font, 200);
|
Font font = new Font(Application.Theme.Font, 200);
|
||||||
|
|
||||||
@@ -28,7 +30,18 @@ internal class TimePlugin : Plugin
|
|||||||
|
|
||||||
SizeF size = tmpGr.MeasureString(time, font);
|
SizeF size = tmpGr.MeasureString(time, font);
|
||||||
|
|
||||||
bmp = new Bitmap((int)size.Width, (int)size.Height);
|
if (oldFont != Application.Theme.Font)
|
||||||
|
{
|
||||||
|
oldFont = Application.Theme.Font;
|
||||||
|
maxWidth = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size.Width > maxWidth)
|
||||||
|
{
|
||||||
|
maxWidth = size.Width;
|
||||||
|
}
|
||||||
|
|
||||||
|
bmp = new Bitmap((int)maxWidth, (int)size.Height);
|
||||||
bmp.SetResolution(100, 100);
|
bmp.SetResolution(100, 100);
|
||||||
|
|
||||||
using Graphics gr = Graphics.FromImage(bmp);
|
using Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
|||||||
Reference in New Issue
Block a user