use super::*;
#[inline(always)]
fn icon_pt(ox: f32, oy: f32, tex_u: f32, px: f32, py: f32) -> Point {
Point::new(ox + px * tex_u, oy + py * tex_u)
}
#[inline(always)]
fn icon_line(display_list: &mut DisplayList, from: Point, to: Point, color: Color, width: f32) {
display_list.push(DrawCommand::Line {
from,
to,
color,
width,
});
}
pub fn draw_euv_icon(
name: EuvIconName,
bounds: Rect,
display_list: &mut DisplayList,
color: Color,
) {
let width_val: f32 = bounds.get_width().max(6.0);
let height_val: f32 = bounds.get_height().max(6.0);
let side: f32 = width_val.min(height_val);
let ox: f32 = bounds.get_x() + (width_val - side) * 0.5;
let oy: f32 = bounds.get_y() + (height_val - side) * 0.5;
let tex_u: f32 = side / 16.0;
let stroke_width: f32 = (side * 0.11).clamp(1.3, 2.2);
match name {
EuvIconName::Copy => {
display_list.push(DrawCommand::FillRoundedRect {
rect: Rect::new(ox + 5.5 * tex_u, oy + 5.5 * tex_u, 8.0 * tex_u, 8.0 * tex_u),
color: COLOR_TRANSPARENT,
radius: CornerRadius::all((1.8 * tex_u).max(1.0)),
border: Border::new(stroke_width, color),
});
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 10.5, 5.5),
icon_pt(ox, oy, tex_u, 10.5, 2.5),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 10.5, 2.5),
icon_pt(ox, oy, tex_u, 2.5, 2.5),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 2.5, 2.5),
icon_pt(ox, oy, tex_u, 2.5, 10.5),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 2.5, 10.5),
icon_pt(ox, oy, tex_u, 5.5, 10.5),
color,
stroke_width,
);
}
EuvIconName::Check => {
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 3.0, 8.4),
icon_pt(ox, oy, tex_u, 6.6, 12.0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 6.6, 12.0),
icon_pt(ox, oy, tex_u, 13.2, 4.4),
color,
stroke_width,
);
}
EuvIconName::Maximize => {
let x0: f32 = 2.0;
let y0: f32 = 2.0;
let x1: f32 = 14.0;
let y1: f32 = 14.0;
let arm: f32 = 4.2;
icon_line(
display_list,
icon_pt(ox, oy, tex_u, x0, y0 + arm),
icon_pt(ox, oy, tex_u, x0, y0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, x0, y0),
icon_pt(ox, oy, tex_u, x0 + arm, y0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, x1 - arm, y0),
icon_pt(ox, oy, tex_u, x1, y0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, x1, y0),
icon_pt(ox, oy, tex_u, x1, y0 + arm),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, x0, y1 - arm),
icon_pt(ox, oy, tex_u, x0, y1),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, x0, y1),
icon_pt(ox, oy, tex_u, x0 + arm, y1),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, x1 - arm, y1),
icon_pt(ox, oy, tex_u, x1, y1),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, x1, y1),
icon_pt(ox, oy, tex_u, x1, y1 - arm),
color,
stroke_width,
);
}
EuvIconName::Minimize => {
let arm: f32 = 3.8;
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 2.2, 6.0),
icon_pt(ox, oy, tex_u, 6.0, 6.0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 6.0, 6.0),
icon_pt(ox, oy, tex_u, 6.0, 2.2),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 10.0, 2.2),
icon_pt(ox, oy, tex_u, 10.0, 6.0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 10.0, 6.0),
icon_pt(ox, oy, tex_u, 13.8, 6.0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 2.2, 10.0),
icon_pt(ox, oy, tex_u, 6.0, 10.0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 6.0, 10.0),
icon_pt(ox, oy, tex_u, 6.0, 13.8),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 10.0, 13.8),
icon_pt(ox, oy, tex_u, 10.0, 10.0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 10.0, 10.0),
icon_pt(ox, oy, tex_u, 10.0 + arm, 10.0),
color,
stroke_width,
);
}
EuvIconName::Close => {
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 3.5, 3.5),
icon_pt(ox, oy, tex_u, 12.5, 12.5),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 12.5, 3.5),
icon_pt(ox, oy, tex_u, 3.5, 12.5),
color,
stroke_width,
);
}
EuvIconName::Search => {
let delta_val: f32 = 8.4 * tex_u;
display_list.push(DrawCommand::FillRoundedRect {
rect: Rect::new(ox + 2.4 * tex_u, oy + 2.4 * tex_u, delta_val, delta_val),
color: COLOR_TRANSPARENT,
radius: CornerRadius::all(RADIUS_PILL),
border: Border::new(stroke_width, color),
});
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 9.3, 9.3),
icon_pt(ox, oy, tex_u, 13.8, 13.8),
color,
stroke_width,
);
}
EuvIconName::Sun => {
let distance_val: f32 = 5.6 * tex_u;
display_list.push(DrawCommand::FillRoundedRect {
rect: Rect::new(
ox + 5.2 * tex_u,
oy + 5.2 * tex_u,
distance_val,
distance_val,
),
color: COLOR_TRANSPARENT,
radius: CornerRadius::all(RADIUS_PILL),
border: Border::new(stroke_width, color),
});
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 8.0, 1.6),
icon_pt(ox, oy, tex_u, 8.0, 3.3),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 8.0, 12.7),
icon_pt(ox, oy, tex_u, 8.0, 14.4),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 1.6, 8.0),
icon_pt(ox, oy, tex_u, 3.3, 8.0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 12.7, 8.0),
icon_pt(ox, oy, tex_u, 14.4, 8.0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 3.5, 3.5),
icon_pt(ox, oy, tex_u, 4.8, 4.8),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 11.2, 11.2),
icon_pt(ox, oy, tex_u, 12.5, 12.5),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 12.5, 3.5),
icon_pt(ox, oy, tex_u, 11.2, 4.8),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 4.8, 11.2),
icon_pt(ox, oy, tex_u, 3.5, 12.5),
color,
stroke_width,
);
}
EuvIconName::Moon => {
let c1x: f32 = 8.0;
let c1y: f32 = 8.4;
let r1: f32 = 5.4;
let c2x: f32 = 11.0;
let c2y: f32 = 5.6;
let r2: f32 = 4.4;
let dx: f32 = c2x - c1x;
let dy: f32 = c2y - c1y;
let dist: f32 = (dx * dx + dy * dy).sqrt();
let base_ang: f32 = dy.atan2(dx);
let a_dist: f32 = (r1 * r1 - r2 * r2 + dist * dist) / (2.0 * dist);
let alpha1: f32 = (a_dist / r1).clamp(-1.0, 1.0).acos();
let theta1_top: f32 = base_ang - alpha1;
let theta1_bot: f32 = base_ang + alpha1;
let theta1_end: f32 = theta1_top + TAU;
let p_top: Point = icon_pt(
ox,
oy,
tex_u,
c1x + r1 * theta1_top.cos(),
c1y + r1 * theta1_top.sin(),
);
let p_bot: Point = icon_pt(
ox,
oy,
tex_u,
c1x + r1 * theta1_bot.cos(),
c1y + r1 * theta1_bot.sin(),
);
let outer_steps: usize = 18;
let mut prev_outer: Point = p_bot;
for step in 1..=outer_steps {
let next_pt: Point = if step == outer_steps {
p_top
} else {
let blend_factor: f32 = (step as f32) / (outer_steps as f32);
let ang: f32 = theta1_bot + (theta1_end - theta1_bot) * blend_factor;
icon_pt(ox, oy, tex_u, c1x + r1 * ang.cos(), c1y + r1 * ang.sin())
};
icon_line(display_list, prev_outer, next_pt, color, stroke_width);
prev_outer = next_pt;
}
let p_top_x: f32 = c1x + r1 * theta1_top.cos();
let p_top_y: f32 = c1y + r1 * theta1_top.sin();
let p_bot_x: f32 = c1x + r1 * theta1_bot.cos();
let p_bot_y: f32 = c1y + r1 * theta1_bot.sin();
let mut theta2_top: f32 = (p_top_y - c2y).atan2(p_top_x - c2x);
let theta2_bot: f32 = (p_bot_y - c2y).atan2(p_bot_x - c2x);
if theta2_top < theta2_bot {
theta2_top += TAU;
}
let inner_steps: usize = 12;
let mut prev_inner: Point = p_top;
for step in 1..=inner_steps {
let next_pt: Point = if step == inner_steps {
p_bot
} else {
let time_step: f32 = (step as f32) / (inner_steps as f32);
let ang: f32 = theta2_top + (theta2_bot - theta2_top) * time_step;
icon_pt(ox, oy, tex_u, c2x + r2 * ang.cos(), c2y + r2 * ang.sin())
};
icon_line(display_list, prev_inner, next_pt, color, stroke_width);
prev_inner = next_pt;
}
}
EuvIconName::Palette => {
let depth_val: f32 = 11.6 * tex_u;
display_list.push(DrawCommand::FillRoundedRect {
rect: Rect::new(ox + 2.2 * tex_u, oy + 2.2 * tex_u, depth_val, depth_val),
color: COLOR_TRANSPARENT,
radius: CornerRadius::all(RADIUS_PILL),
border: Border::new(stroke_width, color),
});
let dot_r: f32 = (1.35 * tex_u).max(1.2);
display_list.push(DrawCommand::Circle {
center: icon_pt(ox, oy, tex_u, 6.0, 6.2),
radius: dot_r,
color,
});
display_list.push(DrawCommand::Circle {
center: icon_pt(ox, oy, tex_u, 10.0, 6.2),
radius: dot_r,
color,
});
display_list.push(DrawCommand::Circle {
center: icon_pt(ox, oy, tex_u, 8.0, 10.2),
radius: dot_r,
color,
});
}
EuvIconName::Menu => {
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 2.5, 4.2),
icon_pt(ox, oy, tex_u, 13.5, 4.2),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 2.5, 8.0),
icon_pt(ox, oy, tex_u, 13.5, 8.0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 2.5, 11.8),
icon_pt(ox, oy, tex_u, 13.5, 11.8),
color,
stroke_width,
);
}
EuvIconName::Play => {
display_list.push(DrawCommand::Triangle {
p0: icon_pt(ox, oy, tex_u, 4.6, 3.0),
p1: icon_pt(ox, oy, tex_u, 13.0, 8.0),
p2: icon_pt(ox, oy, tex_u, 4.6, 13.0),
color,
});
}
EuvIconName::Pause => {
let bar_w: f32 = (2.6 * tex_u).max(2.0);
let bar_h: f32 = 9.6 * tex_u;
display_list.push(DrawCommand::FillRoundedRect {
rect: Rect::new(ox + 4.0 * tex_u, oy + 3.2 * tex_u, bar_w, bar_h),
color,
radius: CornerRadius::all(1.0),
border: Border::default(),
});
display_list.push(DrawCommand::FillRoundedRect {
rect: Rect::new(ox + 9.4 * tex_u, oy + 3.2 * tex_u, bar_w, bar_h),
color,
radius: CornerRadius::all(1.0),
border: Border::default(),
});
}
EuvIconName::Refresh => {
let red_val: f32 = 5.0;
let start_ang: f32 = -0.45;
let sweep: f32 = -4.95;
let steps: usize = 20;
let head_pt: Point = icon_pt(
ox,
oy,
tex_u,
8.0 + red_val * start_ang.cos(),
8.0 + red_val * start_ang.sin(),
);
let mut prev: Point = head_pt;
for step in 1..=steps {
let token_val: f32 = (step as f32) / (steps as f32);
let ang: f32 = start_ang + sweep * token_val;
let cur: Point = icon_pt(
ox,
oy,
tex_u,
8.0 + red_val * ang.cos(),
8.0 + red_val * ang.sin(),
);
icon_line(display_list, prev, cur, color, stroke_width);
prev = cur;
}
icon_line(
display_list,
head_pt,
icon_pt(ox, oy, tex_u, 12.6, 2.8),
color,
stroke_width,
);
icon_line(
display_list,
head_pt,
icon_pt(ox, oy, tex_u, 9.6, 5.9),
color,
stroke_width,
);
}
EuvIconName::Trash => {
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 2.8, 4.4),
icon_pt(ox, oy, tex_u, 13.2, 4.4),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 5.8, 4.4),
icon_pt(ox, oy, tex_u, 5.8, 2.4),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 5.8, 2.4),
icon_pt(ox, oy, tex_u, 10.2, 2.4),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 10.2, 2.4),
icon_pt(ox, oy, tex_u, 10.2, 4.4),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 4.4, 4.4),
icon_pt(ox, oy, tex_u, 5.0, 13.2),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 5.0, 13.2),
icon_pt(ox, oy, tex_u, 11.0, 13.2),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 11.0, 13.2),
icon_pt(ox, oy, tex_u, 11.6, 4.4),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 6.8, 6.8),
icon_pt(ox, oy, tex_u, 6.8, 11.0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 9.2, 6.8),
icon_pt(ox, oy, tex_u, 9.2, 11.0),
color,
stroke_width,
);
}
EuvIconName::ChevronDown => {
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 3.6, 5.8),
icon_pt(ox, oy, tex_u, 8.0, 10.6),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 8.0, 10.6),
icon_pt(ox, oy, tex_u, 12.4, 5.8),
color,
stroke_width,
);
}
EuvIconName::ArrowLeft => {
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 12.6, 8.0),
icon_pt(ox, oy, tex_u, 3.6, 8.0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 7.4, 4.2),
icon_pt(ox, oy, tex_u, 3.6, 8.0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 3.6, 8.0),
icon_pt(ox, oy, tex_u, 7.4, 11.8),
color,
stroke_width,
);
}
EuvIconName::ArrowRight => {
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 3.4, 8.0),
icon_pt(ox, oy, tex_u, 12.4, 8.0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 8.6, 4.2),
icon_pt(ox, oy, tex_u, 12.4, 8.0),
color,
stroke_width,
);
icon_line(
display_list,
icon_pt(ox, oy, tex_u, 12.4, 8.0),
icon_pt(ox, oy, tex_u, 8.6, 11.8),
color,
stroke_width,
);
}
}
}