Skip to content

Commit

Permalink
Merge pull request #17 from rparrett/cosmic-text-wrap
Browse files Browse the repository at this point in the history
Add "word or glyph" linebreaking
  • Loading branch information
TotalKrill authored Jun 26, 2024
2 parents f0e18a3 + bbcff90 commit a62d6aa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/bevy_text/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl TextPipeline {
match linebreak_behavior {
BreakLineOn::WordBoundary => Wrap::Word,
BreakLineOn::AnyCharacter => Wrap::Glyph,
BreakLineOn::WordOrCharacter => Wrap::WordOrGlyph,
BreakLineOn::NoWrap => Wrap::None,
},
);
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_text/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ pub enum BreakLineOn {
/// This is closer to the behavior one might expect from text in a terminal.
/// However it may lead to words being broken up across linebreaks.
AnyCharacter,
/// Wraps at the word level, or fallback to character level if a word can’t fit on a line by itself
WordOrCharacter,
/// No soft wrapping, where text is automatically broken up into separate lines when it overflows a boundary, will ever occur.
/// Hard wrapping, where text contains an explicit linebreak such as the escape sequence `\n`, is still enabled.
NoWrap,
Expand Down
4 changes: 3 additions & 1 deletion examples/ui/text_wrap_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
for linebreak_behavior in [
BreakLineOn::AnyCharacter,
BreakLineOn::WordBoundary,
BreakLineOn::WordOrCharacter,
BreakLineOn::NoWrap,
] {
let row_id = commands
Expand Down Expand Up @@ -115,8 +116,9 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
let messages = [
format!("JustifyContent::{justification:?}"),
format!("LineBreakOn::{linebreak_behavior:?}"),
"Line 1\nLine 2\nLine 3".to_string(),
"Line 1\nLine 2".to_string(),
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas auctor, nunc ac faucibus fringilla.".to_string(),
"pneumonoultramicroscopicsilicovolcanoconiosis".to_string()
];

for (j, message) in messages.into_iter().enumerate() {
Expand Down

0 comments on commit a62d6aa

Please sign in to comment.