Skip to content

feat: input masks, validators and formatters on Text and Numeric column editors (#376) - #512

Open
michaelstonis wants to merge 2 commits into
mainfrom
feat/376-masks-validators-formatters
Open

michaelstonis wants to merge 2 commits into
mainfrom
feat/376-masks-validators-formatters

Conversation

@michaelstonis

Copy link
Copy Markdown
Contributor

Closes #376.

Changes

Text and Numeric column editors can now take an input mask, a maximum length, an input validator and an output formatter from the column, in XAML and in code.

  • KumikoColumn: EditorMask, EditorMaskIncludesLiterals, EditorMaskPromptChar (a one-character string so XAML can set it on both hosts, Uno included; default "_"), EditorMaxLength, EditorInputValidator, EditorOutputFormatter. CellEditorFactory copies them to the DrawnTextBox of CreateTextEditor and CreateNumericEditor (Numeric keeps NumericOnly, applied before the mask).
  • DrawnTextBox (new partial file DrawnTextBox.Mask.cs): the mask language is # digit, A letter, * any, \ escape, other characters literal. Literals are inserted automatically when typing, pasting and committing a composition (all go through TryReplaceSelection), characters that do not fit are dropped, and an edit that would push a character out of the mask is refused. Backspace and Delete skip literals and delete the neighboring input character. The unfilled positions are drawn with the prompt character in the placeholder color while editing (cached string, no per-frame allocation). The old reject-only ValidateAgainstMask is gone; the validator now sees the masked candidate text.
  • Stored value: IValueEditor.Value is the typed characters without the literals, unless InputMaskIncludesLiterals. EditSession.CommitEdit refuses a non-empty masked value with unfilled positions with the new KumikoStrings.EnterCompleteValue ("Enter a complete value."), before conversion; one early check, no other change to the commit path, so it composes with the column validator and item validation steps after it. An emptied editor clears the cell.
  • Typing trigger: the character that opens the editor goes through the mask, validator and maximum length (a refused character leaves the value and the edit untouched). A stored value opens laid out by the mask.
  • Soft keyboard: DrawnTextBox.PrefersNumericKeyboard (NumericOnly, or a mask whose input positions are all digits) is read by the MAUI Apple bridge, the Windows input scope and the Android mapper (which replaces its own IsDigitMask helper). The Uno proxy TextBox sets no input scope for numeric editors today, so there is nothing to match there.
  • TextEditorDescriptor: Mask and MaxLength.
  • Samples: a masked Phone column in the MAUI MainPage and the Uno BasicGridPage. README "Editing" section and CHANGELOG updated.

Public API added (all in PublicAPI.Unshipped.txt of Core; MAUI and Uno have no new public API):
KumikoColumn.EditorMask, EditorMaskIncludesLiterals, EditorMaskPromptChar, EditorMaxLength, EditorInputValidator, EditorOutputFormatter; TextEditorDescriptor.Mask, MaxLength; DrawnTextBox.MaskPromptChar, InputMaskIncludesLiterals, MaskValue, IsMaskComplete, ApplyInputMask(string?), PrefersNumericKeyboard; KumikoStrings.EnterCompleteValue.

Acceptance criteria

  • EditorMask, EditorMaxLength, EditorInputValidator and EditorOutputFormatter apply to Text and Numeric column editors, from XAML and code (the Func properties are code only, like the other delegate properties).
  • Literals are inserted automatically on typing, paste and composition; backspace over literals works.
  • Incomplete masked input fails validation with a localized message (EnterCompleteValue, added to the German localization test); literals are stripped or kept per EditorMaskIncludesLiterals.
  • TextEditorDescriptor exposes Mask and MaxLength.
  • Behavior tests: tests/KumikoUI.Core.Tests/Components/DrawnTextBoxMaskTests.cs (a sibling of DrawnTextBoxTests.cs) and tests/KumikoUI.Core.Tests/Editing/MaskedEditorTests.cs.
  • Works on MAUI and Uno, including the numeric soft keyboard for digit-only masks on MAUI (Android, Apple, Windows). Uno has no numeric keyboard hook for any editor today, so a digit mask behaves like a numeric editor there. Not run on devices.
  • A masked column in the MainPage (MAUI) and BasicGridPage (Uno) samples.
  • XML docs on every new public member; PublicAPI.Unshipped.txt updated (see Verification for how).
  • README "Editing" section updated; CHANGELOG entry under Unreleased.
  • No allocations added to the per-frame render path (the prompt string and the parsed mask are cached; they rebuild only when the text length, prompt character or mask changes).
  • Not done: the optional display (non-edit) formatting of a stored value with the mask. The issue marks it optional and it belongs in the cell text cache, close to renderer code.
  • Not done: DrawnNumericUpDown is unchanged (the Numeric column editor is a DrawnTextBox).

Verification

  • dotnet build src/KumikoUI.Core: 0 warnings, 0 errors.
  • dotnet build src/KumikoUI.Maui -f net10.0-maccatalyst: 0 warnings, 0 errors.
  • dotnet build src/KumikoUI.Uno -f net10.0-desktop: 0 errors; the 2 Uno0001 warnings (IsTextPredictionEnabled, IsHoldingEnabled) are in files this change does not touch.
  • dotnet build samples/SampleApp.Uno -f net10.0-desktop: 0 warnings, 0 errors.
  • dotnet build samples/SampleApp.Maui -f net10.0-maccatalyst: restore fails with NU1605 (Microsoft.Maui.Controls 10.0.110 vs 10.0.41) before this change too; with -p:NoWarn=NU1605 -p:TreatWarningsAsErrors=false -p:WarningsAsErrors= it builds with 0 errors, so the new XAML compiles.
  • dotnet test tests/KumikoUI.Core.Tests: 4404 passed, 5 skipped (existing skips), 0 failed (about 45 new tests).
  • dotnet test tests/KumikoUI.Maui.Tests: 449 passed. dotnet test tests/KumikoUI.Uno.Tests: 321 passed.
  • eng/update-public-api.sh Core could not regenerate the file here (dotnet format analyzers made no changes), so the 26 new lines were taken from the RS0016 diagnostics of a clean build and merged in sorted order; the build is clean afterwards.
  • The prompt character is a one-character string, so EditorMaskPromptChar="." compiles in Uno XAML (a char property cannot be set from Uno XAML: UXAML0001) and in MAUI XAML. Verified by using it in both sample apps and building them, and by the README snippet projects (tests/KumikoUI.Docs.Snippets.Maui and .Uno, 0 errors). Core 4404 + 5 new theory cases passing.

Comment on lines +192 to +195
foreach (char c in inserted)
{
if (PlaceMasked(sb, ref next, c)) placed++;
}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Editing: expose input masks, validators and formatters on Text and Numeric columns

2 participants