-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Manually control ScrollArea scroll offset #74
Comments
ScrollArea
scroll offset
There are two scenarios we want to cover: A) Setting the offset before layout A) Setting the offset before layoutThis could be solved with extending the
where The downside with this is that one needs to anticipate how many points we want the offset to be ahead of time, which only works for trivial content (e.g. rows of single-line labels). This should be fairly easy to implement B) Setting the offset during or after layoutDear ImGui has a very useful I think this could be accomplished by something like this: egui::ScrollArea::auto_sized().show(ui, |ui| {
for (i, line) in my_text.iter().enumerate() {
if i == selected_line {
ui.scroll_to_here();
}
ui.label(line);
}
});
Other considerationsSometimes one want to center on a particular line, sometimes make it the top of the layout. For centering one also needs to take into account the size of the widget one is centering on, so that we center on the center of the widget. Perhaps: let response = ui.label(line);
if i == selected_line {
response.scroll_to_me(Align::CENTER);
} Having it part of |
I'm working on an implementation for this, got the basics from B) done, and works pretty well, this design is pretty good, gets the job done, in my case, with a few lines. Just don't know the best way to achieve:
Currently you need to call |
Why? Do you have a branch I can look at? |
I have the currently scenario:
Peek.2020-12-21.00-46.mp4
that i want to control the scroll when moving the selected line keeping the focus at the active line.
This is what I got trying to achieve this:
Currently the offset state that controls the scroll position is not public. I tried creating an simple public fn to set the offset manually, but since we can't get the Id of the
ScrollArea.source_id
, we can't change the state. We only have access to the Id of the child_ui (Prepared.content_ui
) inside theshow()
function.Also since the Prepared state is passed from the
begin()
to theend()
, we can't change it inside theadd_contents()
. We would need to get the state from the memory again in theend()
if we changed it in theadd_contents()
.Maybe the way out is to pass the Id used to save the state in the return of the show:
ScrollArea.show() -> ScrollResponse<R>
similar to the CollapsingResponse.There is probably better solution for this
The text was updated successfully, but these errors were encountered: