mod context;
mod font;
mod font_loader;
mod systems;
pub(crate) mod render;
pub use font::VelloFont;
mod plugin;
pub(crate) use plugin::VelloTextIntegrationPlugin;
use bevy::{
camera::{primitives::Aabb, visibility::VisibilityClass},
prelude::*,
ui::ContentSize,
};
#[derive(Component, Default, Clone)]
#[require(Aabb, VelloTextAnchor, Transform, Visibility, VisibilityClass)]
#[cfg_attr(feature = "picking", require(Pickable))]
#[component(on_add = bevy::camera::visibility::add_visibility_class::<VelloText2d>)]
pub struct VelloText2d {
pub value: String,
pub style: VelloTextStyle,
pub text_align: VelloTextAlign,
pub max_advance: Option<f32>,
}
#[derive(Component, Default, Clone)]
#[require(ContentSize, VelloTextAnchor, UiTransform, Visibility, VisibilityClass)]
#[component(on_add = bevy::camera::visibility::add_visibility_class::<UiVelloText>)]
pub struct UiVelloText {
pub value: String,
pub style: VelloTextStyle,
pub text_align: VelloTextAlign,
pub max_advance: Option<f32>,
}
#[derive(Clone)]
pub struct VelloTextStyle {
pub font: Handle<VelloFont>,
pub brush: vello::peniko::Brush,
pub font_size: f32,
pub line_height: f32,
pub word_spacing: f32,
pub letter_spacing: f32,
pub font_axes: VelloFontAxes,
}
impl Default for VelloTextStyle {
fn default() -> Self {
Self {
font: Default::default(),
brush: vello::peniko::Brush::Solid(vello::peniko::Color::WHITE),
font_size: 24.0,
line_height: 1.0,
word_spacing: 0.0,
letter_spacing: 0.0,
font_axes: Default::default(),
}
}
}
#[derive(Default, Clone)]
pub struct VelloFontAxes {
pub weight: Option<f32>,
pub width: Option<f32>,
pub optical_size: Option<f32>,
pub italic: bool,
pub slant: Option<f32>,
pub grade: Option<f32>,
pub thick_stroke: Option<f32>,
pub thin_stroke: Option<f32>,
pub counter_width: Option<f32>,
pub uppercase_height: Option<f32>,
pub lowercase_height: Option<f32>,
pub ascender_height: Option<f32>,
pub descender_depth: Option<f32>,
pub figure_height: Option<f32>,
}
#[derive(Component, Default, Clone, Copy, PartialEq, Eq)]
pub enum VelloTextAnchor {
BottomLeft,
Bottom,
BottomRight,
Left,
#[default]
Center,
Right,
TopLeft,
Top,
TopRight,
}
#[derive(Default, Clone, Copy, PartialEq, Eq)]
pub enum VelloTextAlign {
#[default]
Start,
End,
Left,
Middle,
Right,
Justified,
}
impl From<VelloTextAlign> for parley::Alignment {
fn from(value: VelloTextAlign) -> Self {
match value {
VelloTextAlign::Start => parley::Alignment::Start,
VelloTextAlign::End => parley::Alignment::End,
VelloTextAlign::Left => parley::Alignment::Left,
VelloTextAlign::Middle => parley::Alignment::Center,
VelloTextAlign::Right => parley::Alignment::Right,
VelloTextAlign::Justified => parley::Alignment::Justify,
}
}
}