Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CosmicFontSystem in public bevy_text APIs and remove cosmic_text re-export #16063

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions crates/bevy_text/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ mod text;
mod text2d;
mod text_access;

pub use cosmic_text;

pub use bounds::*;
pub use error::*;
pub use font::*;
Expand Down
7 changes: 4 additions & 3 deletions crates/bevy_text/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use alloc::sync::Arc;

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

impl Default for CosmicFontSystem {
Expand Down Expand Up @@ -422,13 +423,13 @@ impl TextMeasureInfo {
&mut self,
bounds: TextBounds,
computed: &mut ComputedTextBlock,
font_system: &mut cosmic_text::FontSystem,
font_system: &mut CosmicFontSystem,
) -> Vec2 {
// Note that this arbitrarily adjusts the buffer layout. We assume the buffer is always 'refreshed'
// whenever a canonical state is required.
computed
.buffer
.set_size(font_system, bounds.width, bounds.height);
.set_size(&mut font_system.0, bounds.width, bounds.height);
buffer_dimensions(&computed.buffer)
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ui/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ with UI components as a child of an entity without UI components, your UI layout
for (camera_id, mut camera) in camera_layout_info.drain() {
let inverse_target_scale_factor = camera.scale_factor.recip();

ui_surface.compute_camera_layout(camera_id, camera.size, text_buffers, &mut font_system.0);
ui_surface.compute_camera_layout(camera_id, camera.size, text_buffers, &mut font_system);

for root in &camera.root_nodes {
update_uinode_geometry_recursive(
Expand Down Expand Up @@ -1231,7 +1231,7 @@ mod tests {
params.camera_entity,
UVec2::new(800, 600),
&mut computed_text_block_query,
&mut font_system.0,
&mut font_system,
);
}

Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_ui/src/layout/ui_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use bevy_math::UVec2;
use bevy_utils::default;

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

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RootNodePair {
Expand Down Expand Up @@ -199,7 +200,7 @@ impl UiSurface {
camera: Entity,
render_target_resolution: UVec2,
buffer_query: &'a mut bevy_ecs::prelude::Query<&mut bevy_text::ComputedTextBlock>,
font_system: &'a mut bevy_text::cosmic_text::FontSystem,
font_system: &'a mut CosmicFontSystem,
) {
let Some(camera_root_nodes) = self.camera_roots.get(&camera) else {
return;
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_ui/src/measurement.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bevy_ecs::{prelude::Component, reflect::ReflectComponent};
use bevy_math::Vec2;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_text::CosmicFontSystem;
use core::fmt::Formatter;
pub use taffy::style::AvailableSpace;

Expand All @@ -19,7 +20,7 @@ pub struct MeasureArgs<'a> {
pub height: Option<f32>,
pub available_width: AvailableSpace,
pub available_height: AvailableSpace,
pub font_system: &'a mut bevy_text::cosmic_text::FontSystem,
pub font_system: &'a mut CosmicFontSystem,
pub buffer: Option<&'a mut bevy_text::ComputedTextBlock>,
}

Expand Down