Redrawing a label area in real-time ?

13 views
Skip to first unread message

Lucas Sanner

unread,
Dec 3, 2025, 10:12:31 AM (13 days ago) Dec 3
to fltk.general
Hi all,
I've created my own widget by extending the Fl_Group widget class:

class Document : public Fl_Group

Whenever something changes in the document, a method is called:

        void Document::hasChanged() {
            label("document has changed !");
            redraw();
        }

The problem is the label is not redrawn in real time. I have to move the main window to see the change.
Now if I modify the method as follows:

void Document::hasChanged() {
    label("document changed");
    // Mark the label area as needing redraw
    damage(FL_DAMAGE_ALL);  
    // Also explicitly mark the label for redraw
    redraw_label();
    // If this needs to be immediate, flush the window
    if (window()) {
        window()->redraw();
        Fl::check();
        Fl::flush();
    }
}

It works fine. The modified label is redrawn in real time.
However, for the sake of performance, I'd rather like to avoid redrawing the entire window each time.
Is there any way to only redraw the label area in real time ?

Thanks in advance for your help.

Matthias Melcher

unread,
Dec 3, 2025, 10:22:58 AM (13 days ago) Dec 3
to fltk.general

If the label is inside the group, simply calling redraw() will tell FLTK to redraw the group. It will redraw the entire group though. If the label is *outside* of the group, calling redraw_label() is correct and will redraw whatever the outside label covers.

Note that the label is not immediately redrawn, but the area where the label lives is marked as damaged. After some time (usually within a 50th to a 25th of a second). The idea is, that damages are collected, and the redraw only happens once per frame.

If performance is an issue, and you don't want the entire group to redraw, you can instead create a widget (Fl_Box, for example) inside the group, and mark only that for redraw. Then only the Fl_Box will be redrawn, and the rest stays as is.

Ian MacArthur

unread,
Dec 3, 2025, 10:52:39 AM (13 days ago) Dec 3
to fltk.general
On Wednesday, 3 December 2025 at 15:12:31 UTC lucas.... wrote:
Hi all,
I've created my own widget by extending the Fl_Group widget class:

class Document : public Fl_Group

Whenever something changes in the document, a method is called:

        void Document::hasChanged() {
            label("document has changed !");
            redraw();
        }

Hmm, I think (for whatever that may be worth!) that to have worked... 
Might be worth checking that the area of the label lies entirely within the bounds of the enclosing group - if the label lies outside the group, the redraw (which mainly works on teh area that it thinks the group encompasses) might miss that the label has changed.

Other than that - well, Matt's suggestions...?

Reply all
Reply to author
Forward
0 new messages