-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Create a new OverflowAxis
that allows scrolling while keeping overflown items visible
#19773
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?
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. |
Why is that so bad? I think you need a clearer justification for this change. |
Using |
I'm not very convinced either. The overflow implementation isn't complete, overflow-scroll is meant to display scrollbars. Once we implement scroll bars, a "ScrollNoClip" variant doesn't make any sense. |
The scrollbars will be required by all ui nodes, not opt-in? |
Looking at the screenshots you will see that all 3 have a ui node that is 128x128, using |
Updated the example to include a border to show the UI Node |
Looking at the screenshot, it seems like you are trying to create a diegetic user interface. If that's the case, then perhaps In any case, this seems like a very niche use case, and given that there's a (admittedly more complex) workaround, I'm not sure it's worth it adding to Bevy engine. (There's another argument I could make, but this involves an etymological argument about the definition of the word "scroll" which I'd rather not get into.) On the question of scrollbars: I've been assuming that games will want to customize the look and feel of scrollbars, so I've been wary of the idea of automatically adding scrollbars to scrolling entities. |
It's not so much about about displaying the scrollbars themselves. It's about controlling the non-visual layout behaviour like:
Problems which our current scrolling implementation just completely ignores 😓 |
i don't want this discussion to devolve into a discussion about scrollbars, but i would like for scrollbars to be able to be placed anywhere, even on a separate UI hierarchy, probably using relationships, i.e. |
and back to this PR, what alternative do y'all suggest then? |
The
Using |
i just don't see it being ergonomic redoing all the math that is already done by |
There are lots of ways to construct this without using overflow, the problem with CSS is there are too many ways to do everything. Adapted from your example: // index of the element inside the white border
let x = (6 * 7 - 1) as f32;
world.spawn((
Node {
width: Val::Percent(100.),
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
..Default::default()
},
children![
Text::new("no overflow"),
(
Scrollable,
Node {
width: Val::Px(NODE_SIDES),
height: Val::Px(NODE_SIDES),
flex_direction: FlexDirection::Row,
border: UiRect::all(Val::Px(2.)),
overflow: Overflow::visible(),
..Default::default()
},
BorderColor::all(Color::WHITE),
children![(
Node {
position_type: bevy::ui::PositionType::Absolute,
width: Val::Px(NODE_SIDES),
height: Val::Px(NODE_SIDES),
..Default::default()
},
UiTransform::from_translation(Val2::new(
Val::Percent(x * -100.),
Val::Px(0.),
)),
Children::spawn(SpawnIter(
(0..(6 * 7))
.map(|id| (
Node {
position_type: bevy::ui::PositionType::Absolute,
width: Val::Px(NODE_SIDES),
height: Val::Px(NODE_SIDES),
..Default::default()
},
UiTransform::from_translation(Val2::new(
Val::Percent(id as f32 * 100.),
Val::Px(0.),
)),
ImageNode {
image: self.0.clone(),
texture_atlas: Some(TextureAtlas {
layout: self.1.clone(),
index: id,
}),
image_mode: NodeImageMode::Stretch,
..Default::default()
},
))
.collect::<Vec<_>>()
.into_iter(),
))
)]
)
],
ChildOf(entity),
)); It's a bit complicated because I hacked it together quickly but the construction can be simplified a lot with some effort. There's no need for the absolute positioning and the transforms on the |
then |
Not exactly. Bevy's relationship with CSS is complicated:
|
then is it really that bad extending the CSS-like |
Objective
If you want to create a node that has a long list of items, have all of them visible and scroll through them, you would need to fiddle with
Node::left
orNode::right
Solution
Create
OverflowAxis::ScrollNoClip
that keeps all items visible and allows you to scroll usingScrollPosition
Showcase
overflow_scroll
example