-
-
Couldn't load subscription status.
- Fork 4.2k
Add sticky ui nodes #21648
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
base: main
Are you sure you want to change the base?
Add sticky ui nodes #21648
Conversation
|
It looks like your PR has been selected for a highlight in the next release blog post, but you didn't provide a release note. Please review the instructions for writing release notes, then expand or revise the content in the release notes directory to showcase your changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add or extend an example so then we can easily test this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it should work fine.
I'm not sure about the API and implementation though, but I've been working too much on text and forgotten everything I knew about CSS. I'd like an example, like alice already asked for. It's quite limited compared to position: sticky, we should at least support bottom and right alignment I think.
Probably this is okay for an initial step though and it's simple enough that we can easily replace it completely if it's not possible to extend the implementation to support more features.
| /// Determines which axes of a node are *sticky* during scrolling. | ||
| /// | ||
| /// A **sticky** node maintains its position along the specified axes | ||
| /// instead of moving with its scrolled parent content when [`ScrollPosition`] is applied. | ||
| #[derive(Component, Debug, Clone, Default, Deref, DerefMut, Reflect)] | ||
| #[reflect(Component, Default, Clone)] | ||
| pub struct ScrollSticky(pub BVec2); | ||
|
|
||
| impl From<BVec2> for ScrollSticky { | ||
| fn from(value: BVec2) -> Self { | ||
| Self(value) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the plain BVec2 here, I'd prefer named fields or some helpers like:
impl ScrollSticky {
fn left() -> Self {
Self(BVec2::new(true, false))
}
// etc..
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to avoid implying in API that ScrollSticky has method left. What does it mean?
Sticky headers can be achieved with this feature only by combining multiple features:
ZIndex, BackgroundColor, ScrollSticky, parent with display Grid.
Users need to carefully mix multiple features to get the final behavior working. So I would like to avoid implying any specific use case in this level of API.
See example: 5ab4c9a
Objective
Add UI nodes that can be used as sticky row, column headers.
Solution
Add ui nodes that ignore parent node scroll position. This approach only allows for row, column headers that are located at the top and at the left side of the parent node. Multiple rows, columns can be used as headers.
Testing
Extended scroll example.
Prior art
Used the same approach to implement sticky elements in egui taffy (sticky)
Showcase
sticky-2025-10-24_23.22.28.mov