Skip to content

Commit be9d193

Browse files
tigCopilotBDisp
authored
Fixes #4372 - Genericize FlagSelector/OptionSelector, Replace RadioGroup (#4373)
* Refactor selectors and improve UI components Refactored `MarginEditor` and `UICatalogTop` to use new `OptionSelector` and `FlagSelector` classes, introducing type-safe generic versions for better flexibility and maintainability. Added `SelectorBase` as a shared foundation for these components, along with the `SelectorStyles` enum for customizable styles. Enhanced unit tests to cover new implementations and edge cases. Enabled nullable reference types for improved null safety. Improved code readability, reduced redundancy, and enhanced user experience with better hotkey management, focus handling, and layout adjustments. * Refactor UI components and remove unused classes Significant refactoring and simplification of the codebase: - Updated `CharacterMap` to use `OptionSelector<UnicodeCategory>`. - Removed `FlagSelector`, `FlagSelector<TEnum>`, and `FlagSelectorStyles`. - Replaced `OptionSelector.Options` with `Labels` in `MenuBarv2`. - Removed `OptionSelector` and its associated properties/methods. - Updated terminology from "Activate" to "Select" across components. - Refactored `SelectorBase` to align with new "Select" behavior. - Removed redundant methods, properties, and event handlers. These changes streamline the codebase, reduce complexity, and align with updated design principles. * Fixes #4374 - 'Application.Screen' is empty when 'Init' returns Refactor and enhance testability of ApplicationImpl Refactored `ApplicationImpl` and related classes to improve modularity and testability. Replaced `FakeConsoleOutput` with `FakeOutput` and introduced `FakeInput` for better test isolation. Added platform-specific factories (`FakeNetComponentFactory`, `FakeWindowsComponentFactory`) to simplify fake component creation. Refactored `GuiTestContext` into partial classes, adding methods for simulating user interactions and improving initialization logic. Enhanced error handling and logging during test setup. Updated tests to use the new `FakeOutput` and `FakeInput` implementations. Standardized driver initialization with `Application.Init(null, "fake")`. Skipped tests relying on the fake driver due to known issues. Performed general cleanup, modernized syntax, and removed redundant code to improve readability and maintainability. * Disable "windows" test case in SynchronizationContextTests The `InlineData("windows")` attribute in the `SynchronizationContext_Post` test method has been commented out. This change temporarily excludes the `"windows"` driverName from the test suite while retaining other test cases (`"fake"`, `"dotnet"`, and `"unix"`). The exclusion may be for debugging, deprecation, or other maintenance purposes. * Disable "windows" test case in SynchronizationContextTests The `[InlineData("windows")]` attribute in the `SynchronizationContextTests` class has been commented out, disabling the test case for the `"windows"` driver name. This change may have been made for debugging, deprecation, or because the test is no longer relevant. Other test cases (`"fake"`, `"dotnet"`, and `"unix"`) remain active. * Update Terminal.Gui/Drivers/FakeDriver/FakeConsole.cs Co-authored-by: Copilot <[email protected]> * Update Terminal.Gui/Views/Selectors/SelectorStyles.cs Co-authored-by: Copilot <[email protected]> * Update Terminal.Gui/Views/Selectors/SelectorBase.cs Co-authored-by: Copilot <[email protected]> * Update Terminal.Gui/Views/Selectors/OptionSelector.cs Co-authored-by: Copilot <[email protected]> * Update Terminal.Gui/Views/Selectors/OptionSelector.cs Co-authored-by: Copilot <[email protected]> * Update Terminal.Gui/Views/Selectors/OptionSelector.cs Co-authored-by: Copilot <[email protected]> * Update Terminal.Gui/Views/Selectors/SelectorBase.cs Co-authored-by: Copilot <[email protected]> * Backported Checkbox from Activate PR * Backported Checkbox from Activate PR 2 * Backported Checkbox from Activate PR 3 * Backported Selctors Scenario * Backported Bars Scenario * Backported AllViewsTester Scenario * Backported Dialogs Scenario * Backported MessageBoxes Scenario * Backported ArrangementEditor * Backported mouse binding fix * Update Terminal.Gui/Views/Selectors/OptionSelector.cs Co-authored-by: Copilot <[email protected]> * Update Terminal.Gui/Drivers/WindowsDriver/WindowsOutput.cs Co-authored-by: Copilot <[email protected]> * Update Terminal.Gui/Views/CheckBox.cs Co-authored-by: Copilot <[email protected]> * Fixed typo * Refactor ArrangementEditor event handling Removed the `ArrangementFlagsOnValueChanged` method, which previously handled updates to `ViewToEdit` properties based on arrangement flags. Updated `ArrangementEditor_Initialized` to attach the event handler to `_arrangementSelector.ValueChanged`. The logic for handling arrangement changes has been refactored or relocated. * Refactor AlignKeys for type safety and readability Updated the `AlignKeys` method in the `Shortcuts` class to replace generic `View` references with the more specific `Shortcut` type. Improved type safety by using `IEnumerable<Shortcut>` and `.Cast<Shortcut>()`. Simplified the `max` calculation logic with a single LINQ query and removed redundant casting in the `foreach` loop. These changes enhance code readability, maintainability, and ensure better type safety. * Refactor ArrangementEditor for clarity and consistency Refactored `ArrangementEditor` to improve code readability and maintainability: - Enabled nullable reference types with `#nullable enable`. - Removed unused `using` directives. - Adjusted namespace declaration for formatting consistency. - Reformatted `_arrangementSelector` initialization and property assignment. - Simplified `OnViewToEditChanged` logic with a ternary expression. - Refactored `ArrangementEditor_Initialized` into a single-line block. * Update Examples/UICatalog/Scenarios/Shortcuts.cs Co-authored-by: Copilot <[email protected]> * Update Terminal.Gui/Views/Selectors/OptionSelector.cs Co-authored-by: Copilot <[email protected]> * Refactor and enhance OptionSelector and SelectorBase Refactored `OptionSelector` and `SelectorBase` to simplify logic, improve hotkey assignment, and ensure robust behavior. Updated `Shortcuts.cs` and `DialogTests.cs` to address nullability issues. Added comprehensive unit tests for `OptionSelector` and `SelectorBase`, covering properties, methods, edge cases, and layout behaviors. These changes improve code readability, maintainability, and functionality while adhering to modern C# practices. * add FlagSelector comprehensive tests Refactored `UncheckNone` and `UncheckAll` methods in `FlagSelector` to improve clarity and prevent concurrent modifications using a new `_updatingChecked` flag. Removed the old `UncheckNone` implementation and reorganized logic for maintainability. Added extensive unit tests in `FlagSelectorTests` to validate functionality, including edge cases and generic implementations. Tests cover flag combination, toggling, "None" flag behavior, and enum-based generic handling. Improved overall maintainability and test coverage for the `FlagSelector` class. * Fixes #4375. UnixDriver fails Toplevel_TabGroup_Forward_Backward Fluent Tests * Refactor RadioGroup to use OptionSelector The `RadioGroup` class has been refactored to inherit from the `OptionSelector` class instead of `View`, marking it as `[Obsolete]` and recommending the use of `OptionSelector`. The previous implementation of `RadioGroup` has been entirely removed, including its properties, methods, events, and internal logic. This includes initialization logic, key bindings, layout management, and event handling. The new `RadioGroup` is now a thin wrapper around `OptionSelector` and implements the `IDesignable` interface. The `EnableForDesign` method has been simplified to set default options for design purposes. This change simplifies the codebase and encourages the use of `OptionSelector` for managing mutually exclusive options. * Backported focus tests and add bug-exposing test case Refactored `AdvanceFocusTests` to improve assertion clarity by replacing `Assert.True`/`Assert.False` with `Assert.Equal`. Enhanced test documentation with detailed view hierarchy comments for better readability. Added a new test case, `FocusNavigation_Should_Cycle_Back_To_Top_Level_Views`, which exposes a bug in focus navigation logic where focus does not cycle back to top-level views after traversing nested views. Updated existing tests to ensure consistent handling of `TabBehavior` and made minor adjustments for improved validation of focus navigation logic. * Remove all tests for RadioGroup component The `RadioGroupTests.cs` file has been completely cleared of all test cases and associated code. This includes the removal of unit tests that validated the `RadioGroup` component's functionality, behavior, and edge cases. The deleted tests covered: - Default constructor behavior and initialization. - Handling of the `SelectedItem` property, including edge cases. - Hotkey bindings and their behavior under different focus states. - Command handling for focus, selection, and acceptance. - Orientation changes and their impact on layout. - Event handling for `SelectedItemChanged`, `Selecting`, and `Accepting`. - Mouse interactions, including single-click and double-click events. This removal eliminates all automated validation for the `RadioGroup` component, leaving it untested and increasing the risk of regressions or undetected issues in future changes. * Fix unix and fake fluent tests. * More fixes for unix and fake drivers * Change classes names for more consistency * Fix typos in docs and method signature Updated XML documentation in `FakeConsole.cs` to replace `<see cref="FakeDriver"/>` with `<exception cref="FakeDriver"></exception>` for clarity. Corrected a parameter name in `WindowsOutput.cs`'s `WriteConsole` method from `numberOfCharsToWritten` to `numberOfCharsToWrite` to fix a typo and improve readability. * Refactor: Replace RadioGroup with OptionSelector Replaced all instances of `RadioGroup` with `OptionSelector` across the codebase to standardize the control for mutually exclusive options. Updated associated properties, methods, and event handlers to align with the `OptionSelector` API, including replacing `RadioLabels` with `AssignHotKeys` and `SelectedItemChanged` with `ValueChanged`. Removed the `RadioGroup` class, marking it as obsolete. Updated documentation, comments, and test cases to reflect the new control. Adjusted layout and positioning logic in various scenarios to ensure UI consistency. Refactored scenarios such as `Buttons`, `ColorPickers`, `DynamicMenuBar`, `FileDialogExamples`, `Images`, `PosAlignDemo`, `ProgressBarStyles`, `RegionScenario`, `Themes`, and others to use `OptionSelector`. Updated `Glyphs` and `View` classes to reflect the terminology change. Cleaned up redundant code and ensured compatibility across the application. * Refactor OptionSelector to use Value instead of SelectedItem Replaced the SelectedItem property with a nullable Value property across the codebase to simplify the API and improve consistency. Updated event handlers from SelectedItemChanged to ValueChanged and adjusted logic accordingly. Refactored UI scenarios (e.g., Buttons, CharacterMap, ColorPickers) and dependent classes (e.g., BorderEditor, DimEditor, PosEditor) to use the new Value property. Improved null handling and streamlined initialization of controls. Updated tests to validate the Value property and renamed test methods for clarity. Removed the RegionOpSelector class as it was no longer needed. Performed general code cleanup, including formatting and removal of redundant code. * Refactor OptionSelector: Replace RadioLabels with Labels Updated the `OptionSelector` class and its derived classes to replace the `RadioLabels` property with a more generic `Labels` property, aligning with the base class `SelectorBase`. This change standardizes the API and simplifies label-related functionality. Refactored all instances of `RadioLabels` across the codebase, including property assignments, method calls, and references in scenarios, tests, and examples. Updated classes include `ColorPickers`, `Dialogs`, `DimAutoDemo`, `DynamicMenuBar`, `FileDialogExamples`, `Images`, `PosAlignDemo`, `Selectors`, `Shortcuts`, `TextAlignmentAndDirection`, `Themes`, `UnicodeInMenu`, `Wizards`, `UICatalogTop`, and `ScenarioTests`. Modified `OptionSelector<TEnum>` to initialize `Labels` directly using `Enum.GetValues<TEnum>()`. Removed the `RadioLabels` property from `OptionSelector`, consolidating functionality under `Labels`. Verified functionality through updated tests and scenarios to ensure consistent behavior with the previous implementation. * Refactor: Replace "radio group" with "option selector" Updated terminology across multiple classes to replace "radio group" with "option selector" for improved clarity and consistency. - Removed unused `OptionSelector` in `ColorPickers`. - Renamed `Title` in `DimAutoDemo` to "Options" and updated `BorderStyle`. - Replaced `_radioItems` with `_optionLabels` in `DimEditor` and `PosEditor`. - Renamed `styleRadioGroup` to `styleOptionSelector` in `MessageBoxes`. - Renamed `radioGroup` to `optionSelector` in `UnicodeInMenu` and `OrientationTests`. - Adjusted related references, event handlers, and UI properties. These changes align the codebase with updated terminology and improve readability. * Replace RadioGroup with OptionSelector and update docs The `RadioGroup` control has been replaced or renamed to `OptionSelector`. Documentation has been updated to reflect this change, including the behavior of raising the `Selecting` event when an option is selected. The navigation table now describes `OptionSelector` as supporting multiple options with actions like `Advance`, `SetValue+OnAccept`, and `Focus+SetValue`. A new section introduces the `OptionSelector` view, which displays mutually-exclusive items with hotkeys. Enhancements to `Menuv2` and `MenuBarv2` include setting focus on `MenuItemv2` selections and raising the `SelectedMenuItemChanged` event. Additionally, a progress bar view has been introduced to visually indicate activity progress. * Fixed `EndAfterFirstIteration` Renamed the `EndAfterFirstIteration` property to `StopAfterFirstIteration` across the codebase for improved clarity and consistency. Updated all references in the `Application`, `ApplicationImpl`, `IApplication`, and `ITimedEvents` classes, as well as related tests and documentation. Modified the application loop logic to use `StopAfterFirstIteration` for controlling the termination of the application after the first iteration. Set its default value to `false`. Updated test cases, demo applications, and XML documentation to reflect the new property name. Added a new project, `OutputView`, to the solution with appropriate configuration entries. Performed minor code cleanup to ensure consistency in naming and behavior. * Enhance selectors and clean up documentation - Added `args.Handled = true` to `CheckBox` event handlers in `FlagSelector` and `OptionSelector` to mark events as handled. - Introduced `_value` field in `FlagSelector` and added a `Cycle` method in `OptionSelector` for better value management. - Updated `OptionSelector` documentation to reference `OptionSelector<TEnum>` for type-safe enum usage. - Improved `UpdateChecked` method documentation in `OptionSelector` to clarify exception behavior. - Enabled nullable reference types in `FlagSelectorTests` and `SelectorBaseTests` and moved them to a new namespace. - Removed outdated auto-generated content from `views.md`. - Removed `CheckBox.DefaultHighlightStyle` from the default theme configuration in `OutputView.cs`. * Update event handling and expand UI documentation Modified `args.Handled` in `FlagSelector` and `OptionSelector` to allow `Accepting` event propagation, improving event handling behavior. Added comments to clarify the changes. Expanded `views.md` with detailed documentation for built-in views and controls in *Terminal.Gui*, including descriptions, examples, and rendered outputs for components like `Bar`, `Button`, `CheckBox`, and more. This update enhances developer guidance for building terminal-based UIs. * Fixed `EndAfterFirstIteration` in `ApplicationImpl` Renamed the `EndAfterFirstIteration` property to `StopAfterFirstIteration` across the codebase for improved clarity. Updated its implementation to use a getter and setter that interact with the `ApplicationImpl.Instance` singleton for centralized management. Modified the `RunLoop` method to check the new `StopAfterFirstIteration` property. Updated the default value to `false` in the `Application` class. Added a private `_stopAfterFirstIteration` field and a corresponding public property in the `ApplicationImpl` class. Updated the `Run` method in `ApplicationImpl` to stop after the first iteration if the property is set to `true`, with appropriate logging. Updated the `IApplication` interface to include the `StopAfterFirstIteration` property and clarified the behavior of the `RequestStop` method. Revised XML documentation comments to reflect these changes. * Fixed EndfterFirstIteration in ApplicaitonImpl Refactored `StopAfterFirstIteration` in `ApplicationImpl` to use an auto-property for simplicity. Updated `RunIteration` to call `view.RequestStop()` instead of modifying `view.Running`. Replaced references to `Application.EndAfterFirstIteration` with `Application.StopAfterFirstIteration` across the codebase, including `ITimedEvents`, `ApplicationTests`, and `GlobalTestSetup`. Added a new test, `InitRunShutdown_StopAfterFirstIteration_Stops`, to verify the application stops correctly after the first iteration. Updated related documentation and assertions for consistency. * Refactor Value handling and improve type safety Refactored `Value` handling across multiple classes to use nullable generic types, improving type safety and eliminating unnecessary casting. Simplified `ValueChanged` event handlers with concise lambda expressions. Enhanced `FlagSelector<TFlagsEnum>` and `OptionSelector<TEnum>` with generic `ValueChanged` events and type-safe event handling. Added nullable reference type annotations to align with modern C# practices. Improved test code by using null-forgiving operators and more descriptive assertions. Cleaned up redundant code and ensured consistency in `Value` handling. Updated `FlagSelectorTests` and `SelectorBaseTests` for better readability and maintainability. Added the `System` namespace to `FlagSelectorTEnum.cs` for compatibility. Overall, these changes enhance code readability, maintainability, and robustness. * Merged v2_develop * Update README badges for v2_develop branch Updated the `.NET Core` badge to reference the `v2_develop` branch. Adjusted the `codecov` badge to remove branch-specific paths and added a token parameter. Reorganized the `codecov` badge position in the README. Retained other badges without modification. * codcov2 * fixed pos tests * Improve cleanup, coverage config, and SpinnerStyle tests Enhanced resource cleanup in `Pos.CombineTests.cs` by disposing of `Application.Top` to prevent leaks. Updated `codecov.yml` to focus coverage on `Terminal.Gui`, simplified path patterns, and clarified configurations. Added `SpinnerStyleTests` with extensive unit tests for `SpinnerStyle` and its variants, covering default properties, behaviors, edge cases, and immutability. Organized tests for readability and ensured thorough validation of all spinner styles. Enabled nullable reference types for improved safety. * Remove .NET Core badge; add comprehensive boundary tests The `.NET Core` workflow badge was removed from the `README.md` file. Added a comprehensive suite of unit tests for the `Region.DrawOuterBoundary` method in `DrawOuterBoundaryTests.cs`. These tests validate the method's behavior across various scenarios, including: - Intersected, unioned, and complex shapes. - Edge cases like empty regions, zero-width/height rectangles, and single-pixel rectangles. - Specific shapes such as L-shaped, T-shaped, and hollow rectangles. - Overlapping, adjacent, and separate rectangles. - Thread safety with parallel drawing. - Different line styles, custom attributes, and very large regions. - Various positions, sizes, and multiple calls on the same canvas. The tests use the `Xunit` framework and include both `[Fact]` and `[Theory]` test cases. These changes enhance the codebase's robustness and ensure correctness in a wide range of scenarios. --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: BDisp <[email protected]>
1 parent 55b45d4 commit be9d193

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+4510
-3329
lines changed

