use iced_core::{
Pixels, Point, Rectangle, Size, Text,
alignment::Vertical,
widget::text::{Alignment, LineHeight, Shaping, Wrapping},
};
use super::Group;
use crate::style::text_marks::Appearance;
#[allow(clippy::too_many_arguments)]
pub fn draw_radial_text_marks<R: iced_core::text::Renderer<Font = iced_core::Font>>(
renderer: &mut R,
center: Point,
radius: f32,
start_angle: f32,
angle_span: f32,
text_marks: &Group,
style: &Appearance,
h_char_offset: f32,
inverse: bool,
) {
let color = style.color;
let font = style.font;
let text_size = f32::from(style.text_size);
let text_bounds_width = f32::from(style.bounds_width);
let text_bounds_height = f32::from(style.bounds_height);
let start_angle = start_angle + std::f32::consts::FRAC_PI_2;
for (position, text) in text_marks.group.iter() {
let angle = if inverse {
start_angle + position.scale_inv(angle_span)
} else {
start_angle + position.scale(angle_span)
};
let (dx, dy) = {
if !(-0.001..=0.001).contains(&angle) {
angle.sin_cos()
} else {
(0.0, -1.0)
}
};
let mut offset_x = dx * radius;
if offset_x < -0.001 {
offset_x -= (text.len() as f32 - 1.0) * h_char_offset;
} else if offset_x > 0.001 {
offset_x += (text.len() as f32 - 1.0) * h_char_offset;
}
renderer.fill_text(
Text {
content: text.clone(),
size: Pixels(text_size),
bounds: Size {
width: text_bounds_width,
height: text_bounds_height,
},
align_x: Alignment::Center,
align_y: Vertical::Center,
line_height: LineHeight::default(),
wrapping: Wrapping::default(),
shaping: Shaping::Basic,
font,
},
Point {
x: (center.x + offset_x).round(),
y: (center.y - (dy * radius)).round(),
},
color,
Rectangle {
x: 0.0,
y: 0.0,
width: 1000.0,
height: 1000.0,
},
);
}
}