Description
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
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, becauseposition: 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.
Activity