Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
be8e768
Added style module
ickshonpe Sep 23, 2025
41ce2f1
* New component `ComputedTextStyle`.
ickshonpe Sep 23, 2025
2b8fbf9
Fix tests
ickshonpe Sep 23, 2025
35eae7f
Added `DefaultTextStyle` to test app
ickshonpe Sep 23, 2025
be52501
Remove more schedule ambiguities
ickshonpe Sep 23, 2025
c83d383
In testbed_ui explicitly use default fonts as needed.
ickshonpe Sep 23, 2025
a4c5dea
Replaced queries for `detect_text_needs_rerender`
ickshonpe Sep 23, 2025
2f7956a
Add comments
ickshonpe Sep 23, 2025
176cd1d
Updated the docs for `DefaultTextStyle` and `ComputedTextStyle`
ickshonpe Sep 24, 2025
43efbc0
Merge branch 'main' into text-style-propagation
ickshonpe Sep 26, 2025
259ac12
Split up `TextFont` into individual components.
ickshonpe Sep 27, 2025
fd076c1
Removed TextWriter, replaced individual getters from TextReader with …
ickshonpe Sep 27, 2025
a0349a5
Clean up, updated dev tools module
ickshonpe Sep 28, 2025
9162767
updated text example
ickshonpe Sep 28, 2025
5321eaf
Removed `TextAcess` module, and `TextSpan`, added new system `update_…
ickshonpe Sep 28, 2025
7f57de7
update text2d
ickshonpe Sep 28, 2025
9477cc2
updated UI text module
ickshonpe Sep 28, 2025
3307d34
updated UI accesibility module
ickshonpe Sep 28, 2025
98ee55a
updated text example
ickshonpe Sep 28, 2025
0ede8d2
Added FontSize, LineHeight, and FontSmoothing to prelude.
ickshonpe Sep 28, 2025
3a40278
Removed TextSpan import
ickshonpe Sep 28, 2025
4cb2d7f
updated many_buttons
ickshonpe Sep 28, 2025
3c33efb
updated many_text2d
ickshonpe Sep 28, 2025
a41f289
Fixed fps display in text exmaple
ickshonpe Sep 28, 2025
1af11d7
updated text_debug example
ickshonpe Sep 28, 2025
2c470e0
Search and replace TextSpan with Text
ickshonpe Sep 28, 2025
826f065
updated text2d example
ickshonpe Sep 28, 2025
a62120c
Merge branch 'main' into text-style-propagation-without-textspan
ickshonpe Sep 29, 2025
57d8c5a
Added InheritedTextStyle component
ickshonpe Sep 29, 2025
c65ae36
added update_sources system
ickshonpe Sep 29, 2025
ae07f1f
New text style propagation implementation based on `bevy_app::Propaga…
ickshonpe Sep 30, 2025
e223d58
updated bevy_dev_tools
ickshonpe Sep 30, 2025
69b79ee
Add back update_text_roots to schedule
ickshonpe Sep 30, 2025
91831b4
made roots buffer into a local in update_text_roots
ickshonpe Sep 30, 2025
9fe8ebb
Fixed accessiblity schedule
ickshonpe Sep 30, 2025
abd459c
Fix imports
ickshonpe Sep 30, 2025
2c0d22b
Added tests for style propagation
ickshonpe Sep 30, 2025
d227021
Fixed many_glyphs
ickshonpe Sep 30, 2025
2446576
Only calculate bounds for roots
ickshonpe Sep 30, 2025
4e4d76e
updated `TextPipeline` example
ickshonpe Sep 30, 2025
28eafa0
Added With<Text> filter to sync_ui_text_components
ickshonpe Sep 30, 2025
6cffaa9
Added `TextSpan` back as a marker component
ickshonpe Sep 30, 2025
b76b8c9
Removed sync_ui_text_components system
ickshonpe Sep 30, 2025
f470035
Removed unused
ickshonpe Sep 30, 2025
0119120
Give all text entities the text span component
ickshonpe Sep 30, 2025
3584216
update all `ComputedTextStyle`s when `DefaultTextStyle` is changed
ickshonpe Sep 30, 2025
65c7c4c
added `test_override_inherited_text_style` test
ickshonpe Sep 30, 2025
4e8c344
Changed `TextRoot` to wrap a `SmallVec`
ickshonpe Sep 30, 2025
d1d0d40
Rearranged `update_text_roots` to remove duplicated logic.
ickshonpe Sep 30, 2025
b46157f
Removed `TextSpan` and `detect_text_needs_rerender`.
ickshonpe Sep 30, 2025
f314eeb
Added checks for if TextRoot is changed
ickshonpe Sep 30, 2025
13dee81
Don't check TextRoot for changes in text_system
ickshonpe Sep 30, 2025
b05ff0b
Added font_count method to FontAtlasSets
ickshonpe Oct 1, 2025
118afb3
Made `FontAtlasKey` clone
ickshonpe Oct 1, 2025
7993b32
Made FontAtlasKey copy
ickshonpe Oct 1, 2025
6abaf45
Improved ont_count method
ickshonpe Oct 1, 2025
d4a845a
Added `ResolvedFont` type
ickshonpe Oct 1, 2025
2adb411
Added `ResolvedFonts` component required by `TextLayout`
ickshonpe Oct 1, 2025
1fbf2d6
update_text_roots cleanup
ickshonpe Oct 1, 2025
fbcd0fa
Removed ResolvedFonts
ickshonpe Oct 1, 2025
f74128f
Added `ComputedFontSize` component, updated during text updates.
ickshonpe Oct 1, 2025
d757c60
Required `ComputedFontSize` on `ComputedTextStyle`
ickshonpe Oct 1, 2025
2f42cdb
Added `MaxFonts` resource and `free_unused_font_atlases` system.
ickshonpe Oct 1, 2025
99c490f
Removed `Component` type constraint from InheritedTextStyle's type pa…
ickshonpe Oct 1, 2025
d9a3176
Added From impls for InheritedTextStyle
ickshonpe Oct 1, 2025
9428d85
Removed `InheritedTextStyle` From impls
ickshonpe Oct 1, 2025
7089e23
Moved `InheritableTextStyle` to `style` module
ickshonpe Oct 1, 2025
dbc9995
Fixed `load_gltf_extras` example
ickshonpe Oct 1, 2025
397fb3e
Renamed TextFont to FontFace
ickshonpe Oct 1, 2025
a12347e
updated virtual_time example
ickshonpe Oct 1, 2025
ad9ad6b
updated testbed_ui
ickshonpe Oct 1, 2025
26a2ba8
Removed uneeded 0 from range
ickshonpe Oct 1, 2025
c04786b
updated borders example
ickshonpe Oct 1, 2025
f54a636
Merge branch 'main' into text-style-propagation-auto-free
ickshonpe Oct 1, 2025
b8449bb
updated `box_shadow` example
ickshonpe Oct 1, 2025
de5246d
Removed unused import
ickshonpe Oct 1, 2025
64266cc
Updated `Scene` example
ickshonpe Oct 1, 2025
47e4266
updated more examples
ickshonpe Oct 1, 2025
692a25e
updated more examples
ickshonpe Oct 1, 2025
388f2d0
updated more examples
ickshonpe Oct 1, 2025
1833460
Added `DefaultTextStyle` and `TextStyle` to the bevy_text prelude
ickshonpe Oct 1, 2025
9bdd1a3
Updated more examples
ickshonpe Oct 1, 2025
7c6cad9
updated more examples
ickshonpe Oct 1, 2025
1328731
removed unused
ickshonpe Oct 1, 2025
0d55787
Changed `FontSize` to an enum
ickshonpe Oct 1, 2025
c8a8eb6
`FontSize` is now an enum with `Px`, `Rem`, `Vw`, `Vh`, `VMin`, and `…
ickshonpe Oct 1, 2025
f7c1d25
Updated `shader_prepass` example
ickshonpe Oct 1, 2025
e7bec30
Merge branch 'main' into bevy-text-new-features
ickshonpe Oct 1, 2025
dcc59c8
Updated more examples
ickshonpe Oct 1, 2025
1550680
Updated more examples
ickshonpe Oct 2, 2025
edb109e
Merge branch 'bevy-text-new-features' of https://github.com/ickshonpe…
ickshonpe Oct 2, 2025
8df7fc9
Fixed more examples
ickshonpe Oct 2, 2025
9df2a97
Fixed more examples
ickshonpe Oct 2, 2025
222a9a9
more doc fixes
ickshonpe Oct 2, 2025
8241e10
Merge branch 'main' into bevy-text-new-features
ickshonpe Oct 2, 2025
bb4701c
Updated more examples
ickshonpe Oct 2, 2025
392cd08
Merge branch 'bevy-text-new-features' of https://github.com/ickshonpe…
ickshonpe Oct 2, 2025
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
53 changes: 24 additions & 29 deletions crates/bevy_dev_tools/src/fps_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use bevy_color::Color;
use bevy_diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin};
use bevy_ecs::{
component::Component,
entity::Entity,
prelude::Local,
query::{With, Without},
resource::Resource,
Expand All @@ -15,12 +14,9 @@ use bevy_ecs::{
};
use bevy_picking::Pickable;
use bevy_render::storage::ShaderStorageBuffer;
use bevy_text::{Font, TextColor, TextFont, TextSpan};
use bevy_text::{Font, FontFace, FontSize, TextColor};
use bevy_time::Time;
use bevy_ui::{
widget::{Text, TextUiWriter},
FlexDirection, GlobalZIndex, Node, PositionType, Val,
};
use bevy_ui::{widget::Text, FlexDirection, GlobalZIndex, Node, PositionType, Val};
use bevy_ui_render::prelude::MaterialNode;
use core::time::Duration;

Expand Down Expand Up @@ -77,9 +73,11 @@ impl Plugin for FpsOverlayPlugin {
/// Configuration options for the FPS overlay.
#[derive(Resource, Clone)]
pub struct FpsOverlayConfig {
/// Configuration of text in the overlay.
pub text_config: TextFont,
/// Color of text in the overlay.
/// Font face used for the overlay's text.
pub font: Handle<Font>,
/// Font size used for the overlay's text.
pub font_size: f32,
/// Color used for the overlay's text.
pub text_color: Color,
/// Displays the FPS overlay if true.
pub enabled: bool,
Expand All @@ -94,11 +92,8 @@ pub struct FpsOverlayConfig {
impl Default for FpsOverlayConfig {
fn default() -> Self {
FpsOverlayConfig {
text_config: TextFont {
font: Handle::<Font>::default(),
font_size: 32.0,
..Default::default()
},
font: Handle::default(),
font_size: 32.,
text_color: Color::WHITE,
enabled: true,
refresh_interval: Duration::from_millis(100),
Expand Down Expand Up @@ -146,6 +141,9 @@ impl Default for FrameTimeGraphConfig {
#[derive(Component)]
struct FpsText;

#[derive(Component)]
struct FpsCounter;

#[derive(Component)]
struct FrameTimeGraph;

Expand All @@ -170,14 +168,15 @@ fn setup(
.with_children(|p| {
p.spawn((
Text::new("FPS: "),
overlay_config.text_config.clone(),
FontFace(overlay_config.font.clone()),
FontSize::Px(overlay_config.font_size),
TextColor(overlay_config.text_color),
FpsText,
Pickable::IGNORE,
))
.with_child((TextSpan::default(), overlay_config.text_config.clone()));
.with_child((Text::default(), FpsCounter));
let font_size = overlay_config.font_size;

let font_size = overlay_config.text_config.font_size;
p.spawn((
Node {
width: Val::Px(font_size * FRAME_TIME_GRAPH_WIDTH_SCALE),
Expand Down Expand Up @@ -211,35 +210,31 @@ fn setup(

fn update_text(
diagnostic: Res<DiagnosticsStore>,
query: Query<Entity, With<FpsText>>,
mut writer: TextUiWriter,
mut fps_counter_text_query: Query<&mut Text, With<FpsCounter>>,
time: Res<Time>,
config: Res<FpsOverlayConfig>,
mut time_since_rerender: Local<Duration>,
) {
*time_since_rerender += time.delta();
if *time_since_rerender >= config.refresh_interval {
*time_since_rerender = Duration::ZERO;
for entity in &query {
for mut fps_counter_text in &mut fps_counter_text_query {
if let Some(fps) = diagnostic.get(&FrameTimeDiagnosticsPlugin::FPS)
&& let Some(value) = fps.smoothed()
{
*writer.text(entity, 1) = format!("{value:.2}");
fps_counter_text.0 = format!("{value:.2}");
}
}
}
}

fn customize_overlay(
overlay_config: Res<FpsOverlayConfig>,
query: Query<Entity, With<FpsText>>,
mut writer: TextUiWriter,
mut query: Query<(&mut FontFace, &mut TextColor), With<FpsText>>,
) {
for entity in &query {
writer.for_each_font(entity, |mut font| {
*font = overlay_config.text_config.clone();
});
writer.for_each_color(entity, |mut color| color.0 = overlay_config.text_color);
for (mut font, mut color) in &mut query {
font.0 = overlay_config.font.clone();
color.0 = overlay_config.text_color;
}
}

Expand All @@ -256,7 +251,7 @@ fn toggle_display(

if overlay_config.frame_time_graph_config.enabled {
// Scale the frame time graph based on the font size of the overlay
let font_size = overlay_config.text_config.font_size;
let font_size = overlay_config.font_size;
graph_node.width = Val::Px(font_size * FRAME_TIME_GRAPH_WIDTH_SCALE);
graph_node.height = Val::Px(font_size * FRAME_TIME_GRAPH_HEIGHT_SCALE);

Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_dev_tools/src/picking_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bevy_picking::pointer::{Location, PointerId, PointerInput, PointerLocation,
use bevy_picking::prelude::*;
use bevy_picking::PickingSystems;
use bevy_reflect::prelude::*;
use bevy_text::prelude::*;
use bevy_text::FontSize;
use bevy_ui::prelude::*;
use core::cmp::Ordering;
use core::fmt::{Debug, Display, Formatter, Result};
Expand Down Expand Up @@ -284,7 +284,7 @@ pub fn debug_draw(
GlobalZIndex(i32::MAX),
Pickable::IGNORE,
UiTargetCamera(camera),
children![(Text::new(text.clone()), TextFont::from_font_size(12.0))],
children![(Text::new(text.clone()), FontSize::Px(12.0))],
));
}
}
Expand Down
13 changes: 5 additions & 8 deletions crates/bevy_feathers/src/font_styles.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! A framework for inheritable font styles.
use bevy_app::{Propagate, PropagateOver};
use bevy_asset::{AssetServer, Handle};
use bevy_ecs::{
component::Component,
Expand All @@ -9,15 +8,15 @@ use bevy_ecs::{
system::{Commands, Query, Res},
};
use bevy_reflect::{prelude::ReflectDefault, Reflect};
use bevy_text::{Font, TextFont};
use bevy_text::{Font, FontFace, FontSize};

use crate::{handle_or_path::HandleOrPath, theme::ThemedText};

/// A component which, when inserted on an entity, will load the given font and propagate it
/// downward to any child text entity that has the [`ThemedText`] marker.
#[derive(Component, Default, Clone, Debug, Reflect)]
#[reflect(Component, Default)]
#[require(ThemedText, PropagateOver::<TextFont>::default())]
#[require(ThemedText)]
pub struct InheritableFont {
/// The font handle or path.
pub font: HandleOrPath<Font>,
Expand Down Expand Up @@ -57,10 +56,8 @@ pub(crate) fn on_changed_font(
HandleOrPath::Path(ref p) => Some(assets.load::<Font>(p)),
}
{
commands.entity(insert.entity).insert(Propagate(TextFont {
font,
font_size: style.font_size,
..Default::default()
}));
commands
.entity(insert.entity)
.insert((FontFace(font), FontSize::Px(style.font_size)));
}
}
18 changes: 2 additions & 16 deletions crates/bevy_feathers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,17 @@
//! Please report issues, submit fixes and propose changes.
//! Thanks for stress-testing; let's build something better together.

use bevy_app::{
HierarchyPropagatePlugin, Plugin, PluginGroup, PluginGroupBuilder, PostUpdate, PropagateSet,
};
use bevy_app::{Plugin, PluginGroup, PluginGroupBuilder, PostUpdate};
use bevy_asset::embedded_asset;
use bevy_ecs::{query::With, schedule::IntoScheduleConfigs};
use bevy_input_focus::{tab_navigation::TabNavigationPlugin, InputDispatchPlugin};
use bevy_text::{TextColor, TextFont};
use bevy_ui::UiSystems;
use bevy_ui_render::UiMaterialPlugin;
use bevy_ui_widgets::UiWidgetsPlugins;

use crate::{
alpha_pattern::{AlphaPatternMaterial, AlphaPatternResource},
controls::ControlsPlugin,
cursor::{CursorIconPlugin, DefaultCursor, EntityCursor},
theme::{ThemedText, UiTheme},
theme::UiTheme,
};

mod alpha_pattern;
Expand Down Expand Up @@ -68,18 +63,9 @@ impl Plugin for FeathersPlugin {
app.add_plugins((
ControlsPlugin,
CursorIconPlugin,
HierarchyPropagatePlugin::<TextColor, With<ThemedText>>::new(PostUpdate),
HierarchyPropagatePlugin::<TextFont, With<ThemedText>>::new(PostUpdate),
UiMaterialPlugin::<AlphaPatternMaterial>::default(),
));

// This needs to run in UiSystems::Propagate so the fonts are up-to-date for `measure_text_system`
// and `detect_text_needs_rerender` in UiSystems::Content
app.configure_sets(
PostUpdate,
PropagateSet::<TextFont>::default().in_set(UiSystems::Propagate),
);

app.insert_resource(DefaultCursor(EntityCursor::System(
bevy_window::SystemCursorIcon::Default,
)));
Expand Down
7 changes: 2 additions & 5 deletions crates/bevy_feathers/src/theme.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! A framework for theming.
use bevy_app::{Propagate, PropagateOver};
use bevy_color::{palettes, Color};
use bevy_ecs::{
change_detection::DetectChanges,
Expand Down Expand Up @@ -105,7 +104,7 @@ pub struct ThemeBorderColor(pub ThemeToken);
#[component(immutable)]
#[derive(Reflect)]
#[reflect(Component, Clone)]
#[require(ThemedText, PropagateOver::<TextColor>::default())]
#[require(ThemedText)]
pub struct ThemeFontColor(pub ThemeToken);

/// A marker component that is used to indicate that the text entity wants to opt-in to using
Expand Down Expand Up @@ -167,8 +166,6 @@ pub(crate) fn on_changed_font_color(
) {
if let Ok(token) = font_color.get(insert.entity) {
let color = theme.color(&token.0);
commands
.entity(insert.entity)
.insert(Propagate(TextColor(color)));
commands.entity(insert.entity).insert(TextColor(color));
}
}
7 changes: 5 additions & 2 deletions crates/bevy_sprite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub mod prelude {
};
#[cfg(feature = "bevy_text")]
#[doc(hidden)]
pub use crate::text2d::{Text2d, Text2dReader, Text2dWriter};
pub use crate::text2d::Text2d;
#[doc(hidden)]
pub use crate::{
sprite::{Sprite, SpriteImageMode},
Expand All @@ -44,6 +44,8 @@ use bevy_camera::{
visibility::VisibilitySystems,
};
use bevy_mesh::{Mesh, Mesh2d};
#[cfg(feature = "bevy_text")]
use bevy_text::update_text_roots;
#[cfg(feature = "bevy_sprite_picking_backend")]
pub use picking_backend::*;
pub use sprite::*;
Expand Down Expand Up @@ -84,14 +86,15 @@ impl Plugin for SpritePlugin {
app.add_systems(
PostUpdate,
(
bevy_text::detect_text_needs_rerender::<Text2d>,
update_text_roots::<Text2d>,
update_text2d_layout
.after(bevy_camera::CameraUpdateSystems)
.after(bevy_text::remove_dropped_font_atlas_sets),
calculate_bounds_text2d.in_set(VisibilitySystems::CalculateBounds),
)
.chain()
.in_set(bevy_text::Text2dUpdateSystems)
.after(bevy_text::ComputedTextStyleUpdateSystems)
.after(bevy_app::AnimationSystems),
);

Expand Down
Loading
Loading