From 5fc01467b36c9b1cbd5d0998c146b2ebf1866c54 Mon Sep 17 00:00:00 2001 From: Molot2032 <117271367+Molot2032@users.noreply.github.com> Date: Fri, 20 Jan 2023 10:19:43 +1000 Subject: [PATCH] Fix CI issues for TextLineBreakBehaviour commits Ran cargo fmt and fixed redundant clone --- crates/bevy_text/src/glyph_brush.rs | 5 +++-- crates/bevy_text/src/pipeline.rs | 9 ++++---- crates/bevy_text/src/text.rs | 13 ++++++++--- crates/bevy_ui/src/node_bundles.rs | 7 ++++-- examples/2d/text2d.rs | 34 ++++++++++++++++++----------- 5 files changed, 44 insertions(+), 24 deletions(-) diff --git a/crates/bevy_text/src/glyph_brush.rs b/crates/bevy_text/src/glyph_brush.rs index 5a4fb2d3c0f38..2a00789904b38 100644 --- a/crates/bevy_text/src/glyph_brush.rs +++ b/crates/bevy_text/src/glyph_brush.rs @@ -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 { diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index b1a14d6e9f953..defe5c590750b 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -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)] @@ -76,9 +77,9 @@ impl TextPipeline { }) .collect::, _>>()?; - let section_glyphs = self - .brush - .compute_glyphs(§ions, bounds, text_alignment, linebreak_behaviour)?; + let section_glyphs = + self.brush + .compute_glyphs(§ions, bounds, text_alignment, linebreak_behaviour)?; if section_glyphs.is_empty() { return Ok(TextLayoutInfo::default()); diff --git a/crates/bevy_text/src/text.rs b/crates/bevy_text/src/text.rs index de679ad81e31a..3f5251fc20e99 100644 --- a/crates/bevy_text/src/text.rs +++ b/crates/bevy_text/src/text.rs @@ -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 } @@ -194,8 +197,12 @@ pub enum TextLineBreakBehaviour { impl From 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 + } } } } diff --git a/crates/bevy_ui/src/node_bundles.rs b/crates/bevy_ui/src/node_bundles.rs index ebe19f693684d..06048de5a7d8e 100644 --- a/crates/bevy_ui/src/node_bundles.rs +++ b/crates/bevy_ui/src/node_bundles.rs @@ -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 @@ -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 } diff --git a/examples/2d/text2d.rs b/examples/2d/text2d.rs index c043c22d6ed77..b6cb52c9571c5 100644 --- a/examples/2d/text2d.rs +++ b/examples/2d/text2d.rs @@ -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() @@ -56,14 +59,14 @@ fn setup(mut commands: Commands, asset_server: Res) { // Demonstrate changing scale commands.spawn(( Text2dBundle { - text: Text::from_section("scale", text_style.clone()).with_alignment(text_alignment), + text: Text::from_section("scale", text_style).with_alignment(text_alignment), ..default() }, AnimateScale, )); // Demonstrate text wrapping let slightly_smaller_text_style = TextStyle { - font: font, + font, font_size: 42.0, color: Color::WHITE, }; @@ -81,9 +84,12 @@ fn setup(mut commands: Commands, asset_server: Res) { }) .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, @@ -94,10 +100,9 @@ fn setup(mut commands: Commands, asset_server: Res) { }); }); - - 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), @@ -109,9 +114,12 @@ fn setup(mut commands: Commands, asset_server: Res) { }) .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,