Skip to content

Commit

Permalink
register TextLayoutInfo and TextFlags type. (bevyengine#9919)
Browse files Browse the repository at this point in the history
derive `Reflect` to `GlyphAtlasInfo`,`PositionedGlyph` and
`TextLayoutInfo`.

# Objective

- I need reflection gets all components of the `TextBundle` and
`clone_value` it

## Solution

- registry it
  • Loading branch information
ycysdf authored and Ray Redondo committed Jan 9, 2024
1 parent e4832b3 commit 7ed906e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion crates/bevy_text/src/font_atlas_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use bevy_asset::{AssetEvent, AssetId};
use bevy_asset::{Assets, Handle};
use bevy_ecs::prelude::*;
use bevy_math::Vec2;
use bevy_reflect::Reflect;
use bevy_render::texture::Image;
use bevy_sprite::TextureAtlas;
use bevy_utils::FloatOrd;
Expand Down Expand Up @@ -40,7 +41,7 @@ pub struct FontAtlasSet {
font_atlases: HashMap<FontSizeKey, Vec<FontAtlas>>,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Reflect)]
pub struct GlyphAtlasInfo {
pub texture_atlas: Handle<TextureAtlas>,
pub glyph_index: usize,
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_text/src/glyph_brush.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use ab_glyph::{Font as _, FontArc, Glyph, PxScaleFont, ScaleFont as _};
use bevy_asset::{AssetId, Assets};
use bevy_math::{Rect, Vec2};
use bevy_reflect::Reflect;
use bevy_render::texture::Image;
use bevy_sprite::TextureAtlas;
use bevy_utils::tracing::warn;
Expand Down Expand Up @@ -158,7 +159,7 @@ impl GlyphBrush {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Reflect)]
pub struct PositionedGlyph {
pub position: Vec2,
pub size: Vec2,
Expand Down
6 changes: 5 additions & 1 deletion crates/bevy_text/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ use crate::{
use ab_glyph::PxScale;
use bevy_asset::{AssetId, Assets, Handle};
use bevy_ecs::component::Component;
use bevy_ecs::prelude::ReflectComponent;
use bevy_ecs::system::Resource;
use bevy_math::Vec2;
use bevy_reflect::prelude::ReflectDefault;
use bevy_reflect::Reflect;
use bevy_render::texture::Image;
use bevy_sprite::TextureAtlas;
use bevy_utils::HashMap;
Expand All @@ -22,7 +25,8 @@ pub struct TextPipeline {
/// Render information for a corresponding [`Text`](crate::Text) component.
///
/// Contains scaled glyphs and their size. Generated via [`TextPipeline::queue_text`].
#[derive(Component, Clone, Default, Debug)]
#[derive(Component, Clone, Default, Debug, Reflect)]
#[reflect(Component, Default)]
pub struct TextLayoutInfo {
pub glyphs: Vec<PositionedGlyph>,
pub logical_size: Vec2,
Expand Down
8 changes: 8 additions & 0 deletions crates/bevy_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub mod widget;
use bevy_derive::{Deref, DerefMut};
use bevy_reflect::Reflect;
#[cfg(feature = "bevy_text")]
use bevy_text::TextLayoutInfo;
#[cfg(feature = "bevy_text")]
mod accessibility;
mod focus;
mod geometry;
Expand All @@ -40,6 +42,8 @@ pub mod prelude {
}

use crate::prelude::UiCameraConfig;
#[cfg(feature = "bevy_text")]
use crate::widget::TextFlags;
use bevy_app::prelude::*;
use bevy_asset::Assets;
use bevy_ecs::prelude::*;
Expand Down Expand Up @@ -126,6 +130,10 @@ impl Plugin for UiPlugin {
PreUpdate,
ui_focus_system.in_set(UiSystem::Focus).after(InputSystem),
);

#[cfg(feature = "bevy_text")]
app.register_type::<TextLayoutInfo>()
.register_type::<TextFlags>();
// add these systems to front because these must run before transform update systems
#[cfg(feature = "bevy_text")]
app.add_systems(
Expand Down

0 comments on commit 7ed906e

Please sign in to comment.