Skip to content

Commit 77af07d

Browse files
committed
refactor(start-menu): StartMenuOptions as class with init properties
Replace positional record with class using object initializer syntax. Add color customization via ColorResolver (background, foreground, highlight colors). Add gradient background to DemoApp start menu. Update all doc examples to use initializer syntax.
1 parent 1d575eb commit 77af07d

7 files changed

Lines changed: 148 additions & 79 deletions

File tree

Examples/DemoApp/Program.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using SharpConsoleUI.Core;
44
using SharpConsoleUI.Drivers;
55
using SharpConsoleUI.Helpers;
6+
using SharpConsoleUI.Rendering;
67
using DemoApp.DemoWindows;
8+
using Color = SharpConsoleUI.Color;
79

810
namespace DemoApp;
911

@@ -16,7 +18,15 @@ static async Task<int> Main(string[] args)
1618
try
1719
{
1820
var options = new ConsoleWindowSystemOptions(
19-
StatusBarOptions: new StatusBarOptions(ShowStartButton: true)
21+
StatusBarOptions: new StatusBarOptions(
22+
ShowStartButton: true,
23+
StartMenu: new StartMenuOptions
24+
{
25+
AppName = "SharpConsoleUI Demo",
26+
BackgroundGradient = new GradientBackground(
27+
ColorGradient.FromColors(new Color(25, 25, 60), new Color(15, 15, 35)),
28+
GradientDirection.Vertical)
29+
})
2030
);
2131
var windowSystem = new ConsoleWindowSystem(new NetConsoleDriver(RenderMode.Buffer), options: options);
2232
using var disposables = new DisposableManager();

Examples/StartMenuDemo/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static async Task<int> Main(string[] args)
2323
ShowStartButton: true,
2424
StartButtonLocation: StatusBarLocation.Bottom,
2525
StartButtonPosition: StartButtonPosition.Left,
26-
StartMenu: new StartMenuOptions(ShowWindowList: true)
26+
StartMenu: new StartMenuOptions { ShowWindowList = true }
2727
)
2828
);
2929

SharpConsoleUI/Configuration/StartMenuOptions.cs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,45 @@ namespace SharpConsoleUI.Configuration;
44

55
/// <summary>
66
/// Configuration options for Start menu appearance and behavior.
7+
/// Use object initializer syntax to set only the properties you need.
78
/// </summary>
8-
public record StartMenuOptions(
9+
public class StartMenuOptions
10+
{
911
/// <summary>Layout mode: SingleColumn (compact) or TwoColumn (with window list).</summary>
10-
StartMenuLayout Layout = StartMenuLayout.TwoColumn,
12+
public StartMenuLayout Layout { get; init; } = StartMenuLayout.TwoColumn;
1113

1214
/// <summary>Application name shown in the Start menu header. Defaults to "SharpConsoleUI".</summary>
13-
string? AppName = null,
15+
public string? AppName { get; init; }
1416

1517
/// <summary>Application version shown in the Start menu header. Defaults to library version.</summary>
16-
string? AppVersion = null,
18+
public string? AppVersion { get; init; }
1719

18-
/// <summary>Whether to show Unicode icons next to categories, headers, and exit.</summary>
19-
bool ShowIcons = true,
20+
/// <summary>Whether to show Unicode icons next to headers and exit.</summary>
21+
public bool ShowIcons { get; init; } = true;
2022

2123
/// <summary>Icon displayed next to the app name in the header. Defaults to "☰" (U+2630).</summary>
22-
string HeaderIcon = "\u2630",
24+
public string HeaderIcon { get; init; } = "\u2630";
2325

2426
/// <summary>Show built-in System category (themes, settings, about, performance).</summary>
25-
bool ShowSystemCategory = true,
27+
public bool ShowSystemCategory { get; init; } = true;
2628

27-
/// <summary>Show Windows category with open window list.</summary>
28-
bool ShowWindowList = true,
29+
/// <summary>Show Windows list (right column in TwoColumn, submenu in SingleColumn).</summary>
30+
public bool ShowWindowList { get; init; } = true;
2931

3032
/// <summary>Optional gradient background for the Start menu window.</summary>
31-
GradientBackground? BackgroundGradient = null
32-
);
33+
public GradientBackground? BackgroundGradient { get; init; }
34+
35+
// Colors — null means resolve from theme via ColorResolver
36+
37+
/// <summary>Background color. Null resolves from theme MenuDropdownBackgroundColor.</summary>
38+
public Color? BackgroundColor { get; init; }
39+
40+
/// <summary>Foreground color. Null resolves from theme MenuDropdownForegroundColor.</summary>
41+
public Color? ForegroundColor { get; init; }
42+
43+
/// <summary>Highlight background color. Null resolves from theme MenuDropdownHighlightBackgroundColor.</summary>
44+
public Color? HighlightBackgroundColor { get; init; }
45+
46+
/// <summary>Highlight foreground color. Null resolves from theme MenuDropdownHighlightForegroundColor.</summary>
47+
public Color? HighlightForegroundColor { get; init; }
48+
}

