use aksr::Builder;
use crate::{Color, ColorSource, Palette, TextLoc, TextStyle, TextStyleMode, ThicknessDirection};
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum HbbStyleMode {
Solid,
Dashed {
length: usize,
gap: usize,
},
Corners {
ratio_long: f32,
ratio_short: f32,
},
Rounded {
ratio: f32,
},
}
impl Default for HbbStyleMode {
fn default() -> Self {
Self::Solid
}
}
impl HbbStyleMode {
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 HbbStyle {
visible: bool,
text_visible: bool,
draw_fill: bool,
draw_outline: bool,
fill_color: ColorSource,
outline_color: ColorSource,
mode: HbbStyleMode,
thickness: usize,
thickness_max_ratio: f32,
thickness_direction: ThicknessDirection,
text_style: TextStyle,
palette: Vec<Color>,
}
impl Default for HbbStyle {
fn default() -> Self {
Self {
visible: true,
text_visible: true,
draw_fill: false,
draw_outline: true,
fill_color: ColorSource::Auto,
outline_color: ColorSource::Auto,
mode: HbbStyleMode::default(),
thickness: 3,
thickness_max_ratio: 0.3,
thickness_direction: ThicknessDirection::default(),
palette: Color::palette_base_20(),
text_style: TextStyle::default()
.with_loc(TextLoc::OuterTopLeft)
.with_mode(TextStyleMode::rect(5.0))
.with_draw_fill(true)
.with_draw_outline(false),
}
}
}
impl Palette for HbbStyle {
fn palette(&self) -> &[Color] {
&self.palette
}
}
impl HbbStyle {
pub fn dashed() -> Self {
Self {
mode: HbbStyleMode::dashed(),
..Default::default()
}
}
pub fn corners() -> Self {
Self {
mode: HbbStyleMode::corners(),
..Default::default()
}
}
pub fn rounded() -> Self {
Self {
mode: HbbStyleMode::rounded(),
..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
}
}