Skip to content

Commit e9daac4

Browse files
authored
Move TextShadow to text widget module (#19579)
# Objective It's odd that `TextShadow` is accessible by importing `bevy::ui::*` but `Text` isn't. Move the `TextShadow` component to `text` widget module and move its type registration to the `build_text_interop` function.
1 parent e6e7310 commit e9daac4

File tree

5 files changed

+34
-28
lines changed

5 files changed

+34
-28
lines changed

crates/bevy_ui/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub mod prelude {
6060
#[cfg(feature = "bevy_ui_debug")]
6161
pub use crate::render::UiDebugOptions;
6262
#[doc(hidden)]
63-
pub use crate::widget::{Text, TextUiReader, TextUiWriter};
63+
pub use crate::widget::{Text, TextShadow, TextUiReader, TextUiWriter};
6464
#[doc(hidden)]
6565
pub use {
6666
crate::{
@@ -184,7 +184,6 @@ impl Plugin for UiPlugin {
184184
.register_type::<Outline>()
185185
.register_type::<BoxShadowSamples>()
186186
.register_type::<UiAntiAlias>()
187-
.register_type::<TextShadow>()
188187
.register_type::<ColorStop>()
189188
.register_type::<AngularColorStop>()
190189
.register_type::<UiPosition>()
@@ -284,11 +283,12 @@ impl Plugin for UiPlugin {
284283
fn build_text_interop(app: &mut App) {
285284
use crate::widget::TextNodeFlags;
286285
use bevy_text::TextLayoutInfo;
287-
use widget::Text;
286+
use widget::{Text, TextShadow};
288287

289288
app.register_type::<TextLayoutInfo>()
290289
.register_type::<TextNodeFlags>()
291-
.register_type::<Text>();
290+
.register_type::<Text>()
291+
.register_type::<TextShadow>();
292292

293293
app.add_systems(
294294
PostUpdate,

crates/bevy_ui/src/render/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ mod debug_overlay;
99
mod gradient;
1010

1111
use crate::prelude::UiGlobalTransform;
12-
use crate::widget::{ImageNode, ViewportNode};
12+
use crate::widget::{ImageNode, TextShadow, ViewportNode};
1313

1414
use crate::{
1515
BackgroundColor, BorderColor, BoxShadowSamples, CalculatedClip, ComputedNode,
16-
ComputedNodeTarget, Outline, ResolvedBorderRadius, TextShadow, UiAntiAlias,
16+
ComputedNodeTarget, Outline, ResolvedBorderRadius, UiAntiAlias,
1717
};
1818
use bevy_app::prelude::*;
1919
use bevy_asset::{AssetEvent, AssetId, Assets};

crates/bevy_ui/src/ui_node.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,28 +2881,6 @@ impl ComputedNodeTarget {
28812881
}
28822882
}
28832883

2884-
/// Adds a shadow behind text
2885-
///
2886-
/// Not supported by `Text2d`
2887-
#[derive(Component, Copy, Clone, Debug, PartialEq, Reflect)]
2888-
#[reflect(Component, Default, Debug, Clone, PartialEq)]
2889-
pub struct TextShadow {
2890-
/// Shadow displacement in logical pixels
2891-
/// With a value of zero the shadow will be hidden directly behind the text
2892-
pub offset: Vec2,
2893-
/// Color of the shadow
2894-
pub color: Color,
2895-
}
2896-
2897-
impl Default for TextShadow {
2898-
fn default() -> Self {
2899-
Self {
2900-
offset: Vec2::splat(4.),
2901-
color: Color::linear_rgba(0., 0., 0., 0.75),
2902-
}
2903-
}
2904-
}
2905-
29062884
#[cfg(test)]
29072885
mod tests {
29082886
use crate::GridPlacement;

crates/bevy_ui/src/widget/text.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,28 @@ impl From<String> for Text {
128128
}
129129
}
130130

131+
/// Adds a shadow behind text
132+
///
133+
/// Not supported by `Text2d`
134+
#[derive(Component, Copy, Clone, Debug, PartialEq, Reflect)]
135+
#[reflect(Component, Default, Debug, Clone, PartialEq)]
136+
pub struct TextShadow {
137+
/// Shadow displacement in logical pixels
138+
/// With a value of zero the shadow will be hidden directly behind the text
139+
pub offset: Vec2,
140+
/// Color of the shadow
141+
pub color: Color,
142+
}
143+
144+
impl Default for TextShadow {
145+
fn default() -> Self {
146+
Self {
147+
offset: Vec2::splat(4.),
148+
color: Color::linear_rgba(0., 0., 0., 0.75),
149+
}
150+
}
151+
}
152+
131153
/// UI alias for [`TextReader`].
132154
pub type TextUiReader<'w, 's> = TextReader<'w, 's, Text>;
133155

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: `TextShadow` has been moved to `bevy::ui::widget::text`
3+
pull_requests: []
4+
---
5+
6+
`TextShadow` has been moved to `bevy::ui::widget::text`.

0 commit comments

Comments
 (0)