SharpConsoleUI/Dialogs/StartMenuDialog.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using SharpConsoleUI.Configuration;
33
using SharpConsoleUI.Controls;
44
using SharpConsoleUI.Controls.StartMenu;
5+
using SharpConsoleUI.Helpers;
56
using SharpConsoleUI.Layout;
67
using SharpConsoleUI.Parsing;
78
using System.Drawing;
@@ -47,12 +48,12 @@ public static void Show(ConsoleWindowSystem windowSystem)
4748
var menuOpts = windowSystem.Options.StatusBar.StartMenuConfig;
4849
var showIcons = menuOpts.ShowIcons;
4950

50-
// Resolve dropdown colors from theme
51+
// Resolve colors: explicit option → theme → default
5152
var theme = windowSystem.Theme;
52-
var dropBg = theme?.MenuDropdownBackgroundColor ?? Color.Grey15;
53-
var dropFg = theme?.MenuDropdownForegroundColor ?? Color.Grey93;
54-
var dropHiBg = theme?.MenuDropdownHighlightBackgroundColor ?? Color.DarkBlue;
55-
var dropHiFg = theme?.MenuDropdownHighlightForegroundColor ?? Color.White;
53+
var dropBg = ColorResolver.ResolveStartMenuBackground(menuOpts.BackgroundColor, theme);
54+
var dropFg = ColorResolver.ResolveStartMenuForeground(menuOpts.ForegroundColor, theme);
55+
var dropHiBg = ColorResolver.ResolveStartMenuHighlightBackground(menuOpts.HighlightBackgroundColor, theme);
56+
var dropHiFg = ColorResolver.ResolveStartMenuHighlightForeground(menuOpts.HighlightForegroundColor, theme);
5657

5758
// Build header markup — use configured app name/version or library defaults
5859
var appName = menuOpts.AppName ?? "SharpConsoleUI";
@@ -187,7 +188,7 @@ public static void Show(ConsoleWindowSystem windowSystem)
187188

188189
var posResult = PortalPositioner.Calculate(new PortalPositionRequest(
189190
Anchor: anchorInDesktop,
190-
ContentSize: new Size(menuWidth, menuHeight),
191+
ContentSize: new System.Drawing.Size(menuWidth, menuHeight),
191192
ScreenBounds: screenBounds,
192193
Placement: placement));
193194

