mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-10-31 17:15:28 +08:00 
			
		
		
		
	Enhance the style of the checkboxes for multi-selection (#1244)
* Enhance the checkboxes' style for multi-selection by applying the selected style, if available, to the checkboxes currently selected.
This commit is contained in:
		| @@ -9,4 +9,15 @@ internal sealed class ListPromptConstants | |||||||
|     public const string InstructionsMarkup = "[grey](Press <space> to select, <enter> to accept)[/]"; |     public const string InstructionsMarkup = "[grey](Press <space> to select, <enter> to accept)[/]"; | ||||||
|     public const string MoreChoicesMarkup = "[grey](Move up and down to reveal more choices)[/]"; |     public const string MoreChoicesMarkup = "[grey](Move up and down to reveal more choices)[/]"; | ||||||
|     public const string SearchPlaceholderMarkup = "[grey](Type to search)[/]"; |     public const string SearchPlaceholderMarkup = "[grey](Type to search)[/]"; | ||||||
|  |  | ||||||
|  |     public static string GetSelectedCheckbox(bool isGroup, SelectionMode mode, Style? style = null) | ||||||
|  |     { | ||||||
|  |         if (style != null) | ||||||
|  |         { | ||||||
|  |             return "[[" + $"[{style.ToMarkup()}]X[/]" + "]]"; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return isGroup && mode == SelectionMode.Leaf | ||||||
|  |             ? GroupSelectedCheckbox : SelectedCheckbox; | ||||||
|  |     } | ||||||
| } | } | ||||||
| @@ -257,8 +257,7 @@ public sealed class MultiSelectionPrompt<T> : IPrompt<List<T>>, IListPromptStrat | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             var checkbox = item.Node.IsSelected |             var checkbox = item.Node.IsSelected | ||||||
|                 ? (item.Node.IsGroup && Mode == SelectionMode.Leaf |                 ? ListPromptConstants.GetSelectedCheckbox(item.Node.IsGroup, Mode, HighlightStyle) | ||||||
|                     ? ListPromptConstants.GroupSelectedCheckbox : ListPromptConstants.SelectedCheckbox) |  | ||||||
|                 : ListPromptConstants.Checkbox; |                 : ListPromptConstants.Checkbox; | ||||||
|  |  | ||||||
|             grid.AddRow(new Markup(indent + prompt + " " + checkbox + " " + text, style)); |             grid.AddRow(new Markup(indent + prompt + " " + checkbox + " " + text, style)); | ||||||
|   | |||||||
| @@ -195,7 +195,7 @@ public sealed class Calendar : JustInTimeRenderable, IHasCulture, IHasTableBorde | |||||||
|         while (currentDay <= daysInMonth) |         while (currentDay <= daysInMonth) | ||||||
|         { |         { | ||||||
|             if (weekdays[currentDay - 1] == weekday) |             if (weekdays[currentDay - 1] == weekday) | ||||||
|             { |             { | ||||||
|                 var todayEvent = _calendarEvents.LastOrDefault(e => e.Month == Month && e.Day == currentDay); |                 var todayEvent = _calendarEvents.LastOrDefault(e => e.Month == Month && e.Day == currentDay); | ||||||
|                 if (todayEvent != null) |                 if (todayEvent != null) | ||||||
|                 { |                 { | ||||||
|   | |||||||
| @@ -28,34 +28,34 @@ public sealed class CalendarEvent | |||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Gets the custom highlight style of the calendar event. |     /// Gets the custom highlight style of the calendar event. | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     public Style? CustomHighlightStyle { get; } |     public Style? CustomHighlightStyle { get; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Initializes a new instance of the <see cref="CalendarEvent"/> class. |     /// Initializes a new instance of the <see cref="CalendarEvent"/> class. | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     /// <param name="year">The year of the calendar event.</param> |     /// <param name="year">The year of the calendar event.</param> | ||||||
|     /// <param name="month">The month of the calendar event.</param> |     /// <param name="month">The month of the calendar event.</param> | ||||||
|     /// <param name="day">The day of the calendar event.</param> |     /// <param name="day">The day of the calendar event.</param> | ||||||
|     /// <param name="customHighlightStyle">The custom highlight style of the calendar event.</param> |     /// <param name="customHighlightStyle">The custom highlight style of the calendar event.</param> | ||||||
|     public CalendarEvent(int year, int month, int day, Style? customHighlightStyle = null) |     public CalendarEvent(int year, int month, int day, Style? customHighlightStyle = null) | ||||||
|         : this(string.Empty, year, month, day, customHighlightStyle) |         : this(string.Empty, year, month, day, customHighlightStyle) | ||||||
|     { |     { | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Initializes a new instance of the <see cref="CalendarEvent"/> class. |     /// Initializes a new instance of the <see cref="CalendarEvent"/> class. | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     /// <param name="description">The calendar event description.</param> |     /// <param name="description">The calendar event description.</param> | ||||||
|     /// <param name="year">The year of the calendar event.</param> |     /// <param name="year">The year of the calendar event.</param> | ||||||
|     /// <param name="month">The month of the calendar event.</param> |     /// <param name="month">The month of the calendar event.</param> | ||||||
|     /// <param name="day">The day of the calendar event.</param> |     /// <param name="day">The day of the calendar event.</param> | ||||||
|     /// <param name="customHighlightStyle">The custom highlight style of the calendar event.</param> |     /// <param name="customHighlightStyle">The custom highlight style of the calendar event.</param> | ||||||
|     public CalendarEvent(string description, int year, int month, int day, Style? customHighlightStyle = null) |     public CalendarEvent(string description, int year, int month, int day, Style? customHighlightStyle = null) | ||||||
|     { |     { | ||||||
|         Description = description ?? string.Empty; |         Description = description ?? string.Empty; | ||||||
|         Year = year; |         Year = year; | ||||||
|         Month = month; |         Month = month; | ||||||
|         Day = day; |         Day = day; | ||||||
|         CustomHighlightStyle = customHighlightStyle; |         CustomHighlightStyle = customHighlightStyle; | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user
	 Davide Piccinini
					Davide Piccinini