-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Allow scroll into view without specifying an alignment #1247
Conversation
@@ -40,7 +42,7 @@ impl Default for FrameState { | |||
used_by_panels: Rect::NAN, | |||
tooltip_rect: None, | |||
scroll_delta: Vec2::ZERO, | |||
scroll_target: [None; 2], | |||
scroll_target: [None, None], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to change this because RangeInclusive
is not Copy
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! This will be useful for #165
/// } | ||
/// }); | ||
/// # }); | ||
/// ``` | ||
pub fn scroll_to_cursor(&mut self, align: Align) { | ||
pub fn scroll_to_cursor(&mut self, align: Option<Align>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs documentation for what align=None means
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added docs!
egui/src/containers/scroll_area.rs
Outdated
@@ -493,14 +493,17 @@ impl Prepared { | |||
let clip_rect = content_ui.clip_rect(); | |||
let visible_range = min..=min + clip_rect.size()[d]; | |||
|
|||
// if the ui is too big to completely fit in the scroll view, align it to the left/top |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the best behavior?
Another alternative is to scroll the minimum amount that makes the scroll view fill with the ui-range. So for instance, if we want to scroll to an image, and that image is very big then we either:
- scroll so that the top of the image is at the top of the scroll view
- scroll so that the bottom of the image is at the bottom of the scroll view (if that is closer)
- don't scroll at all, if all we are currently seeing is the image
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I like the simmetry. I fixed it to have that behavior ☝️
Thanks! |
Problem
response.scroll_to_me
works great. However, in some cases, you only want to bring a UI into view if it's not visible, and don't do anything if it's already visible.Solution
Accept an
Option<Align>
instead of justAlign
. IfNone
is passed, the minimum scrolling necessary to fully bring the ui into view will be applied.🎥
Peek.2022-02-13.09-49.mp4