Skip to content

Commit 7577895

Browse files
authored
Use CosmicFontSystem in public bevy_text APIs and remove cosmic_text re-export (bevyengine#16063)
# Objective Fixes bevyengine#16006 ## Solution We currently re-export `cosmic_text`, which is seemingly motivated by the desire to use `cosmic_text::FontSystem` in `bevy_text` public APIs instead of our `CosmicFontSystem` resource wrapper type. This change makes `bevy_text` a "true" abstraction over `cosmic_text` (it in fact, was already built to be that way generally and has this one "leak"). This allows us to remove the `cosmic_text` re-export, which helps clean up the Rust Analyzer imports and generally makes this a "cleaner" API.
1 parent 3fb6cef commit 7577895

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

crates/bevy_text/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ mod text;
4545
mod text2d;
4646
mod text_access;
4747

48-
pub use cosmic_text;
49-
5048
pub use bounds::*;
5149
pub use error::*;
5250
pub use font::*;

crates/bevy_text/src/pipeline.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use alloc::sync::Arc;
22

33
use bevy_asset::{AssetId, Assets};
44
use bevy_color::Color;
5+
use bevy_derive::{Deref, DerefMut};
56
use bevy_ecs::{
67
component::Component,
78
entity::Entity,
@@ -26,7 +27,7 @@ use crate::{
2627
/// The font system is used to retrieve fonts and their information, including glyph outlines.
2728
///
2829
/// This resource is updated by the [`TextPipeline`] resource.
29-
#[derive(Resource)]
30+
#[derive(Resource, Deref, DerefMut)]
3031
pub struct CosmicFontSystem(pub cosmic_text::FontSystem);
3132

3233
impl Default for CosmicFontSystem {
@@ -422,13 +423,13 @@ impl TextMeasureInfo {
422423
&mut self,
423424
bounds: TextBounds,
424425
computed: &mut ComputedTextBlock,
425-
font_system: &mut cosmic_text::FontSystem,
426+
font_system: &mut CosmicFontSystem,
426427
) -> Vec2 {
427428
// Note that this arbitrarily adjusts the buffer layout. We assume the buffer is always 'refreshed'
428429
// whenever a canonical state is required.
429430
computed
430431
.buffer
431-
.set_size(font_system, bounds.width, bounds.height);
432+
.set_size(&mut font_system.0, bounds.width, bounds.height);
432433
buffer_dimensions(&computed.buffer)
433434
}
434435
}

crates/bevy_ui/src/layout/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ with UI components as a child of an entity without UI components, your UI layout
290290
for (camera_id, mut camera) in camera_layout_info.drain() {
291291
let inverse_target_scale_factor = camera.scale_factor.recip();
292292

293-
ui_surface.compute_camera_layout(camera_id, camera.size, text_buffers, &mut font_system.0);
293+
ui_surface.compute_camera_layout(camera_id, camera.size, text_buffers, &mut font_system);
294294

295295
for root in &camera.root_nodes {
296296
update_uinode_geometry_recursive(
@@ -1231,7 +1231,7 @@ mod tests {
12311231
params.camera_entity,
12321232
UVec2::new(800, 600),
12331233
&mut computed_text_block_query,
1234-
&mut font_system.0,
1234+
&mut font_system,
12351235
);
12361236
}
12371237

crates/bevy_ui/src/layout/ui_surface.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use bevy_math::UVec2;
1010
use bevy_utils::default;
1111

1212
use crate::{layout::convert, LayoutContext, LayoutError, Measure, MeasureArgs, Node, NodeMeasure};
13+
use bevy_text::CosmicFontSystem;
1314

1415
#[derive(Debug, Clone, PartialEq, Eq)]
1516
pub struct RootNodePair {
@@ -199,7 +200,7 @@ impl UiSurface {
199200
camera: Entity,
200201
render_target_resolution: UVec2,
201202
buffer_query: &'a mut bevy_ecs::prelude::Query<&mut bevy_text::ComputedTextBlock>,
202-
font_system: &'a mut bevy_text::cosmic_text::FontSystem,
203+
font_system: &'a mut CosmicFontSystem,
203204
) {
204205
let Some(camera_root_nodes) = self.camera_roots.get(&camera) else {
205206
return;

crates/bevy_ui/src/measurement.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use bevy_ecs::{prelude::Component, reflect::ReflectComponent};
22
use bevy_math::Vec2;
33
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
4+
use bevy_text::CosmicFontSystem;
45
use core::fmt::Formatter;
56
pub use taffy::style::AvailableSpace;
67

@@ -19,7 +20,7 @@ pub struct MeasureArgs<'a> {
1920
pub height: Option<f32>,
2021
pub available_width: AvailableSpace,
2122
pub available_height: AvailableSpace,
22-
pub font_system: &'a mut bevy_text::cosmic_text::FontSystem,
23+
pub font_system: &'a mut CosmicFontSystem,
2324
pub buffer: Option<&'a mut bevy_text::ComputedTextBlock>,
2425
}
2526

0 commit comments

Comments
 (0)