Repository navigation
Closed
Labels
A-UIGraphical user interfaces, styles, layouts, and widgetsGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorD-TrivialNice and easy! A great choice to get started with BevyNice and easy! A great choice to get started with Bevy
Description
Bevy version
v0.4.0
Operating system & version
macOS 10.15.7
What you did
use bevy::prelude::*;
fn main() {
App::build()
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.run();
}
fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
commands
.spawn(CameraUiBundle::default())
.spawn(TextBundle {
text: Text {
value: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas auctor, nunc ac faucibus fringilla.".to_string(),
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
style: TextStyle {
font_size: 60.0,
color: Color::WHITE,
..Default::default()
},
},
style: Style {
position_type: PositionType::Absolute,
position: Rect {
left: Val::Px(0.0),
top: Val::Px(0.0),
..Default::default()
},
max_size: Size::new(Val::Percent(50.0), Val::Percent(100.0)),
..Default::default()
},
..Default::default()
});
}What you expected to happen
I expected it to wrap the text at half the window width.
What actually happened
It doesn't wrap the text. It runs right up to the right edge of the window.
Additional information
It seems that setting a max_size with Val::Px() works, but percent doesn't.
Metadata
Metadata
Assignees
Labels
A-UIGraphical user interfaces, styles, layouts, and widgetsGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorD-TrivialNice and easy! A great choice to get started with BevyNice and easy! A great choice to get started with Bevy
Activity
working example for bevyengine/bevy#1490
djeedai commentedon Aug 30, 2022
Relevant code:
bevy/crates/bevy_ui/src/widget/text.rs
Lines 23 to 35 in fe6246d
FaneTheEternal commentedon Sep 17, 2022
Is there any news on this issue?
jkb0o commentedon Oct 24, 2022
The workaround is to split text into the words and let Taffy layout it, you can achieve even
text-aligment: justifyor any rich text effect with this approach:I've dive a bit into code (thank you @djeedai for pointing), and it looks difficult to fix this the issue without rewriting a bit of code. Taffy is pretty good at layouting (except for maybe #5834), but it is best when it knows atomic element sizes (the size of each word for example). It calculates all layout into a single pass and I believe it is better to keep it as it is. It could be an idea to rework TextBundle to let Taffy layout text as well: as far as I understend, ui already batches text nodes and there is shouldn't be lot of performance lost. Custom plugin would do the job as well.
There is a gist (https://gist.github.com/jkb0o/58ee5980ef6077b39f91979f7f19cddc), project archieve (bevy_example_text_aligment.zip) and inline code:
janos-r commentedon Oct 31, 2022
@jkb0o
Thank you! I made it work with
Because for me (not sure what default that is) everything starts from the bottom left, so without this, the text spawns from the bottom left and wraps up.
Last issue here is... how would you update the text box? Since it's not one text element I can just insert a component to. I was hoping to fill this box through a resource. I guess I can still have a global resource text... but some system has to somehow pick the entity? and every time despawn all its text children and spawn this way new ones? Never deleted and respawned children on a queried something... Thanks for any tip...
janos-r commentedon Nov 5, 2022
Ok, I finally got back to it.
This worked on my first try. And I guess in a similar way I would spawn new children (new text) for the entity (text container). I have to say tho, this feels a little weird. To make such mutating operations on
Entity, that for some reason is in the Query without either&or&mut. Just that seams to me unusual in bevy (maybe I don't undestand something properly). And also the&Childrenget despawned, even though they are just borrowed.Also in here https://bevy-cheatbook.github.io/features/parent-child.html#known-pitfalls I found that I also should call the despawning separately from the removing. I hope that is still the right way how to do it.
Please let me know if you have some clarifying comments on this.
But all in all I can work with this and thank you very much for the help :)
djeedai commentedon Dec 23, 2022
Entityis an index; think of it asu32to simplify.commands.entity(entity)returns a command queue for that particular entity, where mutation commands are recorded. Therefore there's no mutation happening to the entity inside that system. Later at the end of the stage the commands are applied by Bevy automatically and the mutations occur, somewhere else. So this is consistent with Rust rules, and is a common pattern for parallel computing (record mutations in parallel, apply them later sequentially).Remove VerticalAlign from TextAlignment (#6807)
Remove VerticalAlign from TextAlignment (bevyengine#6807)
Remove VerticalAlign from TextAlignment (bevyengine#6807)
Squashed commit of the following:
`text_system` split (#7779)
ickshonpe commentedon May 4, 2023
fixed by #7779