use std::hash::Hash;
use std::collections::HashMap;
use ab_glyph::{Font, PxScale};
use image_colored_text::text::paragraph::ColoredTextParagraph;
use crate::to_image::drawable::leaf::util::MessageExchangeLineStyle;
pub struct PrePostAmbleDrawableActionItem {
pub preamble : Option<ColoredTextParagraph>,
pub postamble : Option<ColoredTextParagraph>
}
impl PrePostAmbleDrawableActionItem {
pub fn new(
preamble : Option<ColoredTextParagraph>,
postamble : Option<ColoredTextParagraph>
) -> Self {
Self{preamble,postamble}
}
pub fn get_size_around_midline(
&self,
scale: impl Into<PxScale> + Copy,
font: &impl Font) -> (f32,f32,f32,f32)
{
let (pre_w,pre_h) = if let Some(preamble) = &self.preamble {
let (preamble_width, preamble_height, _) = preamble.paragraph_size(scale, font);
(preamble_width,preamble_height)
} else {
(0.0,0.0)
};
let (post_w,post_h) = if let Some(postamble) = &self.postamble {
let (postamble_width, postamble_height, _) = postamble.paragraph_size(scale, font);
(postamble_width,postamble_height)
} else {
(0.0,0.0)
};
(pre_w,pre_h,post_w,post_h)
}
}
pub struct CenteredDrawableActionItem {
pub content : ColoredTextParagraph,
}
impl CenteredDrawableActionItem {
pub fn new(content : ColoredTextParagraph) -> Self {
Self{content}
}
pub fn get_size_around_midline(
&self,
scale: impl Into<PxScale> + Copy,
font: &impl Font) -> (f32,f32,f32,f32)
{
let (width, height, _) = self.content.paragraph_size(scale, font);
(width,height/2.0,width,height/2.0)
}
}
pub enum TargetLifelineBroadcastDrawInstruction {
TwoParts(PrePostAmbleDrawableActionItem),
Centered(CenteredDrawableActionItem),
}
impl TargetLifelineBroadcastDrawInstruction {
pub fn get_size_around_midline(
&self,
scale: impl Into<PxScale> + Copy,
font: &impl Font) -> (f32,f32,f32,f32)
{
match &self {
TargetLifelineBroadcastDrawInstruction::TwoParts(ref act) => {
act.get_size_around_midline(scale, font)
},
TargetLifelineBroadcastDrawInstruction::Centered(ref act) => {
act.get_size_around_midline(scale, font)
}
}
}
}
pub enum DrawableBroadcastLeafPatternOrigin<LifelineIdentifier : Eq + Hash + Copy + Clone> {
Empty,
Lifeline(LifelineIdentifier,PrePostAmbleDrawableActionItem),
InputOutsideGate(ColoredTextParagraph)
}
pub struct DrawableBroadcastLeafPattern<LifelineIdentifier : Eq + Hash + Copy + Clone> {
pub message : ColoredTextParagraph,
pub line_style : MessageExchangeLineStyle,
pub origin : DrawableBroadcastLeafPatternOrigin<LifelineIdentifier>,
pub lifeline_targets : HashMap<LifelineIdentifier,TargetLifelineBroadcastDrawInstruction>,
pub output_outside_gates_targets : Vec<ColoredTextParagraph>
}
impl<LI : Eq + Hash + Copy + Clone> DrawableBroadcastLeafPattern<LI> {
pub fn new(
message : ColoredTextParagraph,
line_style : MessageExchangeLineStyle,
origin : DrawableBroadcastLeafPatternOrigin<LI>,
lifeline_targets : HashMap<LI,TargetLifelineBroadcastDrawInstruction>,
output_outside_gates_targets : Vec<ColoredTextParagraph>) -> Self {
Self { message, line_style, origin, lifeline_targets, output_outside_gates_targets }
}
}