Skip to content

Commit

Permalink
Fix formatting for TextLineBreakBehaviour changes
Browse files Browse the repository at this point in the history
Ran cargo fmt
  • Loading branch information
Molot2032 committed Jan 20, 2023
1 parent 7004552 commit 8b75a65
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 23 deletions.
5 changes: 3 additions & 2 deletions crates/bevy_text/src/glyph_brush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use bevy_render::texture::Image;
use bevy_sprite::TextureAtlas;
use bevy_utils::tracing::warn;
use glyph_brush_layout::{
FontId, GlyphPositioner, Layout, SectionGeometry, SectionGlyph, SectionText, ToSectionText, BuiltInLineBreaker,
BuiltInLineBreaker, FontId, GlyphPositioner, Layout, SectionGeometry, SectionGlyph,
SectionText, ToSectionText,
};

use crate::{
error::TextError, Font, FontAtlasSet, FontAtlasWarning, GlyphAtlasInfo, TextAlignment,
TextSettings, YAxisOrientation, TextLineBreakBehaviour,
TextLineBreakBehaviour, TextSettings, YAxisOrientation,
};

pub struct GlyphBrush {
Expand Down
9 changes: 5 additions & 4 deletions crates/bevy_text/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use glyph_brush_layout::{FontId, SectionText};

use crate::{
error::TextError, glyph_brush::GlyphBrush, scale_value, Font, FontAtlasSet, FontAtlasWarning,
PositionedGlyph, TextAlignment, TextSection, TextSettings, YAxisOrientation, TextLineBreakBehaviour,
PositionedGlyph, TextAlignment, TextLineBreakBehaviour, TextSection, TextSettings,
YAxisOrientation,
};

#[derive(Default, Resource)]
Expand Down Expand Up @@ -76,9 +77,9 @@ impl TextPipeline {
})
.collect::<Result<Vec<_>, _>>()?;

let section_glyphs = self
.brush
.compute_glyphs(&sections, bounds, text_alignment, linebreak_behaviour)?;
let section_glyphs =
self.brush
.compute_glyphs(&sections, bounds, text_alignment, linebreak_behaviour)?;

if section_glyphs.is_empty() {
return Ok(TextLayoutInfo::default());
Expand Down
13 changes: 10 additions & 3 deletions crates/bevy_text/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ impl Text {
self
}

pub const fn with_linebreak_behaviour(mut self, linebreak_behaviour: TextLineBreakBehaviour) -> Self {
pub const fn with_linebreak_behaviour(
mut self,
linebreak_behaviour: TextLineBreakBehaviour,
) -> Self {
self.linebreak_behaviour = linebreak_behaviour;
self
}
Expand Down Expand Up @@ -194,8 +197,12 @@ pub enum TextLineBreakBehaviour {
impl From<TextLineBreakBehaviour> for glyph_brush_layout::BuiltInLineBreaker {
fn from(val: TextLineBreakBehaviour) -> Self {
match val {
TextLineBreakBehaviour::Unicode => glyph_brush_layout::BuiltInLineBreaker::UnicodeLineBreaker,
TextLineBreakBehaviour::AnyCharacter => glyph_brush_layout::BuiltInLineBreaker::AnyCharLineBreaker,
TextLineBreakBehaviour::Unicode => {
glyph_brush_layout::BuiltInLineBreaker::UnicodeLineBreaker
}
TextLineBreakBehaviour::AnyCharacter => {
glyph_brush_layout::BuiltInLineBreaker::AnyCharLineBreaker
}
}
}
}
7 changes: 5 additions & 2 deletions crates/bevy_ui/src/node_bundles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bevy_render::{
prelude::{Color, ComputedVisibility},
view::Visibility,
};
use bevy_text::{Text, TextAlignment, TextSection, TextStyle, TextLineBreakBehaviour};
use bevy_text::{Text, TextAlignment, TextLineBreakBehaviour, TextSection, TextStyle};
use bevy_transform::prelude::{GlobalTransform, Transform};

/// The basic UI node
Expand Down Expand Up @@ -154,7 +154,10 @@ impl TextBundle {
}

/// Returns this [`TextBundle`] with a new [`TextLineBreakBehaviour`] on [`Text`].
pub const fn with_linebreak_behaviour(mut self, linebreak_behaviour: TextLineBreakBehaviour) -> Self {
pub const fn with_linebreak_behaviour(
mut self,
linebreak_behaviour: TextLineBreakBehaviour,
) -> Self {
self.text.linebreak_behaviour = linebreak_behaviour;
self
}
Expand Down
32 changes: 20 additions & 12 deletions examples/2d/text2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
//! For an example on how to render text as part of a user interface, independent from the world
//! viewport, you may want to look at `2d/contributors.rs` or `ui/text.rs`.
use bevy::{prelude::*, text::{Text2dBounds, TextLineBreakBehaviour}};
use bevy::{
prelude::*,
text::{Text2dBounds, TextLineBreakBehaviour},
};

fn main() {
App::new()
Expand Down Expand Up @@ -63,7 +66,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
));
// Demonstrate text wrapping
let slightly_smaller_text_style = TextStyle {
font: font,
font,
font_size: 42.0,
color: Color::WHITE,
};
Expand All @@ -81,9 +84,12 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
})
.with_children(|builder| {
builder.spawn(Text2dBundle {
text: Text::from_section("this text wraps in the box\n(Unicode linebreaks)", slightly_smaller_text_style.clone())
.with_alignment(TextAlignment::Left)
.with_linebreak_behaviour(TextLineBreakBehaviour::Unicode),
text: Text::from_section(
"this text wraps in the box\n(Unicode linebreaks)",
slightly_smaller_text_style.clone(),
)
.with_alignment(TextAlignment::Left)
.with_linebreak_behaviour(TextLineBreakBehaviour::Unicode),
text_2d_bounds: Text2dBounds {
// Wrap text in the rectangle
size: box_size,
Expand All @@ -94,10 +100,9 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
});
});


let other_box_size = Vec2::new(300.0, 200.0);
let other_box_position = Vec2::new(320.0, -250.0);
commands
let other_box_size = Vec2::new(300.0, 200.0);
let other_box_position = Vec2::new(320.0, -250.0);
commands
.spawn(SpriteBundle {
sprite: Sprite {
color: Color::rgb(0.20, 0.3, 0.70),
Expand All @@ -109,9 +114,12 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
})
.with_children(|builder| {
builder.spawn(Text2dBundle {
text: Text::from_section("this text wraps in the box\n(AnyCharacter linebreaks)", slightly_smaller_text_style)
.with_alignment(TextAlignment::Left)
.with_linebreak_behaviour(TextLineBreakBehaviour::AnyCharacter),
text: Text::from_section(
"this text wraps in the box\n(AnyCharacter linebreaks)",
slightly_smaller_text_style,
)
.with_alignment(TextAlignment::Left)
.with_linebreak_behaviour(TextLineBreakBehaviour::AnyCharacter),
text_2d_bounds: Text2dBounds {
// Wrap text in the rectangle
size: other_box_size,
Expand Down

0 comments on commit 8b75a65

Please sign in to comment.