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

Support position: sticky in Overflow::Scroll nodes #771

Open
PPakalns opened this issue Dec 29, 2024 · 0 comments
Open

Support position: sticky in Overflow::Scroll nodes #771

PPakalns opened this issue Dec 29, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@PPakalns
Copy link

What problem does this solve or what need does it fill?

Improve support for sticky elements inside scrollable elements so that floating headers, columns, etc. can be added to scrollable elements. Web example: https://codepen.io/neoky/pen/mGpaKN.

What solution would you like?

Extracted from relevant discussion: #770

@nicoburns

Technically it looks like i could store "stickiness" flag as metadata and I just shouldn't apply scroll offset to element and it would be drawn correctly. If this is all that is required, could taffy add position: sticky and add a flag to layout if it should be sticky?

So I think the "correct" computation for position: sticky is a little more complicated than just not applying the scroll offset:

1. It should _conditionally_ not apply the scroll offset once the item would otherwise scroll out of view

2. The position at which the "sticky" position takes effect should be inset by the `top/left/bottom/right` styles.

3. There might need to be some kind of conflict resolution for over-constrained cases (e.g. container is smaller than sticky node or sticky node has both `bottom` and `top` set)

But, as you have demonstrated:

* (1) doesn't apply if the initial (static) position of the node is 0

* (2) doesn't apply if the sticky position is 0

* (3) doesn't apply if the container is big enough and only one property is each axis is set

I don't think it makes sense to have position: sticky as part of the main layout phase in Taffy, because position: sticky is scroll position dependent, and you don't want to have to recompute layout every time the scroll position changes. But:

* There could be a helper which computes the position given inputs (which would be called manually)

* It could potentially be incorporated as part of a (new) phase that could:
  
  * Compute `position: sticky`
  * Apply `transform`

I'd probably want to start with the former approach and move towards the latter once I/we are more sure how it needs to work.

Additional context

For simple case egui_taffy implements simple sticky boolean flag for each dimension. Using this approach top, left floating content is possible, but right, bottom floating content is not.

sticky_grid_demo.mov
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

No branches or pull requests

1 participant