Run code when Fl_Scroll stops scrolling?

11 views
Skip to first unread message

Jakub Holý

unread,
Sep 9, 2022, 3:29:09 AM9/9/22
to fltk.general
Hello!

As described in https://stackoverflow.com/questions/73653471/fltks-fl-scroll-run-code-in-reaction-to-scrolling-happening, I want to run a function when Fl_Scroll's yposition changes or stops changing. I did not find any callback or event that would help me with that.

In the end I solved my need by checking the yposition every 100ms but want to pick your brains for alternative / better solutions. Thank you!

Best regards, Jakub Holy

Ian MacArthur

unread,
Sep 9, 2022, 3:42:18 AM9/9/22
to fltk.general
Is it not possible to subclass your own scroll and then, in the handle method, simply check for the user releasing the mouse button drag?
Or even in the subclass draw() method, note when the widget is redrawn at a different offset, perhaps (though that seems like it would be trickier, perhaps...)

Is the redrawing of the scroll a slow operation, such that it completes a significant time after the user releases the button?

That said, polling on a timeout possible is not to hideous a solution, since it does allow for the redraw of the scroll to complete asynchronously to toher events in the system and still do the Right Thing, in effect.

 

geert karman

unread,
Sep 9, 2022, 4:19:45 AM9/9/22
to fltk.general
I wanted something similar a few weeks ago (posted it with the title "Problem with redraw() / draw()"). The solution offered to me by some generous fltk fan (I don't remember huis name) was to provide a new callback function for the existing scrollbars in Fl_Scroll and intercept the yposition from there. Very neat! I attach the code with solution.

Op vrijdag 9 september 2022 om 08:29:09 UTC+1 schreef jakubh...@gmail.com:
modified_scrollb.cxx

geert karman

unread,
Sep 9, 2022, 4:23:04 AM9/9/22
to fltk.general
PS. After scrolling I check with a time out if another scroll happens, if not I execute my code. So you don't need repetitive timeouts.

Op vrijdag 9 september 2022 om 08:29:09 UTC+1 schreef jakubh...@gmail.com:
Hello!

Jakub Holý

unread,
Sep 9, 2022, 6:33:47 AM9/9/22
to fltk.general
Thank you all!


> Is it not possible to subclass your own scroll and then, in the handle method, simply check for the user releasing the mouse button drag?
I guess it is though I would also need to check for KeyUp (scrolling with keybord arrows) and MouseWheel (scrolling with mouse).

Thank you very much for the code, Karman! It looks neat though I have yet to fully understand it :) And I wonder what is the purpose of the boxes you draw in the constructor?

geert karman

unread,
Sep 9, 2022, 7:19:21 AM9/9/22
to fltk.general


Thank you very much for the code, Karman! It looks neat though I have yet to fully understand it :) And I wonder what is the purpose of the boxes you draw in the constructor?

The boxes were part of my test program, see the post that I referred to in my previous answer ("Problem with redraw() / draw()" from mid august, I already moved on and don't have it on my computer anymore). You can plug in the code for the modified scroll_B class to see what it does. The crux is that you provide your own callback function for the scrollbar. It should of course perform the task of the original callback which is just positioning the scroll:

  Fl_Scroll* s = (Fl_Scroll*)(o->parent());
  s->scroll_to(int(((Fl_Scrollbar*)o)->value()), s->yposition());

(This is the only thing it does) and then you can have it perform the tasks specific for your application. 

On a general note: I find the Fl_Scroll class not very adaptable to my needs, very un-FLTK-like. I hope the development team can come up with an "improved" version. I do greatly appreciate all the work that is going into FLTK, it is quite a feat! A great thanks to everyone!



 
Reply all
Reply to author
Forward
0 new messages