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

Implement scroll_view widget #146

Closed
wants to merge 4 commits into from
Closed

Implement scroll_view widget #146

wants to merge 4 commits into from

Conversation

nicoburns
Copy link
Contributor

@nicoburns nicoburns commented Nov 17, 2023

Builds on top of #140 which should be merged first. I've now made this PR independent of #140

Notes

  • I'm not very confident about the approach of changing the origin or clipping the painting.
  • I had to change the set_origin method take &mut WidgetState rather than &mut LayoutCx. Because otherwise I couldn't call it from event and had to request layout every time the scroll position changed.

Video

Screen.Recording.2023-11-17.at.00.13.47.mov

@nicoburns nicoburns added the enhancement New feature or request label Nov 17, 2023
@nicoburns nicoburns marked this pull request as draft November 17, 2023 00:12
@nicoburns nicoburns force-pushed the scrollview branch 6 times, most recently from ac3d105 to 97bf9b1 Compare November 22, 2023 19:46
@nicoburns nicoburns changed the title WIP: Implement scroll_view widget Implement scroll_view widget Nov 22, 2023
@nicoburns nicoburns marked this pull request as ready for review November 22, 2023 19:47
@nicoburns nicoburns force-pushed the scrollview branch 12 times, most recently from a82af1e to 1627f3b Compare November 23, 2023 20:00
Copy link
Contributor

@Philipp-M Philipp-M left a comment

Choose a reason for hiding this comment

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

Thanks :)

I think it generally makes sense to add small examples showing the widgets in action (I personally like self-contained examples showing each widgets capabilities on its own, for this maybe a lorem ipsum text in a scroll view), but not a requirement.

I'm not (yet) deep in layouting and vello, so I may be wrong here: Wouldn't it make sense, instead of setting the child origin, to use the vello layer with a transform that has the offset instead?

src/view/scroll_view.rs Outdated Show resolved Hide resolved
src/view/scroll_view.rs Outdated Show resolved Hide resolved
src/view/scroll_view.rs Outdated Show resolved Hide resolved
@@ -94,7 +95,7 @@ pub struct Pod {
}

#[derive(Debug)]
pub(crate) struct WidgetState {
pub struct WidgetState {
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to allow set_origin to be called with multiple different context types. As set_origin is public, and now takes WidgetState as a parameter, WidgetState also needs to be public.


self.state.flags.insert(PodFlags::VIEW_CONTEXT_CHANGED);
}
}

/// Get the widgets size (as returned by the layout method)
pub fn get_size(&mut self) -> Size {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should omit get_ prefixes to stay consistent

Suggested change
pub fn get_size(&mut self) -> Size {
pub fn size(&mut self) -> Size {

if !cx.is_handled() {
if let RawEvent::MouseWheel(mouse) = event {
let new_offset = (self.offset + mouse.wheel_delta.y).max(0.0);
if let Event::MouseWheel(mouse) = event {
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of a UX perspective it would be interesting (not entirely sure how this is done in web, but I think it's similar as here?), how to handle nested scroll-views.

When I'm getting this right, the nested scroll view handles the scroll event, unless it doesn't scroll (e.g. is at the end).

Just thinking out loud, not suggesting anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe that ideally it would be a little more sophisticated than that, and that the inner view could handle part of a scroll event (some of the pixel delta) and leave the rest for an outer scroll view (perhaps by making the event mutable?). But you suggestion would probably cover the basics.

@nicoburns
Copy link
Contributor Author

I'm not (yet) deep in layouting and vello, so I may be wrong here: Wouldn't it make sense, instead of setting the child origin, to use the vello layer with a transform that has the offset instead?

I believe that would draw the widget in the correct place, but would not allow input to work correctly. Whereas set_origin applies to both.

@Philipp-M
Copy link
Contributor

I believe that would draw the widget in the correct place, but would not allow input to work correctly. Whereas set_origin applies to both.

That's a good point, might be interesting to research something like virtualized pointer events or similar that can be modified while traversing down the tree (in Pod::event).
Hah just saw in that moment, that was done previously like that^^, what speaks against this approach for now?

Copy link
Contributor

@richard-uk1 richard-uk1 left a comment

Choose a reason for hiding this comment

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

Awesome, thanks. Feel free to continue the discussion before merging if you think it necessary.

@DJMcNab
Copy link
Member

DJMcNab commented Mar 1, 2024

@nicoburns are you expecting to revive this branch? It seems to be on the Xilem repo and not deleted.

@nicoburns
Copy link
Contributor Author

No. #155 was merged instead

@DJMcNab
Copy link
Member

DJMcNab commented Mar 1, 2024

I'll delete the branch then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants