This an observation on the really useful TextEditor control code.
I have the latest source (1.19).
So I’m using the Timer class in a project of mine to update a control (it is a VU meter).
It ran fine until I put a bunch of TextEditor controls on the form.
Now I notice that the VU meter I’m updating is starting to hiccup every 1/3 of a second or so.
So while stepping into the JUCE libray code that handles callbacks and i notice that there a lot of callback objects.
All of these callback objects turn out my newly added TextEditors and all of them go off at 380 milliseconds.
So why are a bunch of TextEditors getting callbacks every 380ms?
After examining the TextEditor source I see they all have timers spinning to update their carets.
But only one TextEditor at a time needs a timer for updating a caret, the one in focus would be best!
TextEditor::moveCaret() is called when I call TextEditor::setText(),
which starts a timer that just spins even if it has no visible caret.
So in effect TextEditor::moveCaret(newCaretPos) is starting a timer upon initialization (when I set the default text of the control).
This Timer never gets deactivated if I don’t touch anything on the form.
So now I got a bunch of timers spinning when I only need the one for the one TextEditor in focus (if any).
For the time being I removed StartTimer in this moveCaret, I don’t to need it right now.
This solves my hiccup problem because I don’t have bunches of timers going off now.
void TextEditor::moveCaret (int newCaretPos)
{
if (newCaretPos < 0)
newCaretPos = 0;
else if (newCaretPos > getTotalNumChars())
newCaretPos = getTotalNumChars();
if (newCaretPos != getCaretPosition())
{
repaintCaret();
caretFlashState = true;
caretPosition = newCaretPos;
------> //textHolder->startTimer (flashSpeedIntervalMs); // my change to the JUCE library
scrollToMakeSureCursorIsVisible();
repaintCaret();
}
}
I normally wouldn’t care that some extra timers are spinning but they all hit at once and
give a noticable hiccup to my otherwise smooth looking VU control.
Any thoughts on this guys?
Or am I missing something?
I just wanted to post something about this, it could prove to be a source of frustration for someone else using the Timer.
either way this is a really cool library, it is fun to program in.