use bevy::{prelude::*, text::LineHeight};
use super::UiText;
#[derive(Bundle)]
pub struct EmbossedText {
text: Text,
font: TextFont,
color: TextColor,
layout: TextLayout,
shadow: TextShadow,
line_height: LineHeight,
}
impl Default for EmbossedText {
fn default() -> Self {
Self {
text: Text::new(""),
font: TextFont::from_font_size(super::DEFAULT_SIZE_MEDIUM),
color: TextColor(Color::WHITE),
layout: TextLayout::new_with_justify(Justify::Center),
shadow: TextShadow {
offset: Vec2::splat(2.0),
color: Color::BLACK,
},
line_height: LineHeight::default(),
}
}
}
impl UiText for EmbossedText {
fn color(mut self, color: TextColor) -> Self {
self.color = color;
self
}
fn font(mut self, font: &Handle<Font>) -> Self {
self.font.font = font.clone();
self
}
fn size(mut self, size: f32) -> Self {
self.font.font_size = size;
self
}
fn text(mut self, text: Text) -> Self {
self.text = text;
self
}
fn line_height(mut self, line_height: LineHeight) -> Self {
self.line_height = line_height;
self
}
fn justify(mut self, justify: Justify) -> Self {
self.layout.justify = justify;
self
}
fn line_break(mut self, line_break: LineBreak) -> Self {
self.layout.linebreak = line_break;
self
}
}
impl EmbossedText {
pub fn small(value: &str, font: &Handle<Font>) -> Self {
<Self as UiText>::small(value, font).relief(1.0)
}
pub fn medium(value: &str, font: &Handle<Font>) -> Self {
<Self as UiText>::medium(value, font).relief(2.0)
}
pub fn large(value: &str, font: &Handle<Font>) -> Self {
<Self as UiText>::large(value, font).relief(5.0)
}
pub fn extra_large(value: &str, font: &Handle<Font>) -> Self {
<Self as UiText>::extra_large(value, font).relief(6.0)
}
pub fn shadow(mut self, color: Color) -> Self {
self.shadow.color = color;
self
}
fn relief(mut self, relief: f32) -> Self {
self.shadow.offset = Vec2::splat(relief);
self
}
}