Skip to content

Commit 057d1f5

Browse files
ickshonpealice-i-cecileatlv24
authored
Text2d feature-gate (#20637)
# Objective Add a "text2d" feature-gate to enable text rendering using `bevy_sprite` and `bevy_sprite_render`. ## Solution Add a "text2d" default feature, and all the necessary feature gates. Made `bevy_window` an optional depedency for `bevy_sprite` again. ## Testing The UI `text` example runs with the "text2d" feature disabled. I haven't implemented any features like this that span multiple crates before, so needs a good second look from someone. --------- Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: atlas dostal <[email protected]>
1 parent 8db5f31 commit 057d1f5

File tree

8 files changed

+37
-21
lines changed

8 files changed

+37
-21
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ bevy_sprite_render = [
281281
]
282282

283283
# Provides text functionality
284-
bevy_text = ["bevy_internal/bevy_text", "bevy_asset", "bevy_sprite"]
284+
bevy_text = ["bevy_internal/bevy_text", "bevy_asset"]
285285

286286
# A custom ECS-driven UI framework
287287
bevy_ui = [

crates/bevy_internal/Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,18 @@ bevy_ci_testing = ["bevy_dev_tools/bevy_ci_testing", "bevy_render?/ci_limits"]
199199
# Enable animation support, and glTF animation loading
200200
animation = ["bevy_animation", "bevy_mesh", "bevy_gltf?/bevy_animation"]
201201

202-
bevy_window = ["dep:bevy_window", "dep:bevy_a11y"]
203-
204202
bevy_shader = ["dep:bevy_shader"]
205203
bevy_image = ["dep:bevy_image"]
206204
bevy_sprite = ["dep:bevy_sprite", "bevy_image"]
207-
bevy_text = ["dep:bevy_text", "bevy_image", "bevy_sprite"]
205+
bevy_text = [
206+
"dep:bevy_text",
207+
"bevy_image",
208+
"bevy_sprite?/bevy_text",
209+
"bevy_sprite_render?/bevy_text",
210+
]
208211
bevy_mesh = ["dep:bevy_mesh", "bevy_image"]
209-
bevy_camera = ["dep:bevy_camera", "bevy_mesh"]
212+
bevy_window = ["dep:bevy_window", "dep:bevy_a11y", "bevy_image"]
213+
bevy_camera = ["dep:bevy_camera", "bevy_mesh", "bevy_window"]
210214
bevy_light = ["dep:bevy_light", "bevy_camera"]
211215
bevy_render = [
212216
"dep:bevy_render",
@@ -227,6 +231,7 @@ bevy_pbr = [
227231
bevy_sprite_render = [
228232
"dep:bevy_sprite_render",
229233
"bevy_sprite",
234+
"bevy_window",
230235
"bevy_core_pipeline",
231236
"bevy_gizmos?/bevy_sprite",
232237
"bevy_gizmos?/bevy_sprite_render",

crates/bevy_sprite/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ license = "MIT OR Apache-2.0"
99
keywords = ["bevy"]
1010

1111
[features]
12-
bevy_sprite_picking_backend = ["bevy_picking"]
12+
bevy_sprite_picking_backend = ["bevy_picking", "bevy_window"]
13+
bevy_text = ["dep:bevy_text", "bevy_window"]
1314

1415
[dependencies]
1516
# bevy
@@ -24,9 +25,9 @@ bevy_math = { path = "../bevy_math", version = "0.17.0-dev" }
2425
bevy_picking = { path = "../bevy_picking", version = "0.17.0-dev", optional = true }
2526
bevy_reflect = { path = "../bevy_reflect", version = "0.17.0-dev" }
2627
bevy_transform = { path = "../bevy_transform", version = "0.17.0-dev" }
27-
bevy_window = { path = "../bevy_window", version = "0.17.0-dev" }
28+
bevy_window = { path = "../bevy_window", version = "0.17.0-dev", optional = true }
2829
bevy_derive = { path = "../bevy_derive", version = "0.17.0-dev" }
29-
bevy_text = { path = "../bevy_text", version = "0.17.0-dev" }
30+
bevy_text = { path = "../bevy_text", version = "0.17.0-dev", optional = true }
3031

3132
# other
3233
radsort = "0.1"

crates/bevy_sprite/src/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extern crate alloc;
1313
#[cfg(feature = "bevy_sprite_picking_backend")]
1414
mod picking_backend;
1515
mod sprite;
16+
#[cfg(feature = "bevy_text")]
1617
mod text2d;
1718
mod texture_slice;
1819

@@ -25,28 +26,28 @@ pub mod prelude {
2526
pub use crate::picking_backend::{
2627
SpritePickingCamera, SpritePickingMode, SpritePickingPlugin, SpritePickingSettings,
2728
};
29+
#[cfg(feature = "bevy_text")]
30+
#[doc(hidden)]
31+
pub use crate::text2d::{Text2d, Text2dReader, Text2dWriter};
2832
#[doc(hidden)]
2933
pub use crate::{
3034
sprite::{Sprite, SpriteImageMode},
31-
text2d::{Text2d, Text2dReader, Text2dWriter},
3235
texture_slice::{BorderRect, SliceScaleMode, TextureSlice, TextureSlicer},
3336
ScalingMode,
3437
};
3538
}
3639

37-
use bevy_app::AnimationSystems;
3840
use bevy_asset::Assets;
3941
use bevy_camera::{
4042
primitives::{Aabb, MeshAabb},
4143
visibility::NoFrustumCulling,
44+
visibility::VisibilitySystems,
4245
};
43-
use bevy_camera::{visibility::VisibilitySystems, CameraUpdateSystems};
4446
use bevy_mesh::{Mesh, Mesh2d};
45-
use bevy_text::detect_text_needs_rerender;
46-
use bevy_text::Text2dUpdateSystems;
4747
#[cfg(feature = "bevy_sprite_picking_backend")]
4848
pub use picking_backend::*;
4949
pub use sprite::*;
50+
#[cfg(feature = "bevy_text")]
5051
pub use text2d::*;
5152
pub use texture_slice::*;
5253

@@ -79,22 +80,23 @@ impl Plugin for SpritePlugin {
7980
calculate_bounds_2d.in_set(VisibilitySystems::CalculateBounds),
8081
);
8182

83+
#[cfg(feature = "bevy_text")]
8284
app.add_systems(
8385
PostUpdate,
8486
(
85-
detect_text_needs_rerender::<Text2d>,
87+
bevy_text::detect_text_needs_rerender::<Text2d>,
8688
update_text2d_layout
8789
// Potential conflict: `Assets<Image>`
8890
// In practice, they run independently since `bevy_render::camera_update_system`
8991
// will only ever observe its own render target, and `update_text2d_layout`
9092
// will never modify a pre-existing `Image` asset.
91-
.ambiguous_with(CameraUpdateSystems)
93+
.ambiguous_with(bevy_camera::CameraUpdateSystems)
9294
.after(bevy_text::remove_dropped_font_atlas_sets),
9395
calculate_bounds_text2d.in_set(VisibilitySystems::CalculateBounds),
9496
)
9597
.chain()
96-
.in_set(Text2dUpdateSystems)
97-
.after(AnimationSystems),
98+
.in_set(bevy_text::Text2dUpdateSystems)
99+
.after(bevy_app::AnimationSystems),
98100
);
99101

100102
#[cfg(feature = "bevy_sprite_picking_backend")]

crates/bevy_sprite_render/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ keywords = ["bevy"]
1111
[features]
1212
webgl = []
1313
webgpu = []
14+
bevy_text = ["dep:bevy_text", "bevy_sprite/bevy_text"]
1415

1516
[dependencies]
1617
# bevy
@@ -25,7 +26,7 @@ bevy_mesh = { path = "../bevy_mesh", version = "0.17.0-dev" }
2526
bevy_math = { path = "../bevy_math", version = "0.17.0-dev" }
2627
bevy_shader = { path = "../bevy_shader", version = "0.17.0-dev" }
2728
bevy_sprite = { path = "../bevy_sprite", version = "0.17.0-dev" }
28-
bevy_text = { path = "../bevy_text", version = "0.17.0-dev" }
29+
bevy_text = { path = "../bevy_text", version = "0.17.0-dev", optional = true }
2930
bevy_reflect = { path = "../bevy_reflect", version = "0.17.0-dev" }
3031
bevy_render = { path = "../bevy_render", version = "0.17.0-dev" }
3132
bevy_transform = { path = "../bevy_transform", version = "0.17.0-dev" }

crates/bevy_sprite_render/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern crate alloc;
1212

1313
mod mesh2d;
1414
mod render;
15+
#[cfg(feature = "bevy_text")]
1516
mod text2d;
1617
mod texture_slice;
1718
mod tilemap_chunk;
@@ -43,6 +44,7 @@ use bevy_render::{
4344
};
4445
use bevy_sprite::Sprite;
4546

47+
#[cfg(feature = "bevy_text")]
4648
use crate::text2d::extract_text2d_sprite;
4749

4850
/// Adds support for 2D sprite rendering.
@@ -103,6 +105,7 @@ impl Plugin for SpriteRenderingPlugin {
103105
(
104106
extract_sprites.in_set(SpriteSystems::ExtractSprites),
105107
extract_sprite_events,
108+
#[cfg(feature = "bevy_text")]
106109
extract_text2d_sprite.after(SpriteSystems::ExtractSprites),
107110
),
108111
)

crates/bevy_ui/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ bevy_image = { path = "../bevy_image", version = "0.17.0-dev" }
2121
bevy_input = { path = "../bevy_input", version = "0.17.0-dev" }
2222
bevy_math = { path = "../bevy_math", version = "0.17.0-dev" }
2323
bevy_reflect = { path = "../bevy_reflect", version = "0.17.0-dev" }
24-
bevy_sprite = { path = "../bevy_sprite", version = "0.17.0-dev" }
24+
bevy_sprite = { path = "../bevy_sprite", version = "0.17.0-dev", features = [
25+
"bevy_text",
26+
] }
2527
bevy_text = { path = "../bevy_text", version = "0.17.0-dev" }
2628
bevy_picking = { path = "../bevy_picking", version = "0.17.0-dev", optional = true }
2729
bevy_transform = { path = "../bevy_transform", version = "0.17.0-dev" }

crates/bevy_ui_render/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.17.0-dev" }
2424
bevy_shader = { path = "../bevy_shader", version = "0.17.0-dev" }
2525
bevy_render = { path = "../bevy_render", version = "0.17.0-dev" }
2626
bevy_sprite = { path = "../bevy_sprite", version = "0.17.0-dev" }
27-
bevy_sprite_render = { path = "../bevy_sprite_render", version = "0.17.0-dev" }
27+
bevy_sprite_render = { path = "../bevy_sprite_render", version = "0.17.0-dev", features = [
28+
"bevy_text",
29+
] }
2830
bevy_picking = { path = "../bevy_picking", version = "0.17.0-dev", optional = true }
2931
bevy_transform = { path = "../bevy_transform", version = "0.17.0-dev" }
3032
bevy_utils = { path = "../bevy_utils", version = "0.17.0-dev" }
3133
bevy_platform = { path = "../bevy_platform", version = "0.17.0-dev", default-features = false, features = [
3234
"std",
3335
] }
3436
bevy_ui = { path = "../bevy_ui", version = "0.17.0-dev" }
35-
bevy_text = { path = "../bevy_text", version = "0.17.0-dev", default-features = false }
37+
bevy_text = { path = "../bevy_text", version = "0.17.0-dev" }
3638
bevy_window = { path = "../bevy_window", version = "0.17.0-dev", default-features = false }
3739

3840
# other

0 commit comments

Comments
 (0)