Skip to content

Commit 9332a11

Browse files
committed
Improve tray menu font, spacing, and icon rendering
Standardize menu font and padding, and simplify icon rendering for better visual consistency and clarity.
1 parent 1d3fbf6 commit 9332a11

2 files changed

Lines changed: 15 additions & 20 deletions

File tree

ModernMenuRenderer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e) {
4646
? Color.FromArgb(32, 32, 32)
4747
: Color.FromArgb(240, 240, 240);
4848

49-
e.TextFont = new Font(e.TextFont.FontFamily, e.TextFont.Size, FontStyle.Regular);
49+
e.TextFont = new Font("Segoe UI", 10.5f, FontStyle.Regular);
5050

5151
Rectangle adjustedRect = e.TextRectangle;
52-
adjustedRect.Y += 3;
52+
adjustedRect.Y += 4;
53+
adjustedRect.Height += 4;
5354
e.TextRectangle = adjustedRect;
5455

5556
base.OnRenderItemText(e);

Program.cs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,12 @@ public void setContextMenu() {
319319
appSettings.DefaultDuration = 0;
320320
}
321321

322+
Padding itemPadding = new(6, 14, 6, 6);
323+
322324
ToolStripMenuItem? settingsItem = new("&Settings...") {
323325
Image = CreateSymbolImage("⚙", isLightTheme),
324326
ImageScaling = ToolStripItemImageScaling.None,
325-
Padding = new Padding(4, 6, 4, 6),
327+
Padding = itemPadding,
326328
ImageAlign = ContentAlignment.MiddleLeft,
327329
TextImageRelation = TextImageRelation.ImageBeforeText
328330
};
@@ -332,7 +334,7 @@ public void setContextMenu() {
332334
ToolStripMenuItem? aboutItem = new("&About...") {
333335
Image = CreateSymbolImage("ℹ", isLightTheme),
334336
ImageScaling = ToolStripItemImageScaling.None,
335-
Padding = new Padding(4, 6, 4, 6),
337+
Padding = itemPadding,
336338
ImageAlign = ContentAlignment.MiddleLeft,
337339
TextImageRelation = TextImageRelation.ImageBeforeText
338340
};
@@ -342,7 +344,7 @@ public void setContextMenu() {
342344
ToolStripMenuItem? exitItem = new("E&xit") {
343345
Image = CreateSymbolImage("✖", isLightTheme),
344346
ImageScaling = ToolStripItemImageScaling.None,
345-
Padding = new Padding(4, 6, 4, 6),
347+
Padding = itemPadding,
346348
ImageAlign = ContentAlignment.MiddleLeft,
347349
TextImageRelation = TextImageRelation.ImageBeforeText,
348350
};
@@ -370,7 +372,7 @@ public void setContextMenu() {
370372
Tag = time,
371373
Image = CreateSymbolImage("⏰", isLightTheme),
372374
ImageScaling = ToolStripItemImageScaling.None,
373-
Padding = new Padding(4, 6, 4, 6),
375+
Padding = itemPadding,
374376
ImageAlign = ContentAlignment.MiddleLeft,
375377
TextImageRelation = TextImageRelation.ImageBeforeText
376378
};
@@ -382,27 +384,19 @@ public void setContextMenu() {
382384
}
383385

384386
private static Bitmap CreateSymbolImage(string symbol, bool isLightTheme) {
385-
using Graphics g = Graphics.FromHwnd(IntPtr.Zero);
386-
float dpiScale = g.DpiX / 96f;
387-
388-
int baseSize = 16;
389-
int size = (int)(baseSize * dpiScale);
390-
int padding = (int)(2 * dpiScale);
391-
int totalSize = size + (padding * 2);
392-
393-
string cacheKey = $"{symbol}_{isLightTheme}_{dpiScale:F2}";
387+
int size = 24;
388+
string cacheKey = $"{symbol}_{isLightTheme}";
394389

395390
if (symbolCache.TryGetValue(cacheKey, out Bitmap? cached)) {
396391
return cached;
397392
}
398393

399-
Bitmap bitmap = new(totalSize, totalSize);
394+
Bitmap bitmap = new(size, size);
400395
using Graphics graphics = Graphics.FromImage(bitmap);
401396
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
402-
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
397+
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
403398

404-
float fontSize = 10f * dpiScale;
405-
using Font font = new("Segoe UI Symbol", fontSize, FontStyle.Regular);
399+
using Font font = new("Segoe UI Symbol", 11f, FontStyle.Regular);
406400
Color textColor = isLightTheme ? Color.FromArgb(32, 32, 32) : Color.FromArgb(240, 240, 240);
407401
using SolidBrush brush = new(textColor);
408402

@@ -411,7 +405,7 @@ private static Bitmap CreateSymbolImage(string symbol, bool isLightTheme) {
411405
LineAlignment = StringAlignment.Center
412406
};
413407

414-
graphics.DrawString(symbol, font, brush, new RectangleF(padding, padding, size, size), format);
408+
graphics.DrawString(symbol, font, brush, new RectangleF(0, 0, size, size), format);
415409

416410
symbolCache[cacheKey] = bitmap;
417411

0 commit comments

Comments
 (0)