use super::anchor::{AnchorX, AnchorY, OverlayAnchor};
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct LabelItem {
pub anchor: OverlayAnchor,
pub text: String,
pub colour: crate::colour::Colour,
pub font_size: f32,
pub font: Option<crate::overlay::font::FontHandle>,
pub background: bool,
pub background_colour: crate::colour::Colour,
pub padding: f32,
pub leader_line: bool,
pub leader_colour: crate::colour::Colour,
pub align_x: AnchorX,
pub align_y: AnchorY,
pub anchor_padding: f32,
pub position: [f32; 2],
pub opacity: f32,
pub max_width: Option<f32>,
pub border_radius: f32,
pub z_order: i32,
pub occlude: bool,
pub clip_id: Option<u32>,
}
impl Default for LabelItem {
fn default() -> Self {
Self {
anchor: OverlayAnchor::default(),
text: String::new(),
colour: [1.0, 1.0, 1.0, 1.0].into(),
font_size: 14.0,
font: None,
background: false,
background_colour: [0.0, 0.0, 0.0, 0.55].into(),
padding: 3.0,
leader_line: false,
leader_colour: [1.0, 1.0, 1.0, 0.6].into(),
align_x: AnchorX::Left,
align_y: AnchorY::Middle,
anchor_padding: 6.0,
position: [0.0, 0.0],
opacity: 1.0,
max_width: None,
border_radius: 0.0,
z_order: 0,
occlude: false,
clip_id: None,
}
}
}
impl LabelItem {
pub fn new(text: impl Into<String>) -> Self {
Self {
text: text.into(),
..Default::default()
}
}
pub fn with_anchor(mut self, anchor: OverlayAnchor) -> Self {
self.anchor = anchor;
self
}
pub fn with_world_anchor(mut self, pos: [f32; 3]) -> Self {
self.anchor = OverlayAnchor::World(pos);
self
}
pub fn with_screen_anchor(mut self, pos: [f32; 2]) -> Self {
self.anchor = OverlayAnchor::Viewport {
x: AnchorX::Left,
y: AnchorY::Top,
};
self.position = pos;
self
}
pub fn with_colour(mut self, colour: impl Into<crate::colour::Colour>) -> Self {
self.colour = colour.into();
self
}
pub fn with_font_size(mut self, font_size: f32) -> Self {
self.font_size = font_size;
self
}
pub fn with_font(mut self, font: crate::overlay::font::FontHandle) -> Self {
self.font = Some(font);
self
}
pub fn with_background(mut self, background: bool) -> Self {
self.background = background;
self
}
pub fn with_background_colour(mut self, colour: impl Into<crate::colour::Colour>) -> Self {
self.background_colour = colour.into();
self
}
pub fn with_padding(mut self, padding: f32) -> Self {
self.padding = padding;
self
}
pub fn with_leader_line(mut self, leader_line: bool) -> Self {
self.leader_line = leader_line;
self
}
pub fn with_leader_colour(mut self, colour: impl Into<crate::colour::Colour>) -> Self {
self.leader_colour = colour.into();
self
}
pub fn with_align_x(mut self, align_x: AnchorX) -> Self {
self.align_x = align_x;
self
}
pub fn with_align_y(mut self, align_y: AnchorY) -> Self {
self.align_y = align_y;
self
}
pub fn with_anchor_padding(mut self, anchor_padding: f32) -> Self {
self.anchor_padding = anchor_padding;
self
}
pub fn with_position(mut self, position: [f32; 2]) -> Self {
self.position = position;
self
}
pub fn with_opacity(mut self, opacity: f32) -> Self {
self.opacity = opacity;
self
}
pub fn with_max_width(mut self, max_width: f32) -> Self {
self.max_width = Some(max_width);
self
}
pub fn with_border_radius(mut self, border_radius: f32) -> Self {
self.border_radius = border_radius;
self
}
pub fn with_z_order(mut self, z_order: i32) -> Self {
self.z_order = z_order;
self
}
pub fn with_occlude(mut self, occlude: bool) -> Self {
self.occlude = occlude;
self
}
pub fn with_clip(mut self, clip_id: u32) -> Self {
self.clip_id = Some(clip_id);
self
}
}