PC games often have to create their own user interface widgets (buttons, input text boxes, etc.). Fortunately, it is relatively trivial to write your own text box from scratch given only a 2D drawing API and user input event messages:
- Current text buffer
- Dimensions of the text box
- Current cursor location and current text selection range
- Simple options, for example, is read-only, etc.
- Draw a rectangle (perhaps with an edge aspect inserted)
- Draw a line of text from the internal buffer within the dimensions
- Draw caret and / or text selection.
- Pressing a key:
- If the character key was pressed, insert that character in the buffer at the location of the symbol (often it is only added at the end)
- If you pressed the control key (for example, backspace), handle each control key appropriately
- If they are the arrow keys, move the cursor accordingly, including up / down for multi-line text boxes
- On the down key
- If the key is held down for more than 3 seconds, then repeat the pressure until the key is raised.
- Pressing a key:
So far, so simple.
But I noticed that many games and even business software that use custom widgets toolkits (thanks, WPF …) do not match the full set of functions provided by the Microsoft Windows User32 text box (formally, edit control).
Examples of this functionality that are lacking in other implementations include several key-chord commands and several types of system integration, for example:
- Ctrl + arrow keys to move the cursor to the next word limit
- Shift + arrow keys for the selection
- Ctrl + Shift + arrow keys to select the next word limit
- Built-in spell checker with red ripple underlines
- Context menu of the right button
- Ctrl + A to select all
- Automatic opening of the keyboard on the system screen when the control is focused
- "Tab" highlight the focus
But I realized that these keystrokes and shortcuts are also accepted by other standard text boxes present on other platforms, avoiding small differences (for example, in macOS is Alt + arrow keys to move between word boundaries) .
But they are not just keystrokes, you must also consider things like Unicode representation correctly, since Unicode includes rules about text design (for example, Zalgo text through Combining Marks).
So I was wondering if there is something like an "ISO standard for input text boxes" or something similar that establishes all the standard behavior of a text box so that developers of a new platform know exactly the functionality they need to implement to build something like that. other systems, without the need to consult the specific documentation of the platform that can hide undocumented functions. I notice that the documentation for the Win32 Edition Control does not include details about the user functionality (which is exactly what I'm talking about) because that's something I would read in the User's Manual, not the programming reference, especially because the Editing control functionality has been improved and expanded in future versions of Windows without the developers of the original hosting application having to do anything.