Skip to content

Commit 38f802c

Browse files
committed
Add Value property to DropdownItem and fix CS1591 XML doc warnings
- Wire DropdownControl.SelectedValue/SelectedValueChanged to use Value ?? Text, so programmatic values (e.g. "30") are returned instead of display text (e.g. "30 FPS") - Fix DropdownBuilder.AddItem to set Value property instead of Icon - Clean up FPS dropdown in SettingsDialog and PerformanceDialog - Add XML documentation to all DatePicker/TimePicker public APIs, builders, theme interfaces, theme implementations, and ColorResolver - Make RenderCoordinator accept Func<Options> for runtime changes
1 parent d071b16 commit 38f802c

20 files changed

Lines changed: 623 additions & 43 deletions

SharpConsoleUI/Builders/DatePickerBuilder.cs

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
namespace SharpConsoleUI.Builders;
1717

18+
/// <summary>
19+
/// Fluent builder for creating and configuring DatePicker controls.
20+
/// </summary>
1821
public sealed class DatePickerBuilder : IControlBuilder<DatePickerControl>
1922
{
2023
private string _prompt = "Date:";
@@ -39,150 +42,275 @@ public sealed class DatePickerBuilder : IControlBuilder<DatePickerControl>
3942
private EventHandler? _lostFocusHandler;
4043
private WindowEventHandler<EventArgs>? _lostFocusWithWindowHandler;
4144

45+
/// <summary>
46+
/// Sets the prompt text displayed in the date picker header.
47+
/// </summary>
48+
/// <param name="prompt">The prompt text.</param>
49+
/// <returns>The builder for chaining.</returns>
4250
public DatePickerBuilder WithPrompt(string prompt)
4351
{
4452
_prompt = prompt;
4553
return this;
4654
}
4755

56+
/// <summary>
57+
/// Sets the initially selected date.
58+
/// </summary>
59+
/// <param name="date">The date to select.</param>
60+
/// <returns>The builder for chaining.</returns>
4861
public DatePickerBuilder WithSelectedDate(DateTime? date)
4962
{
5063
_selectedDate = date;
5164
return this;
5265
}
5366

67+
/// <summary>
68+
/// Sets the minimum selectable date.
69+
/// </summary>
70+
/// <param name="date">The minimum date.</param>
71+
/// <returns>The builder for chaining.</returns>
5472
public DatePickerBuilder WithMinDate(DateTime? date)
5573
{
5674
_minDate = date;
5775
return this;
5876
}
5977

78+
/// <summary>
79+
/// Sets the maximum selectable date.
80+
/// </summary>
81+
/// <param name="date">The maximum date.</param>
82+
/// <returns>The builder for chaining.</returns>
6083
public DatePickerBuilder WithMaxDate(DateTime? date)
6184
{
6285
_maxDate = date;
6386
return this;
6487
}
6588

89+
/// <summary>
90+
/// Sets the culture for date formatting and calendar layout.
91+
/// </summary>
92+
/// <param name="culture">The culture to use.</param>
93+
/// <returns>The builder for chaining.</returns>
6694
public DatePickerBuilder WithCulture(CultureInfo culture)
6795
{
6896
_culture = culture;
6997
return this;
7098
}
7199

100+
/// <summary>
101+
/// Sets a custom date format string.
102+
/// </summary>
103+
/// <param name="format">The date format string.</param>
104+
/// <returns>The builder for chaining.</returns>
72105
public DatePickerBuilder WithFormat(string format)
73106
{
74107
_dateFormat = format;
75108
return this;
76109
}
77110

111+
/// <summary>
112+
/// Sets the first day of the week for the calendar.
113+
/// </summary>
114+
/// <param name="dayOfWeek">The first day of the week.</param>
115+
/// <returns>The builder for chaining.</returns>
78116
public DatePickerBuilder WithFirstDayOfWeek(DayOfWeek dayOfWeek)
79117
{
80118
_firstDayOfWeek = dayOfWeek;
81119
return this;
82120
}
83121

122+
/// <summary>
123+
/// Sets the horizontal alignment.
124+
/// </summary>
125+
/// <param name="alignment">The horizontal alignment.</param>
126+
/// <returns>The builder for chaining.</returns>
84127
public DatePickerBuilder WithAlignment(HorizontalAlignment alignment)
85128
{
86129
_alignment = alignment;
87130
return this;
88131
}
89132

133+
/// <summary>
134+
/// Sets the vertical alignment.
135+
/// </summary>
136+
/// <param name="alignment">The vertical alignment.</param>
137+
/// <returns>The builder for chaining.</returns>
90138
public DatePickerBuilder WithVerticalAlignment(VerticalAlignment alignment)
91139
{
92140
_verticalAlignment = alignment;
93141
return this;
94142
}
95143

144+
/// <summary>
145+
/// Sets the margin.
146+
/// </summary>
147+
/// <param name="left">Left margin.</param>
148+
/// <param name="top">Top margin.</param>
149+
/// <param name="right">Right margin.</param>
150+
/// <param name="bottom">Bottom margin.</param>
151+
/// <returns>The builder for chaining.</returns>
96152
public DatePickerBuilder WithMargin(int left, int top, int right, int bottom)
97153
{
98154
_margin = new Margin(left, top, right, bottom);
99155
return this;
100156
}
101157

158+
/// <summary>
159+
/// Sets uniform margin on all sides.
160+
/// </summary>
161+
/// <param name="margin">The margin value for all sides.</param>
162+
/// <returns>The builder for chaining.</returns>
102163
public DatePickerBuilder WithMargin(int margin)
103164
{
104165
_margin = new Margin(margin, margin, margin, margin);
105166
return this;
106167
}
107168

169+
/// <summary>
170+
/// Sets the visibility.
171+
/// </summary>
172+
/// <param name="visible">Whether the control is visible.</param>
173+
/// <returns>The builder for chaining.</returns>
108174
public DatePickerBuilder Visible(bool visible = true)
109175
{
110176
_visible = visible;
111177
return this;
112178
}
113179

180+
/// <summary>
181+
/// Sets the width.
182+
/// </summary>
183+
/// <param name="width">The width in columns.</param>
184+
/// <returns>The builder for chaining.</returns>
114185
public DatePickerBuilder WithWidth(int width)
115186
{
116187
_width = width;
117188
return this;
118189
}
119190

191+
/// <summary>
192+
/// Sets the control name for lookup.
193+
/// </summary>
194+
/// <param name="name">The control name.</param>
195+
/// <returns>The builder for chaining.</returns>
120196
public DatePickerBuilder WithName(string name)
121197
{
122198
_name = name;
123199
return this;
124200
}
125201

202+
/// <summary>
203+
/// Sets a tag object.
204+
/// </summary>
205+
/// <param name="tag">The tag object.</param>
206+
/// <returns>The builder for chaining.</returns>
126207
public DatePickerBuilder WithTag(object tag)
127208
{
128209
_tag = tag;
129210
return this;
130211
}
131212

213+
/// <summary>
214+
/// Sets the sticky position.
215+
/// </summary>
216+
/// <param name="position">The sticky position.</param>
217+
/// <returns>The builder for chaining.</returns>
132218
public DatePickerBuilder WithStickyPosition(StickyPosition position)
133219
{
134220
_stickyPosition = position;
135221
return this;
136222
}
137223

224+
/// <summary>
225+
/// Makes the control stick to the top of the window.
226+
/// </summary>
227+
/// <returns>The builder for chaining.</returns>
138228
public DatePickerBuilder StickyTop()
139229
{
140230
_stickyPosition = StickyPosition.Top;
141231
return this;
142232
}
143233

234+
/// <summary>
235+
/// Makes the control stick to the bottom of the window.
236+
/// </summary>
237+
/// <returns>The builder for chaining.</returns>
144238
public DatePickerBuilder StickyBottom()
145239
{
146240
_stickyPosition = StickyPosition.Bottom;
147241
return this;
148242
}
149243

244+
/// <summary>
245+
/// Sets the selected date changed event handler.
246+
/// </summary>
247+
/// <param name="handler">The event handler.</param>
248+
/// <returns>The builder for chaining.</returns>
150249
public DatePickerBuilder OnSelectedDateChanged(EventHandler<DateTime?> handler)
151250
{
152251
_selectedDateChangedHandler = handler;
153252
return this;
154253
}
155254

255+
/// <summary>
256+
/// Sets the selected date changed event handler with window access.
257+
/// </summary>
258+
/// <param name="handler">The event handler with window access.</param>
259+
/// <returns>The builder for chaining.</returns>
156260
public DatePickerBuilder OnSelectedDateChanged(WindowEventHandler<DateTime?> handler)
157261
{
158262
_selectedDateChangedWithWindowHandler = handler;
159263
return this;
160264
}
161265

266+
/// <summary>
267+
/// Sets the GotFocus event handler.
268+
/// </summary>
269+
/// <param name="handler">The event handler.</param>
270+
/// <returns>The builder for chaining.</returns>
162271
public DatePickerBuilder OnGotFocus(EventHandler handler)
163272
{
164273
_gotFocusHandler = handler;
165274
return this;
166275
}
167276

277+
/// <summary>
278+
/// Sets the GotFocus event handler with window access.
279+
/// </summary>
280+
/// <param name="handler">The event handler with window access.</param>
281+
/// <returns>The builder for chaining.</returns>
168282
public DatePickerBuilder OnGotFocus(WindowEventHandler<EventArgs> handler)
169283
{
170284
_gotFocusWithWindowHandler = handler;
171285
return this;
172286
}
173287

288+
/// <summary>
289+
/// Sets the LostFocus event handler.
290+
/// </summary>
291+
/// <param name="handler">The event handler.</param>
292+
/// <returns>The builder for chaining.</returns>
174293
public DatePickerBuilder OnLostFocus(EventHandler handler)
175294
{
176295
_lostFocusHandler = handler;
177296
return this;
178297
}
179298

299+
/// <summary>
300+
/// Sets the LostFocus event handler with window access.
301+
/// </summary>
302+
/// <param name="handler">The event handler with window access.</param>
303+
/// <returns>The builder for chaining.</returns>
180304
public DatePickerBuilder OnLostFocus(WindowEventHandler<EventArgs> handler)
181305
{
182306
_lostFocusWithWindowHandler = handler;
183307
return this;
184308
}
185309

310+
/// <summary>
311+
/// Builds the date picker control.
312+
/// </summary>
313+
/// <returns>The configured <see cref="DatePickerControl"/>.</returns>
186314
public DatePickerControl Build()
187315
{
188316
var control = new DatePickerControl(_prompt)
@@ -247,5 +375,9 @@ public DatePickerControl Build()
247375
return control;
248376
}
249377

378+
/// <summary>
379+
/// Implicit conversion to <see cref="DatePickerControl"/>.
380+
/// </summary>
381+
/// <param name="builder">The builder to convert.</param>
250382
public static implicit operator DatePickerControl(DatePickerBuilder builder) => builder.Build();
251383
}

SharpConsoleUI/Builders/DropdownBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public DropdownBuilder WithPrompt(string prompt)
5555
/// </summary>
5656
public DropdownBuilder AddItem(string text, string? value = null, Color? color = null)
5757
{
58-
_items.Add(new DropdownItem(text, value ?? text, color));
58+
_items.Add(new DropdownItem(text) { Value = value, IconColor = color });
5959
return this;
6060
}
6161

@@ -74,7 +74,7 @@ public DropdownBuilder AddItem(DropdownItem item)
7474
public DropdownBuilder AddItems(params string[] items)
7575
{
7676
foreach (var item in items)
77-
_items.Add(new DropdownItem(item, item, null));
77+
_items.Add(new DropdownItem(item));
7878
return this;
7979
}
8080

0 commit comments

Comments
 (0)