Examples/UICatalog/Scenarios/AllViewsTester.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,13 @@ public override void Main ()
158158

159159
_eventLog = new ()
160160
{
161-
// X = Pos.Right(_layoutEditor),
161+
X = Pos.AnchorEnd () - 1,
162+
Y = 0,
163+
Width = 30,
164+
Height = Dim.Fill (),
162165
SuperViewRendersLineCanvas = true
163166
};
164167
_eventLog.Border!.Thickness = new (1);
165-
_eventLog.X = Pos.AnchorEnd () - 1;
166-
_eventLog.Y = 0;
167-
168-
_eventLog.Height = Dim.Height (_classListView);
169-
170-
//_eventLog.Width = 30;
171168

172169
_layoutEditor.Width = Dim.Fill (
173170
Dim.Func (
@@ -194,7 +191,6 @@ public override void Main ()
194191
Height = Dim.Fill (),
195192
CanFocus = true,
196193
TabStop = TabBehavior.TabStop,
197-
//SchemeName = SchemeManager.SchemesToSchemeName (Schemes.Base),
198194
Arrangement = ViewArrangement.LeftResizable | ViewArrangement.BottomResizable | ViewArrangement.RightResizable,
199195
BorderStyle = LineStyle.Double,
200196
SuperViewRendersLineCanvas = true
@@ -228,7 +224,7 @@ private void CreateCurrentView (Type type)
228224
if (type.IsGenericType)
229225
{
230226
// For each of the <T> arguments
231-
List<Type> typeArguments = new ();
227+
List<Type> typeArguments = [];
232228

233229
// use <object> or the original type if applicable
234230
foreach (Type arg in type.GetGenericArguments ())

Examples/UICatalog/Scenarios/Bars.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ void PopOverMenuOnAccept (object o, CommandEventArgs args)
185185

186186
menuLikeExamples.Add (popOverMenu);
187187

188-
menuLikeExamples.MouseClick += MenuLikeExamplesMouseClick;
188+
menuLikeExamples.MouseEvent += MenuLikeExamplesMouseEvent;
189189

190-
void MenuLikeExamplesMouseClick (object sender, MouseEventArgs e)
190+
void MenuLikeExamplesMouseEvent (object _, MouseEventArgs e)
191191
{
192192
if (e.Flags.HasFlag (MouseFlags.Button3Clicked))
193193
{

Examples/UICatalog/Scenarios/Buttons.cs

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -243,17 +243,17 @@ static void DoMessage (Button button, string txt)
243243
};
244244
main.Add (label);
245245

246-
var radioGroup = new RadioGroup
246+
OptionSelector<Alignment> osAlignment = new ()
247247
{
248248
X = 4,
249249
Y = Pos.Bottom (label) + 1,
250-
SelectedItem = 2,
251-
RadioLabels = new [] { "_Start", "_End", "_Center", "_Fill" },
252-
Title = "_9 RadioGroup",
250+
Value = Alignment.Center,
251+
AssignHotKeys = true,
252+
Title = "_9 OptionSelector",
253253
BorderStyle = LineStyle.Dotted,
254254
// CanFocus = false
255255
};
256-
main.Add (radioGroup);
256+
main.Add (osAlignment);
257257

258258
// Demo changing hotkey
259259
string MoveHotkey (string txt)
@@ -292,7 +292,7 @@ string MoveHotkey (string txt)
292292
var moveHotKeyBtn = new Button
293293
{
294294
X = 2,
295-
Y = Pos.Bottom (radioGroup) + 1,
295+
Y = Pos.Bottom (osAlignment) + 1,
296296
Width = Dim.Width (computedFrame) - 2,
297297
SchemeName = "TopLevel",
298298
Text = mhkb
@@ -309,7 +309,7 @@ string MoveHotkey (string txt)
309309
var moveUnicodeHotKeyBtn = new Button
310310
{
311311
X = Pos.Left (absoluteFrame) + 1,
312-
Y = Pos.Bottom (radioGroup) + 1,
312+
Y = Pos.Bottom (osAlignment) + 1,
313313
Width = Dim.Width (absoluteFrame) - 2,
314314
SchemeName = "TopLevel",
315315
Text = muhkb
@@ -321,48 +321,21 @@ string MoveHotkey (string txt)
321321
};
322322
main.Add (moveUnicodeHotKeyBtn);
323323

324-
radioGroup.SelectedItemChanged += (s, args) =>
325-
{
326-
switch (args.SelectedItem)
327-
{
328-
case 0:
329-
moveBtn.TextAlignment = Alignment.Start;
330-
sizeBtn.TextAlignment = Alignment.Start;
331-
moveBtnA.TextAlignment = Alignment.Start;
332-
sizeBtnA.TextAlignment = Alignment.Start;
333-
moveHotKeyBtn.TextAlignment = Alignment.Start;
334-
moveUnicodeHotKeyBtn.TextAlignment = Alignment.Start;
335-
336-
break;
337-
case 1:
338-
moveBtn.TextAlignment = Alignment.End;
339-
sizeBtn.TextAlignment = Alignment.End;
340-
moveBtnA.TextAlignment = Alignment.End;
341-
sizeBtnA.TextAlignment = Alignment.End;
342-
moveHotKeyBtn.TextAlignment = Alignment.End;
343-
moveUnicodeHotKeyBtn.TextAlignment = Alignment.End;
344-
345-
break;
346-
case 2:
347-
moveBtn.TextAlignment = Alignment.Center;
348-
sizeBtn.TextAlignment = Alignment.Center;
349-
moveBtnA.TextAlignment = Alignment.Center;
350-
sizeBtnA.TextAlignment = Alignment.Center;
351-
moveHotKeyBtn.TextAlignment = Alignment.Center;
352-
moveUnicodeHotKeyBtn.TextAlignment = Alignment.Center;
353-
354-
break;
355-
case 3:
356-
moveBtn.TextAlignment = Alignment.Fill;
357-
sizeBtn.TextAlignment = Alignment.Fill;
358-
moveBtnA.TextAlignment = Alignment.Fill;
359-
sizeBtnA.TextAlignment = Alignment.Fill;
360-
moveHotKeyBtn.TextAlignment = Alignment.Fill;
361-
moveUnicodeHotKeyBtn.TextAlignment = Alignment.Fill;
362-
363-
break;
364-
}
365-
};
324+
osAlignment.ValueChanged += (s, args) =>
325+
{
326+
if (args.Value is null)
327+
{
328+
return;
329+
}
330+
331+
Alignment newValue = args.Value.Value;
332+
moveBtn.TextAlignment = newValue;
333+
sizeBtn.TextAlignment = newValue;
334+
moveBtnA.TextAlignment = newValue;
335+
sizeBtnA.TextAlignment = newValue;
336+
moveHotKeyBtn.TextAlignment = newValue;
337+
moveUnicodeHotKeyBtn.TextAlignment = newValue;
338+
};
366339

367340
label = new ()
368341
{

Examples/UICatalog/Scenarios/CharacterMap/CharacterMap.cs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -365,40 +365,16 @@ private MenuItemv2 CreateMenuUnicodeCategorySelector ()
365365
options [0] = "All";
366366
Array.Copy (allCategoryNames, 0, options, 1, allCategoryNames.Length);
367367

368-
// TODO: When #4126 is merged update this to use OptionSelector<UnicodeCategory?>
369-
var selector = new OptionSelector
370-
{
371-
AssignHotKeysToCheckBoxes = true,
372-
Options = options
373-
};
368+
// TODO: Add a "None" option
369+
OptionSelector<UnicodeCategory> selector = new ();
374370

375371
_unicodeCategorySelector = selector;
376372

377-
// Default to "All"
378-
selector.SelectedItem = 0;
373+
selector.Value = null;
379374
_charMap!.ShowUnicodeCategory = null;
380375

381-
selector.SelectedItemChanged += (s, e) =>
382-
{
383-
int? idx = selector.SelectedItem;
384-
385-
if (idx is null)
386-
{
387-
return;
388-
}
389-
390-
if (idx.Value == 0)
391-
{
392-
_charMap.ShowUnicodeCategory = null;
393-
}
394-
else
395-
{
396-
// Map index to UnicodeCategory (offset by 1 because 0 is "All")
397-
UnicodeCategory cat = Enum.GetValues<UnicodeCategory> () [idx.Value - 1];
398-
_charMap.ShowUnicodeCategory = cat;
399-
}
400-
};
401-
402-
return new() { CommandView = selector };
376+
selector.ValueChanged += (_, e) => _charMap.ShowUnicodeCategory = e.Value;
377+
378+
return new () { CommandView = selector };
403379
}
404380
}

Examples/UICatalog/Scenarios/ColorPicker.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,26 +125,25 @@ public override void Main ()
125125
app.Add (_demoView);
126126

127127

128-
// Radio for switching color models
129-
var rgColorModel = new RadioGroup ()
128+
var osColorModel = new OptionSelector ()
130129
{
131130
Y = Pos.Bottom (_demoView),
132131
Width = Dim.Auto (),
133132
Height = Dim.Auto (),
134-
RadioLabels = new []
135-
{
133+
Labels =
134+
[
136135
"_RGB",
137136
"_HSV",
138137
"H_SL",
139138
"_16 Colors"
140-
},
141-
SelectedItem = (int)foregroundColorPicker.Style.ColorModel,
139+
],
140+
Value = (int)foregroundColorPicker.Style.ColorModel,
142141
};
143142

144-
rgColorModel.SelectedItemChanged += (_, e) =>
143+
osColorModel.ValueChanged += (_, e) =>
145144
{
146145
// 16 colors
147-
if (e.SelectedItem == 3)
146+
if (e.Value == 3)
148147
{
149148

150149
foregroundColorPicker16.Visible = true;
@@ -161,12 +160,17 @@ public override void Main ()
161160
{
162161
foregroundColorPicker16.Visible = false;
163162
foregroundColorPicker.Visible = true;
164-
foregroundColorPicker.Style.ColorModel = (ColorModel)e.SelectedItem;
165-
foregroundColorPicker.ApplyStyleChanges ();
166163

167-
backgroundColorPicker16.Visible = false;
168-
backgroundColorPicker.Visible = true;
169-
backgroundColorPicker.Style.ColorModel = (ColorModel)e.SelectedItem;
164+
if (e.Value is { })
165+
{
166+
foregroundColorPicker.Style.ColorModel = (ColorModel)e.Value;
167+
foregroundColorPicker.ApplyStyleChanges ();
168+
169+
backgroundColorPicker16.Visible = false;
170+
backgroundColorPicker.Visible = true;
171+
backgroundColorPicker.Style.ColorModel = (ColorModel)e.Value;
172+
}
173+
170174
backgroundColorPicker.ApplyStyleChanges ();
171175

172176

@@ -176,13 +180,13 @@ public override void Main ()
176180
}
177181
};
178182

179-
app.Add (rgColorModel);
183+
app.Add (osColorModel);
180184

181185
// Checkbox for switching show text fields on and off
182186
var cbShowTextFields = new CheckBox ()
183187
{
184188
Text = "Show _Text Fields",
185-
Y = Pos.Bottom (rgColorModel) + 1,
189+
Y = Pos.Bottom (osColorModel) + 1,
186190
Width = Dim.Auto (),
187191
Height = Dim.Auto (),
188192
CheckedState = foregroundColorPicker.Style.ShowTextFields ? CheckState.Checked : CheckState.UnChecked,

Examples/UICatalog/Scenarios/Dialogs.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,15 @@ public override void Main ()
151151
};
152152
frame.Add (label);
153153

154-
// Add hotkeys
155-
var labels = Enum.GetNames<Alignment> ().Select (n => n = "_" + n);
156-
var alignmentGroup = new RadioGroup
154+
OptionSelector<Alignment> alignmentOptionSelector = new ()
157155
{
158156
X = Pos.Right (label) + 1,
159157
Y = Pos.Top (label),
160-
RadioLabels = labels.ToArray (),
161158
Title = "Ali_gn",
162-
BorderStyle = LineStyle.Dashed
159+
AssignHotKeys = true
163160
};
164-
frame.Add (alignmentGroup);
165-
alignmentGroup.SelectedItem = labels.ToList ().IndexOf ("_" + Dialog.DefaultButtonAlignment.ToString ());
161+
frame.Add (alignmentOptionSelector);
162+
alignmentOptionSelector.Value = Dialog.DefaultButtonAlignment;
166163

167164
frame.ValidatePosDim = true;
168165

@@ -192,7 +189,7 @@ public override void Main ()
192189
titleEdit,
193190
numButtonsEdit,
194191
glyphsNotWords,
195-
alignmentGroup,
192+
alignmentOptionSelector,
196193
buttonPressedLabel
197194
);
198195
Application.Run (dlg);
@@ -216,7 +213,7 @@ private Dialog CreateDemoDialog (
216213
TextField titleEdit,
217214
TextField numButtonsEdit,
218215
CheckBox glyphsNotWords,
219-
RadioGroup alignmentRadioGroup,
216+
OptionSelector alignmentGroup,
220217
Label buttonPressedLabel
221218
)
222219
{
@@ -269,7 +266,7 @@ Label buttonPressedLabel
269266
{
270267
Title = titleEdit.Text,
271268
Text = "Dialog Text",
272-
ButtonAlignment = (Alignment)Enum.Parse (typeof (Alignment), alignmentRadioGroup.RadioLabels [alignmentRadioGroup.SelectedItem].Substring (1)),
269+
ButtonAlignment = (Alignment)Enum.Parse (typeof (Alignment), alignmentGroup.Labels! [(int)alignmentGroup.Value!.Value] [1..]),
273270

274271
Buttons = buttons.ToArray ()
275272
};

Examples/UICatalog/Scenarios/DimAutoDemo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ private static FrameView CreateDimAutoContentFrameView ()
163163
dimAutoFrameView.Add (resetButton);
164164

165165

166-
var radioGroup = new RadioGroup ()
166+
var optionSelector = new OptionSelector ()
167167
{
168-
RadioLabels = ["One", "Two", "Three"],
168+
Labels = ["One", "Two", "Three"],
169169
X = 0,
170170
Y = Pos.AnchorEnd (),
171-
Title = "Radios",
171+
Title = "Options",
172172
BorderStyle = LineStyle.Dotted
173173
};
174-
dimAutoFrameView.Add (radioGroup);
174+
dimAutoFrameView.Add (optionSelector);
175175
return dimAutoFrameView;
176176
}
177177

0 commit comments

Comments
 (0)