SharpConsoleUI/Helpers/ColorResolver.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,5 +560,37 @@ public static Color ResolveStartMenuInfoStripForeground(Color? explicitValue, IC
560560
=> Coalesce(explicitValue)
561561
?? Coalesce(container?.GetConsoleWindowSystem?.Theme?.StartMenuInfoStripForegroundColor)
562562
?? Color.Grey;
563+
564+
/// <summary>
565+
/// Resolves Start menu background: explicit → theme MenuDropdownBackgroundColor → Color.Grey15.
566+
/// </summary>
567+
public static Color ResolveStartMenuBackground(Color? explicitValue, Themes.ITheme? theme)
568+
=> Coalesce(explicitValue)
569+
?? Coalesce(theme?.MenuDropdownBackgroundColor)
570+
?? Color.Grey15;
571+
572+
/// <summary>
573+
/// Resolves Start menu foreground: explicit → theme MenuDropdownForegroundColor → Color.Grey93.
574+
/// </summary>
575+
public static Color ResolveStartMenuForeground(Color? explicitValue, Themes.ITheme? theme)
576+
=> Coalesce(explicitValue)
577+
?? Coalesce(theme?.MenuDropdownForegroundColor)
578+
?? Color.Grey93;
579+
580+
/// <summary>
581+
/// Resolves Start menu highlight background: explicit → theme MenuDropdownHighlightBackgroundColor → Color.DarkBlue.
582+
/// </summary>
583+
public static Color ResolveStartMenuHighlightBackground(Color? explicitValue, Themes.ITheme? theme)
584+
=> Coalesce(explicitValue)
585+
?? Coalesce(theme?.MenuDropdownHighlightBackgroundColor)
586+
?? Color.DarkBlue;
587+
588+
/// <summary>
589+
/// Resolves Start menu highlight foreground: explicit → theme MenuDropdownHighlightForegroundColor → Color.White.
590+
/// </summary>
591+
public static Color ResolveStartMenuHighlightForeground(Color? explicitValue, Themes.ITheme? theme)
592+
=> Coalesce(explicitValue)
593+
?? Coalesce(theme?.MenuDropdownHighlightForegroundColor)
594+
?? Color.White;
563595
}
564596
}

docs/CONFIGURATION.md

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,35 @@ Configuration for status bars and Start Menu system.
146146
| `StartMenuShortcutKey` | `ConsoleKey` | `Spacebar` | Keyboard shortcut key (Ctrl+Space by default) |
147147
| `StartMenuShortcutModifiers` | `ConsoleModifiers` | `Control` | Keyboard modifiers (Ctrl, Alt, Shift, or combinations) |
148148

149-
#### Start Menu Content
149+
#### Start Menu Options
150+
151+
Start menu appearance and behavior is configured via the `StartMenu` parameter, which accepts a `StartMenuOptions` object:
150152

151153
| Property | Type | Default | Description |
152154
|----------|------|---------|-------------|
153-
| `ShowSystemMenuCategory` | `bool` | `true` | Show built-in System category (themes, settings, about) |
154-
| `ShowWindowListInMenu` | `bool` | `true` | Show Windows category with open window list |
155-
| `StartMenuLayout` | `StartMenuLayout` | `TwoColumn` | `SingleColumn` (compact, categories as flyout submenus) or `TwoColumn` (quick actions + window list side-by-side) |
156-
| `StartMenuAppName` | `string?` | `null` | Application name shown in header (defaults to "SharpConsoleUI") |
157-
| `StartMenuAppVersion` | `string?` | `null` | Application version shown in header (defaults to library version) |
155+
| `Layout` | `StartMenuLayout` | `TwoColumn` | `SingleColumn` (compact) or `TwoColumn` (with window list) |
156+
| `AppName` | `string?` | `null` | App name in header (defaults to "SharpConsoleUI") |
157+
| `AppVersion` | `string?` | `null` | App version in header (defaults to library version) |
158+
| `ShowIcons` | `bool` | `true` | Show Unicode icons in header and exit row |
159+
| `HeaderIcon` | `string` | `"☰"` | Icon next to the app name in the header |
160+
| `ShowSystemCategory` | `bool` | `true` | Show System category (themes, settings, about) |
161+
| `ShowWindowList` | `bool` | `true` | Show Windows list (right column in TwoColumn, submenu in SingleColumn) |
162+
| `BackgroundGradient` | `GradientBackground?` | `null` | Optional gradient background for the Start menu window |
163+
164+
**Examples:**
165+
```csharp
166+
// Minimal — everything uses defaults
167+
StartMenu: new StartMenuOptions()
168+
169+
// Just set what you need
170+
StartMenu: new StartMenuOptions { AppName = "My App", AppVersion = "1.0.0" }
171+
172+
// Single column, no icons
173+
StartMenu: new StartMenuOptions { Layout = StartMenuLayout.SingleColumn, ShowIcons = false }
174+
175+
// Custom colors
176+
StartMenu: new StartMenuOptions { BackgroundColor = Color.DarkBlue, ForegroundColor = Color.White }
177+
```
158178

159179
#### Status Bar Display
160180

