Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
name: Pull Request
about: Create a pull request to help us improve
title: Added a scroll handler
assignees: ''
Description:
This PR adds a scroll handler that fires every time the corresponding widget (a container) is scrolled, that is, when the position returned by
get_x_scrolland/orget_y_scrollchanges. With this handler, the "traditional" polling onget_y_scrollinitem_visible_handleris not needed anymore.Events for horizontal and vertical scroll are reported separately. If somehow the container has been scrolled in both directions (quite possible with touch screens, I think), there will be two handler calls in the frame.
The handler receives a tuple in
app_datawith the following contents:(widget, direction, pos, max_pos, is_scrolling).widget: the container being scrolled (i.e. the item to which the handler registry is bound).direction: one ofdpg.mvScrollDirection_XAxisordpg.mvScrollDirection_YAxis- can be used to filter out just one direction (I bet most users will be interested inYAxisonly). One can also usedpg.mvScrollDirection_Horizontalanddpg.mvScrollDirection_Vertical, they are just synonyms toX/YAxis.pos: current scroll position in pixels as returned byget_x_scrollorget_y_scroll. Note: this is the scroll position at the time the event occurred; since the handlers are queued and in a heavily loaded application may lag begind rendering, it's quite possible thatposwill be different from what thegetfunctions return. In this case, however, there will be more handler calls and they will eventually catch up with thegetfunctions. Technically this applies to every handler, not just the scroll handler.pos_max: max scroll position as returned byget_x_scroll_maxorget_y_scroll_max.is_scrolling: currently always False (supposed to be True while the user is holding the scrollbar). Reserved for future use - this needs support on the ImGui side, we'll see if we can add such support (technically it's trivial).Another change in this PR is the
whenargument onset_x/y_scrollfunctions. There are two ways in ImGui to specify the scroll position; one works before rendering the container in the current frame starts, and therefore applies right in the current frame; the other sets scroll position immediately after rendering and therefore only takes effect in the next frame. Depending on how contents changes, one or the other may be necessary. Of course one could always use the former method, combined withsplit_frameas necessary, but I figured it would be easier to let ImGui do this on its own. Thewhenargument lets the caller choose when to apply scroll position: right in the next frame (the former method) or with a 1-frame delay (the latter method). One can also "kill it twice" and specifymvSetScrollFlags_Both. The default is theDelayedmethod as it is more reliable; whereas theNowmethod can be used for flicker-free scrolling.Concerning Areas:
None.