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.
This commit is contained in:
ickshonpe 2025-06-29 18:37:04 +01:00 committed by GitHub
parent e6e731017d
commit e9daac4f11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 34 additions and 28 deletions

View File

@ -60,7 +60,7 @@ pub mod prelude {
#[cfg(feature = "bevy_ui_debug")]
pub use crate::render::UiDebugOptions;
#[doc(hidden)]
pub use crate::widget::{Text, TextUiReader, TextUiWriter};
pub use crate::widget::{Text, TextShadow, TextUiReader, TextUiWriter};
#[doc(hidden)]
pub use {
crate::{
@ -184,7 +184,6 @@ impl Plugin for UiPlugin {
.register_type::<Outline>()
.register_type::<BoxShadowSamples>()
.register_type::<UiAntiAlias>()
.register_type::<TextShadow>()
.register_type::<ColorStop>()
.register_type::<AngularColorStop>()
.register_type::<UiPosition>()
@ -284,11 +283,12 @@ impl Plugin for UiPlugin {
fn build_text_interop(app: &mut App) {
use crate::widget::TextNodeFlags;
use bevy_text::TextLayoutInfo;
use widget::Text;
use widget::{Text, TextShadow};
app.register_type::<TextLayoutInfo>()
.register_type::<TextNodeFlags>()
.register_type::<Text>();
.register_type::<Text>()
.register_type::<TextShadow>();
app.add_systems(
PostUpdate,

View File

@ -9,11 +9,11 @@ mod debug_overlay;
mod gradient;
use crate::prelude::UiGlobalTransform;
use crate::widget::{ImageNode, ViewportNode};
use crate::widget::{ImageNode, TextShadow, ViewportNode};
use crate::{
BackgroundColor, BorderColor, BoxShadowSamples, CalculatedClip, ComputedNode,
ComputedNodeTarget, Outline, ResolvedBorderRadius, TextShadow, UiAntiAlias,
ComputedNodeTarget, Outline, ResolvedBorderRadius, UiAntiAlias,
};
use bevy_app::prelude::*;
use bevy_asset::{AssetEvent, AssetId, Assets};

View File

@ -2881,28 +2881,6 @@ impl ComputedNodeTarget {
}
}
/// Adds a shadow behind text
///
/// Not supported by `Text2d`
#[derive(Component, Copy, Clone, Debug, PartialEq, Reflect)]
#[reflect(Component, Default, Debug, Clone, PartialEq)]
pub struct TextShadow {
/// Shadow displacement in logical pixels
/// With a value of zero the shadow will be hidden directly behind the text
pub offset: Vec2,
/// Color of the shadow
pub color: Color,
}
impl Default for TextShadow {
fn default() -> Self {
Self {
offset: Vec2::splat(4.),
color: Color::linear_rgba(0., 0., 0., 0.75),
}
}
}
#[cfg(test)]
mod tests {
use crate::GridPlacement;

View File

@ -128,6 +128,28 @@ impl From<String> for Text {
}
}
/// Adds a shadow behind text
///
/// Not supported by `Text2d`
#[derive(Component, Copy, Clone, Debug, PartialEq, Reflect)]
#[reflect(Component, Default, Debug, Clone, PartialEq)]
pub struct TextShadow {
/// Shadow displacement in logical pixels
/// With a value of zero the shadow will be hidden directly behind the text
pub offset: Vec2,
/// Color of the shadow
pub color: Color,
}
impl Default for TextShadow {
fn default() -> Self {
Self {
offset: Vec2::splat(4.),
color: Color::linear_rgba(0., 0., 0., 0.75),
}
}
}
/// UI alias for [`TextReader`].
pub type TextUiReader<'w, 's> = TextReader<'w, 's, Text>;

View File

@ -0,0 +1,6 @@
---
title: `TextShadow` has been moved to `bevy::ui::widget::text`
pull_requests: []
---
`TextShadow` has been moved to `bevy::ui::widget::text`.