use aksr::Builder;
use crate::{Color, ColorSource, Palette, TextLoc, TextStyle, ThicknessDirection};
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ObbStyleMode {
Solid,
Dashed {
length: usize,
gap: usize,
},
Corners {
ratio_long: f32,
ratio_short: f32,
},
Rounded {
ratio: f32,
},
}
impl Default for ObbStyleMode {
fn default() -> Self {
Self::Solid
}
}
impl ObbStyleMode {
pub fn dashed() -> Self {
Self::Dashed { length: 10, gap: 5 }
}
pub fn corners() -> Self {
Self::Corners {
ratio_long: 0.2,
ratio_short: 0.2,
}
}
pub fn rounded() -> Self {
Self::Rounded { ratio: 0.1 }
}
}
#[derive(Debug, Clone, Builder, PartialEq)]
pub struct ObbStyle {
visible: bool,
text_visible: bool,
draw_fill: bool,
draw_outline: bool,
fill_color: ColorSource,
outline_color: ColorSource,
mode: ObbStyleMode,
thickness: usize,
thickness_max_ratio: f32,
thickness_direction: ThicknessDirection,
text_style: TextStyle,
palette: Vec<Color>,
}
impl Default for ObbStyle {
fn default() -> Self {
Self {
visible: true,
text_visible: true,
draw_fill: false,
draw_outline: true,
fill_color: ColorSource::Auto,
outline_color: ColorSource::Auto,
mode: ObbStyleMode::rounded(),
thickness: 3,
thickness_max_ratio: 0.3,
thickness_direction: ThicknessDirection::default(),
text_style: TextStyle::default().with_loc(TextLoc::OuterTopRight),
palette: Color::palette_base_20(),
}
}
}
impl Palette for ObbStyle {
fn palette(&self) -> &[Color] {
&self.palette
}
}
impl ObbStyle {
pub fn dashed() -> Self {
Self {
mode: ObbStyleMode::dashed(),
..Default::default()
}
}
pub fn show_confidence(mut self, show: bool) -> Self {
self.text_style = self.text_style.with_confidence(show);
self
}
pub fn show_id(mut self, show: bool) -> Self {
self.text_style = self.text_style.with_id(show);
self
}
pub fn show_name(mut self, show: bool) -> Self {
self.text_style = self.text_style.with_name(show);
self
}
}