Skip to content

Commit

Permalink
Add some more docs for bevy_text.
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardmonkeys committed Sep 20, 2023
1 parent 038d113 commit 3ad819d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 11 additions & 4 deletions crates/bevy_text/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ use bevy_render::{camera::CameraUpdateSystem, ExtractSchedule, RenderApp};
use bevy_sprite::SpriteSystem;
use std::num::NonZeroUsize;

/// Adds text rendering support to an app.
///
/// When the `bevy_text` feature is enabled with the `bevy` crate, this
/// plugin is included by default in the `DefaultPlugins`.
#[derive(Default)]
pub struct TextPlugin;

/// [`TextPlugin`] settings
/// Settings used to configure the [`TextPlugin`].
#[derive(Resource)]
pub struct TextSettings {
/// Maximum number of font atlases supported in a [`FontAtlasSet`].
/// Maximum number of font atlases supported in a [`FontAtlasSet`]. When this is exceeded,
/// the [`FontAtlasWarning`] resource's `warning` field will be set to `true`.
pub max_font_atlases: NonZeroUsize,
/// Allows font size to be set dynamically exceeding the amount set in `max_font_atlases`.
/// Note each font size has to be generated which can have a strong performance impact.
Expand All @@ -56,13 +61,15 @@ impl Default for TextSettings {
}
}

/// When the number of font atlases exceeds the [`TextSettings::max_font_atlases`] setting,
/// this resource's `warning` field will be set to `true`.
#[derive(Resource, Default)]
pub struct FontAtlasWarning {
warned: bool,
}

/// Text is rendered for two different view projections, normal `Text2DBundle` is rendered with a
/// `BottomToTop` y axis, and UI is rendered with a `TopToBottom` y axis. This matters for text because
/// Text is rendered for two different view projections, a [`Text2dBundle`] is rendered with a
/// `BottomToTop` y axis, while UI is rendered with a `TopToBottom` y axis. This matters for text because
/// the glyph positioning is different in either layout.
pub enum YAxisOrientation {
TopToBottom,
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_text/src/text2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ pub struct Text2dBundle {
pub text_layout_info: TextLayoutInfo,
}

/// This system extracts the sprites from the 2D text components and adds them to the
/// "render world".
pub fn extract_text2d_sprite(
mut commands: Commands,
mut extracted_sprites: ResMut<ExtractedSprites>,
Expand Down Expand Up @@ -143,7 +145,7 @@ pub fn extract_text2d_sprite(
}

/// Updates the layout and size information whenever the text or style is changed.
/// This information is computed by the `TextPipeline` on insertion, then stored.
/// This information is computed by the [`TextPipeline`] on insertion, then stored.
///
/// ## World Resources
///
Expand Down Expand Up @@ -217,6 +219,7 @@ pub fn update_text2d_layout(
}
}

/// Scales `value` by `factor`.
pub fn scale_value(value: f32, factor: f64) -> f32 {
(value as f64 * factor) as f32
}

0 comments on commit 3ad819d

Please sign in to comment.