use std::hash::Hash;
use std::collections::HashMap;
use ab_glyph::{Font, PxScale};
use image::RgbImage;
use crate::to_image::drawable::leaf::info::LifelineRequiredHorizontalSpaceInDiagram;
use crate::to_image::drawable::operator::builtin_operator::*;
use crate::to_image::drawable::operator::util::*;
impl<LI : Eq + Hash + Copy + Clone> DrawableOperator<LI> {
pub fn draw(
&self,
image : &mut RgbImage,
font: &impl Font,
scale: impl Into<PxScale> + Copy,
horizontal_seps_vertical_positions : &[f32],
enclosed_lfs_reqs : &HashMap<LI,LifelineRequiredHorizontalSpaceInDiagram>,
lifelines_horizontal_positions : &HashMap<LI,f32>,
nest_padding : f32,
margin_between_items : f32) {
match &self.kind {
DrawableOperatorKind::CoRegionLike(framed_lfs) => {
if framed_lfs.is_empty() {
} else {
draw_coregion_frame(
image,
framed_lfs,
nest_padding,
horizontal_seps_vertical_positions,
lifelines_horizontal_positions,
self.frame_color,
margin_between_items
);
}
},
DrawableOperatorKind::Framed(label) => {
if let Some(leftmost_lf) = enclosed_lfs_reqs.keys()
.min_by(|l1,l2|
{
let l1_x_pos = *lifelines_horizontal_positions.get(l1).unwrap();
let l2_x_pos = *lifelines_horizontal_positions.get(l2).unwrap();
l1_x_pos.partial_cmp(&l2_x_pos).unwrap()
}
)
{
if let Some(rightmost_lf) = enclosed_lfs_reqs.keys()
.max_by(|l1,l2|
{
let l1_x_pos = *lifelines_horizontal_positions.get(l1).unwrap();
let l2_x_pos = *lifelines_horizontal_positions.get(l2).unwrap();
l1_x_pos.partial_cmp(&l2_x_pos).unwrap()
}
) {
draw_combined_fragment_frame(
image,
label,
enclosed_lfs_reqs,
nest_padding,
horizontal_seps_vertical_positions,
*leftmost_lf,
*rightmost_lf,
lifelines_horizontal_positions,
self.frame_color,
margin_between_items,
font,
scale
);
}
}
}
}
}
}