CanvasTextField.CharTints
ReferencesA resolved table of per-grapheme colours, and the CanvasTextField.Tinting delegate which reads it. Construct one per field and keep it for the lifetime of the field; call Prepare(string, Color) once per draw and assign the result to CanvasTextField.Tinting.
The point of this class is that the resolver sees the entire string at once, so it can do as much parsing as it likes - multi-character operators, symbols whose meaning depends on their context, colour names resolved to the colour they name - and it only runs again when the text or the text colour actually change. The per-grapheme callback the field ends up invoking is a bare array lookup.
Not thread safe, and doesn't need to be: it is only touched while drawing.
Constructors
CharTints
#Create a table from a resolver.
Parameters:
| resolve (Func<string, Color, Color?[]>) | Given the whole text and the colour the field draws its text in, returns one nullable colour per grapheme cluster - not per char, so that the indices line up with the field's own. A null entry, or an array shorter than the text, leaves those graphemes in the field's own colour. |
Methods
Prepare
#Re-resolve the table if the text or the colour have changed since the last call, and return the CanvasTextField.Tinting delegate which reads it. Cheap to call on every draw; the resolver only runs when something actually moved.
Parameters:
| text (string) | |
| colour (Color) |