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

Describe in documentation how to implement scrollable areas properly #1804

Open
cheery opened this issue Mar 21, 2025 · 1 comment
Open

Describe in documentation how to implement scrollable areas properly #1804

cheery opened this issue Mar 21, 2025 · 1 comment

Comments

@cheery
Copy link

cheery commented Mar 21, 2025

Hi,

I presume all the documentation for this project is here: https://www.yogalayout.dev/docs/about-yoga

It does not tell how to make a scrollable area. Could you take a little bit of time to explain how it's done?

I'm using poga bindings to apply yoga in my project. It's providing C bindings directly, eg. YGNodeStyleSetOverflow would allow me to set the scroll on.

So once I've set the overflow: scroll, how do I actually make it scroll? Eg. Set the scroll offsets and get the scroll limits so I won't let the user scroll over the content.

Thank you for writing yoga. It's been a nice library to use overall.

(I'm also interested about making very large scrollable areas that need to dynamically remove/add content based on where user is scrolling. But the basic recipe would be nice and I could then apply it on the infinite scrolling -problem)

@cheery
Copy link
Author

cheery commented Mar 21, 2025

I realised it was simpler than I expected. I was not examining the whole palette of options I actually have.

The following recipe assumes you don't have paddings in the scroll area element:

  • Measure the content area from children nodes by merging their rectangles.
  • Get the scroll area width.
  • scroll_x = clamp(scroll_x, -(content_width - scroll_area_width), 0)
  • When drawing/interacting with the content, apply your scroll offset.

When I'm doing it properly, I have less need for infinite scrolling element.

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

No branches or pull requests

1 participant