Hi, I am in the process of learning Cocos2d-x v3.17.
I am looking for advice and suggestions on implementing a Form Field control; that is, a text label and an input field combined to look something like this, and perhaps draw box around edit to make it obvious it is a field user can “click and edit”.
Gunpowder (lb): [1.2345]
I plan to combine a Label with an EditBox in a FormField class derived from (perhaps) ProtectedNode
EDIT or perhaps Widget? Apparently I was looking at older docs with EditBox derived from ProtectedNode, but now (V3.17) is from Widget.
ASCII UML +---------------+ | ProtectedNode | Or Widget? +-------+-------+ ^ | Code to handle sizing of Label and EditBox +-----+-----+ Presents Label and EditBox side by side +-<>+ FormField +<>-+ | +-----------+ | | | | | +---+---+ +----+----+ | Label | | EditBox | +-------+ +---------+
What is difference between Node and ProtectedNode? I assume I should use protected since most UI elements like buttons seem to use protected.
Is there a better approach, or existing controls I should be using?
I modified the Win32 EditBox control to handle decimals and negatives i.e. -1.234.
Because of Windows limitation, DECIMAL input mode only allowed plain numbers 01234…9, not “.” and “-”.
- Modified input filter for WM_CHAR event to allow “.” and “-”
- Since Windows allow cut and paste with other characters, and since “12-3…4” is invalid I included GetValidText() function which would return GetText, but made as valid as possible or empty:
“-1-…23.4-5” -> “-1.2345”
- Added get/set CaretIndex(), which lets me work on text in delegate as user types, while maintaining their caret position.
- Will I have problems since I did not modify other implementations (IOS, Android)?
- The code is still a bit rough, but once I clean it up I might share it.
Is this something of interest to community, and if so, how to share?