Skip to content

Commit c441d66

Browse files
committed
Share the Synix menu design
1 parent e1f8068 commit c441d66

4 files changed

Lines changed: 104 additions & 50 deletions

File tree

SynixApp/Design/SynixMenuStyler.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// ============================================================================
2+
// PROJECT: Synix Game Server Control Panel
3+
// AUTHOR: Jason Turner (ubidzz)
4+
// COPYRIGHT: © 2026 All Rights Reserved.
5+
// ============================================================================
6+
using System.Runtime.InteropServices;
7+
8+
namespace Synix_Control_Panel.SynixApp.Design
9+
{
10+
public static class SynixMenuStyler
11+
{
12+
private const int DwmWindowCornerPreference = 33;
13+
private const int DwmCornerPreferenceRound = 2;
14+
private static readonly Font MenuFont = new("Segoe UI", 11F, FontStyle.Regular);
15+
16+
[DllImport("dwmapi.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
17+
private static extern void DwmSetWindowAttribute(
18+
IntPtr window,
19+
int attribute,
20+
ref int value,
21+
uint valueSize);
22+
23+
public static void Apply(ToolStripDropDown menu)
24+
{
25+
ArgumentNullException.ThrowIfNull(menu);
26+
menu.Renderer = new SynixMenuRenderer();
27+
menu.BackColor = SettingsPalette.Card;
28+
menu.ForeColor = SettingsPalette.PrimaryText;
29+
menu.Font = MenuFont;
30+
if (menu is ContextMenuStrip contextMenu)
31+
contextMenu.ShowImageMargin = false;
32+
33+
ApplyRoundedWindow(menu);
34+
foreach (ToolStripItem item in menu.Items)
35+
{
36+
item.BackColor = SettingsPalette.Card;
37+
item.ForeColor = SettingsPalette.PrimaryText;
38+
item.Padding = new Padding(0, 4, 0, 4);
39+
if (item is ToolStripDropDownItem dropDownItem && dropDownItem.HasDropDownItems)
40+
Apply(dropDownItem.DropDown);
41+
}
42+
}
43+
44+
private static void ApplyRoundedWindow(ToolStripDropDown menu)
45+
{
46+
void ApplyDwm()
47+
{
48+
if (Environment.OSVersion.Version.Build < 22000)
49+
return;
50+
try
51+
{
52+
int preference = DwmCornerPreferenceRound;
53+
DwmSetWindowAttribute(
54+
menu.Handle,
55+
DwmWindowCornerPreference,
56+
ref preference,
57+
sizeof(int));
58+
}
59+
catch (ExternalException)
60+
{
61+
// Windows can reject this visual hint; the renderer still supplies the theme.
62+
}
63+
}
64+
65+
if (menu.IsHandleCreated)
66+
ApplyDwm();
67+
else
68+
menu.HandleCreated += (_, _) => ApplyDwm();
69+
}
70+
}
71+
}

SynixApp/MainGUI.cs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ public MainGUI()
6363
FileHandler.LoadServers();
6464
AddGuidanceMenuItems();
6565

66-
contextMenuStrip.Renderer = new Synix_Control_Panel.SynixApp.Design.SynixMenuRenderer();
67-
contextMenuStrip.ShowImageMargin = false;
68-
contextMenuStrip.Font = new Font("Segoe UI", 11F, FontStyle.Regular);
69-
ApplyMenuRoundingAndSpacing(contextMenuStrip);
66+
SynixMenuStyler.Apply(contextMenuStrip);
7067

7168
dataGridView1.AutoGenerateColumns = false;
7269
dataGridView1.DataSource = _visibleServers;
@@ -171,41 +168,6 @@ private void AddGuidanceMenuItems()
171168
contextMenuStrip.Items.Insert(insertAt, connectionInformation);
172169
}
173170

174-
[DllImport("dwmapi.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
175-
internal static extern void DwmSetWindowAttribute(IntPtr hwnd, int attribute, ref int pvAttribute, uint cbAttribute);
176-
177-
private void ApplyMenuRoundingAndSpacing(ToolStripDropDown menu)
178-
{
179-
void ApplyDwm()
180-
{
181-
if (Environment.OSVersion.Version.Build >= 22000)
182-
{
183-
int DWMWA_WINDOW_CORNER_PREFERENCE = 33;
184-
int DWMWCP_ROUND = 2;
185-
DwmSetWindowAttribute(menu.Handle, DWMWA_WINDOW_CORNER_PREFERENCE, ref DWMWCP_ROUND, sizeof(int));
186-
}
187-
}
188-
189-
if (menu.IsHandleCreated)
190-
{
191-
ApplyDwm();
192-
}
193-
else
194-
{
195-
menu.HandleCreated += (s, e) => ApplyDwm();
196-
}
197-
198-
foreach (ToolStripItem item in menu.Items)
199-
{
200-
item.Padding = new Padding(0, 4, 0, 4);
201-
202-
if (item is ToolStripDropDownItem dropDownItem && dropDownItem.HasDropDownItems)
203-
{
204-
ApplyMenuRoundingAndSpacing(dropDownItem.DropDown);
205-
}
206-
}
207-
}
208-
209171
private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
210172
{
211173
e.ThrowException = false;

SynixApp/Tests/ModPluginManagerTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,36 @@ namespace Synix_Control_Panel.Tests;
1515

1616
public sealed class ModPluginManagerTests
1717
{
18+
[Fact]
19+
public void SharedMenuStylerAppliesTheSynixMenuDesign()
20+
{
21+
Exception? failure = null;
22+
Thread thread = new(() =>
23+
{
24+
try
25+
{
26+
using ContextMenuStrip menu = new();
27+
ToolStripMenuItem item = new("Nexus Mods");
28+
menu.Items.Add(item);
29+
30+
SynixMenuStyler.Apply(menu);
31+
32+
Assert.IsType<SynixMenuRenderer>(menu.Renderer);
33+
Assert.False(menu.ShowImageMargin);
34+
Assert.Equal(new Padding(0, 4, 0, 4), item.Padding);
35+
Assert.Equal(11F, menu.Font.Size);
36+
}
37+
catch (Exception exception)
38+
{
39+
failure = exception;
40+
}
41+
});
42+
thread.SetApartmentState(ApartmentState.STA);
43+
thread.Start();
44+
thread.Join();
45+
Assert.Null(failure);
46+
}
47+
1848
[Fact]
1949
public void SharedGridThemeDoesNotAddTheDashboardTooltip()
2050
{

SynixApp/UI/ModPluginManager.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ internal ModPluginManager(GameServer server)
4949
BackColor = SettingsPalette.Window;
5050
ForeColor = SettingsPalette.PrimaryText;
5151
Font = new Font("Segoe UI", 9.5F);
52-
_catalogMenu.BackColor = SettingsPalette.Card;
53-
_catalogMenu.ForeColor = SettingsPalette.PrimaryText;
54-
_catalogMenu.Font = Font;
55-
_catalogMenu.Padding = new Padding(4);
56-
_catalogMenu.ShowImageMargin = false;
57-
_catalogMenu.Renderer = new SynixMenuRenderer();
5852

5953
Label pageHeading = Heading("Mod & Plugin Manager", 28, 20, 640, 42, 19F);
6054
pageHeading.Name = "modPluginManagerHeading";
@@ -676,15 +670,12 @@ private void BrowseCatalog()
676670
ToolStripMenuItem item = new(catalog.Name)
677671
{
678672
ForeColor = SettingsPalette.PrimaryText,
679-
BackColor = SettingsPalette.Card,
680-
AutoSize = false,
681-
Margin = new Padding(0, 2, 0, 2),
682-
Padding = new Padding(8, 3, 8, 3),
683-
Size = new Size(220, 38)
673+
BackColor = SettingsPalette.Card
684674
};
685675
item.Click += (_, _) => OpenCatalog(catalog.Uri);
686676
_catalogMenu.Items.Add(item);
687677
}
678+
SynixMenuStyler.Apply(_catalogMenu);
688679
_catalogMenu.Show(_browseCatalog, new Point(0, _browseCatalog.Height + 4));
689680
}
690681

0 commit comments

Comments
 (0)