Fixes #3641. CheckBox.State -> CheckBox.CheckState (#3648)

* State->CheckState.
Toggled->CheckStateChanging.

* Code cleanup & doc fix

* Updated migration guide

* Updated migration guide
This commit is contained in:
Tig
2024-08-06 08:39:55 -06:00
committed by GitHub
parent 363cdddb2c
commit 0bd50c5b93
32 changed files with 283 additions and 245 deletions

View File

@@ -296,3 +296,33 @@ The [Aligner](~/api/Terminal.Gui.Aligner.yml) class makes it easy to align eleme
- );
+ var statusBar = new StatusBar (new Shortcut [] { new (Application.QuitKey, "Quit", Quit) });
```
## `CheckBox` - API renamed and simplified
In v1 `CheckBox` used `bool?` to represent the 3 states. To support consistent behavior for the `Accept` event, `CheckBox` was refactored to use the new `CheckState` enum instead of `bool?`.
Additionally the `Toggle` event was renamed `CheckStateChanging` and made cancelable. The `Toggle` method was renamed to `AdvanceCheckState`.
### How to Fix
```diff
-var cb = new CheckBox ("_Checkbox", true); {
- X = Pos.Right (label) + 1,
- Y = Pos.Top (label) + 2
- };
- cb.Toggled += (e) => {
- };
- cb.Toggle ();
+
+var cb = new CheckBox ()
+{
+ Title = "_Checkbox",
+ CheckState = CheckState.Checked
+}
+cb.CheckStateChanging += (s, e) =>
+{
+ e.Cancel = preventChange;
+}
+preventChange = false;
+cb.AdvanceCheckState ();
```