Skip to content
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

Fix cursor clipping in TextEdit inside a ScrollArea #3660

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

juancampa
Copy link
Contributor

@juancampa juancampa commented Nov 29, 2023

Before

Notice how the cursor hides after third enter.

Screenshot.2024-10-13.at.04.36.56.mp4

After

Cursor is always visible

Screenshot.2024-10-13.at.04.37.52.mp4
  • ScrollArea now checks if there's a scroll_target in begin, if there is, it saves it because it's not from its children, then restore it in end.
  • TextEdit now allocates additional space if its galley grows during the frame. This is needed so that any surrounding ScrollArea can bring the cursor to view, otherwise the cursor lays outside the the ScrollArea's content_ui.

@juancampa juancampa changed the title Ignore unrelated scroll targets Ignore unrelated scroll_target values Nov 29, 2023
@juancampa juancampa marked this pull request as ready for review November 29, 2023 03:38
@juancampa juancampa changed the title Ignore unrelated scroll_target values ScrollArea now ignores unrelated scroll_target values Nov 29, 2023
@juancampa
Copy link
Contributor Author

juancampa commented Nov 29, 2023

The reason for this fix btw is because the temporary workaround #153 (cc @Barugon) has a problem. Notice that on the fourth Enter press (00:03), the scrollarea doesn't follow the cursor. That's because the ScrollArea doesn't set up a clip rect (because contents are small enough) and the text area doesn't know it's been clipped.

Screen.Recording.2023-11-29.at.10.52.31.AM.mov

@juancampa juancampa force-pushed the ignore-unrelated-scroll-targets branch from ff4b722 to d7bd15d Compare October 13, 2024 08:41
@juancampa juancampa changed the title ScrollArea now ignores unrelated scroll_target values Fix cursor clipping in TextEdit inside a ScrollArea Oct 13, 2024
@juancampa
Copy link
Contributor Author

@emilk I just reimplemented this on top of the latest master. Also posted two videos in the description showing the issue.

@juancampa juancampa requested a review from emilk October 13, 2024 09:09
Copy link

Preview available at https://egui-pr-preview.github.io/pr/3660-ignore-unrelated-scroll-targets
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

Copy link
Collaborator

@lucasmerlin lucasmerlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Comment on lines +503 to +505
/// If there was a scroll target before the ScrollArea was added this frame, it's
/// not for us to handle so we save it and restore it after this ScrollArea is done.
saved_scroll_target: [Option<pass_state::ScrollTarget>; 2],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also FrameState::scroll_delta, I think we should do the same with that?

@lucasmerlin lucasmerlin added bug Something is broken egui labels Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken egui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ScrollArea scroll state modified by sibling textedit
3 participants