@@ -283,15 +303,13 @@ var options = new ConsoleWindowSystemOptions(
283303
ShowStartButton: true,
284304
StartButtonLocation: StatusBarLocation.Bottom,
285305
StartButtonPosition: StartButtonPosition.Left,
286-
StartButtonText: "☰ Start",
287-
StartMenuShortcutKey: ConsoleKey.Spacebar,
288-
StartMenuShortcutModifiers: ConsoleModifiers.Control,
289-
StartMenuLayout: StartMenuLayout.TwoColumn,
290-
StartMenuAppName: "My App",
291-
StartMenuAppVersion: "1.0.0",
292-
ShowSystemMenuCategory: true,
293-
ShowWindowListInMenu: true,
294-
ShowTaskBar: false // Hide taskbar, window list only in Start Menu
306+
ShowTaskBar: false, // Hide taskbar, window list only in Start Menu
307+
StartMenu: new StartMenuOptions
308+
{
309+
Layout = StartMenuLayout.TwoColumn,
310+
AppName = "My App",
311+
AppVersion = "1.0.0"
312+
}
295313
)
296314
);
297315

docs/STATUS_SYSTEM.md

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,22 @@ var options = new ConsoleWindowSystemOptions(
248248
StartButtonLocation: StatusBarLocation.Bottom, // Top or Bottom
249249
StartButtonPosition: StartButtonPosition.Left, // Left or Right
250250
StartButtonText: "☰ Start", // Button text
251-
StartMenuShortcutKey: ConsoleKey.Spacebar, // Shortcut key (Ctrl+Space)
251+
StartMenuShortcutKey: ConsoleKey.Spacebar, // Shortcut key (Ctrl+Space)
252252
StartMenuShortcutModifiers: ConsoleModifiers.Control,
253-
StartMenuLayout: StartMenuLayout.TwoColumn, // Two-column with window list
254-
StartMenuAppName: "My App", // Custom app name in header
255-
StartMenuAppVersion: "1.0.0", // Custom version in header
256-
ShowSystemMenuCategory: true, // Show System category
257-
ShowWindowListInMenu: true // Show Windows category
253+
StartMenu: new StartMenuOptions
254+
{
255+
Layout = StartMenuLayout.TwoColumn,
256+
AppName = "My App",
257+
AppVersion = "1.0.0"
258+
}
258259
)
259260
);
260261
```
261262

262263
#### Configuration Options
263264

265+
**StatusBarOptions:**
266+
264267
| Option | Type | Default | Description |
265268
|--------|------|---------|-------------|
266269
| `ShowStartButton` | `bool` | `false` | Show/hide the Start button |
@@ -269,11 +272,20 @@ var options = new ConsoleWindowSystemOptions(
269272
| `StartButtonText` | `string` | `"☰ Start"` | Button display text |
270273
| `StartMenuShortcutKey` | `ConsoleKey` | `Spacebar` | Keyboard shortcut key |
271274
| `StartMenuShortcutModifiers` | `ConsoleModifiers` | `Control` | Modifier keys (Ctrl, Alt, Shift) |
272-
| `ShowSystemMenuCategory` | `bool` | `true` | Show System category |
273-
| `ShowWindowListInMenu` | `bool` | `true` | Show Windows category |
274-
| `StartMenuLayout` | `StartMenuLayout` | `TwoColumn` | Layout mode (see below) |
275-
| `StartMenuAppName` | `string?` | `null` | App name in header (defaults to "SharpConsoleUI") |
276-
| `StartMenuAppVersion` | `string?` | `null` | App version in header (defaults to library version) |
275+
| `StartMenu` | `StartMenuOptions?` | `null` | Start menu configuration (see below) |
276+
277+
**StartMenuOptions:**
278+
279+
| Option | Type | Default | Description |
280+
|--------|------|---------|-------------|
281+
| `Layout` | `StartMenuLayout` | `TwoColumn` | Layout mode (see below) |
282+
| `AppName` | `string?` | `null` | App name in header (defaults to "SharpConsoleUI") |
283+
| `AppVersion` | `string?` | `null` | App version in header (defaults to library version) |
284+
| `ShowIcons` | `bool` | `true` | Show Unicode icons in header and exit row |
285+
| `HeaderIcon` | `string` | `"☰"` | Icon next to app name in header |
286+
| `ShowSystemCategory` | `bool` | `true` | Show System category |
287+
| `ShowWindowList` | `bool` | `true` | Show Windows list |
288+
| `BackgroundGradient` | `GradientBackground?` | `null` | Optional gradient background |
277289

278290
#### Layout Modes
279291

@@ -304,8 +316,7 @@ StartMenuShortcutModifiers: ConsoleModifiers.None
304316

305317
**Custom Branding:**
306318
```csharp
307-
StartMenuAppName: "My Dashboard",
308-
StartMenuAppVersion: "2.1.0"
319+
StartMenu: new StartMenuOptions { AppName = "My Dashboard", AppVersion = "2.1.0" }
309320
```
310321

311322
### Registering Actions
@@ -358,7 +369,7 @@ windowSystem.RegisterStartMenuAction("About", ShowAbout, "Help", 20);
358369

359370
#### System Category
360371

361-
**Enabled by default** via `ShowSystemMenuCategory: true`. Provides:
372+
**Enabled by default** via `StartMenuOptions.ShowSystemCategory`. Provides:
362373

363374
**Quick actions** (top-level):
364375
- **Change Theme...** - Theme selector dialog
@@ -370,10 +381,7 @@ windowSystem.RegisterStartMenuAction("About", ShowAbout, "Help", 20);
370381

371382
Disable System category:
372383
```csharp
373-
StatusBarOptions: new StatusBarOptions(
374-
ShowStartButton: true,
375-
ShowSystemMenuCategory: false // Hide System actions
376-
)
384+
StartMenu: new StartMenuOptions { ShowSystemCategory = false }
377385
```
378386

379387
#### Windows Category
@@ -385,12 +393,9 @@ StatusBarOptions: new StatusBarOptions(
385393
- Click to activate/focus
386394
- Minimized windows shown dimmed
387395

388-
Disable Windows category:
396+
Disable Windows list:
389397
```csharp
390-
StatusBarOptions: new StatusBarOptions(
391-
ShowStartButton: true,
392-
ShowWindowListInMenu: false // Hide window list from Start Menu
393-
)
398+
StartMenu: new StartMenuOptions { ShowWindowList = false }
394399
```
395400

396401
**Note:** When disabled, windows still appear in bottom status bar if `ShowTaskBar: true`.
@@ -492,10 +497,8 @@ var windowSystem = new ConsoleWindowSystem(new NetConsoleDriver(RenderMode.Buffe
492497
var options = new ConsoleWindowSystemOptions(
493498
StatusBarOptions: new StatusBarOptions(
494499
ShowStartButton: true,
495-
StartButtonLocation: StatusBarLocation.Bottom,
496-
StartButtonPosition: StartButtonPosition.Left,
497-
ShowWindowListInMenu: true, // Windows in Start Menu
498-
ShowTaskBar: false // Not in status bar
500+
ShowTaskBar: false, // Window list only in Start Menu
501+
StartMenu: new StartMenuOptions { AppName = "My App", AppVersion = "1.0.0" }
499502
)
500503
);
501504

@@ -549,25 +552,14 @@ var options = new ConsoleWindowSystemOptions(
549552
EnableFrameRateLimiting: true,
550553
TargetFPS: 60,
551554
StatusBarOptions: new StatusBarOptions(
552-
// Start Menu enabled
553555
ShowStartButton: true,
554-
StartButtonLocation: StatusBarLocation.Bottom,
555-
StartButtonPosition: StartButtonPosition.Left,
556556
StartButtonText: "☰ Menu",
557-
StartMenuShortcutKey: ConsoleKey.Spacebar,
558-
StartMenuShortcutModifiers: ConsoleModifiers.Control,
559-
StartMenuLayout: StartMenuLayout.TwoColumn,
560-
StartMenuAppName: "My IDE",
561-
StartMenuAppVersion: "3.0.0",
562-
563-
// Content options
564-
ShowSystemMenuCategory: true,
565-
ShowWindowListInMenu: true,
566-
ShowTaskBar: true, // Show both in menu and status bar
567-
568-
// Status bar visibility
569-
ShowTopStatus: true,
570-
ShowBottomStatus: true
557+
ShowTaskBar: true,
558+
StartMenu: new StartMenuOptions
559+
{
560+
AppName = "My IDE",
561+
AppVersion = "3.0.0"
562+
}
571563
)
572564
);
573565

0 commit comments

Comments
 (0)