3

I am using FLTK 1.3, displaying a single Flex column with a number of Flex rows inside a Fl_Scroll. I want to do something to rows that were outside of the visible area when they scroll into view. But I cannot figure out how to do that. There is no event emitted when the scroll position changes (as far as I can see) nor does a callback on the scroll seem to do anything.

The only solution I can think of is something like using the column's, scroll's, or window's callback to get informed of all UI events (such as move, key up, leave, ..) and use them to check whether the scoll's yposition has changed from the last time and run the code I need if it is....

But there surely must be a better way?

Thank you!!!

Jakub Holý
  • 6,019
  • 3
  • 33
  • 33
  • This is a very interesting question. You seem to be right that there's no callback of the Fl_Scroll defined. We (the FLTK devs; I'm one of them) could maybe add one that is fired when the scroll position (x and/or y) is changed. I suggest to open a thread in our official development forum (Google Group) fltk.coredev (https://groups.google.com/g/fltkcoredev) to discusse this. Another option would be to ask for help in fltk.general (https://groups.google.com/g/fltkgeneral) where user questions can be asked. Maybe someone has a better idea. – Albrecht Schlosser Sep 08 '22 at 22:19
  • A really hackish idea is to intercept the Fl_Scrollbar callbacks (one or both) but this is unsupported and you really need to know what you do. I don't recommend this! Anyway, this is an untested recipe: the Fl_Scroll widget defines two callback functions, one for each scrollbar, in its constructor. You can query these callbacks with Fl_Scrollbar::callback(), save the address(es), and then assign your own callback(s). In your own callback you first call the saved callback and then do your own stuff. Maybe this could work - but I would only try it for test code! See my previous comment. – Albrecht Schlosser Sep 08 '22 at 22:31
  • Third idea: derive your own class from Fl_Scroll, implement the handle() method, figure out whether an event goes to one of the scrollbars, and if yes, let Fl_Scroll handle it and then do your own stuff. Fl::event_inside() can tell you whether an event applies to a particular widget (scrollbar or hscrollbar). You can save the result, call Fl_Scroll::handle() *always*, then use the saved result. Or, even simpler, check the scrollbar positions after Fl_Scroll::handle() etc.. However, this will not catch resize() op's, so you will have to override resize() as well. Just some thoughts... – Albrecht Schlosser Sep 08 '22 at 22:41
  • I ended up checking the scroll's yposition every ± 100ms (the lowest granularity) - as can be seen in https://github.com/holyjak/img-mg/blob/8a188a1998bab10aff5a1e7d286b9444d426ba17/src/main.rs#L117 – Jakub Holý Sep 09 '22 at 07:09
  • Thanks a lot, Albrecht! I I will go to the fora. – Jakub Holý Sep 09 '22 at 07:12
  • @AlbrechtSchlosser interesting questions should be upvoted. :) – DejanLekic Sep 09 '22 at 07:57

0 Answers0