use super::*;
#[inline(always)]
fn icon_pt(ox: f32, oy: f32, u: f32, px: f32, py: f32) -> Point {
Point::new(ox + px * u, oy + py * u)
}
#[inline(always)]
fn icon_line(dl: &mut DisplayList, from: Point, to: Point, color: Color, width: f32) {
dl.push(DrawCommand::Line {
from,
to,
color,
width,
});
}
pub fn draw_euv_icon(name: EuvIconName, bounds: Rect, dl: &mut DisplayList, color: Color) {
let w: f32 = bounds.get_width().max(6.0);
let h: f32 = bounds.get_height().max(6.0);
let side: f32 = w.min(h);
let ox: f32 = bounds.get_x() + (w - side) * 0.5;
let oy: f32 = bounds.get_y() + (h - side) * 0.5;
let u: f32 = side / 16.0;
let sw: f32 = (side * 0.11).clamp(1.3, 2.2);
match name {
EuvIconName::Copy => {
dl.push(DrawCommand::FillRoundedRect {
rect: Rect::new(ox + 5.5 * u, oy + 5.5 * u, 8.0 * u, 8.0 * u),
color: COLOR_TRANSPARENT,
radius: CornerRadius::all((1.8 * u).max(1.0)),
border: Border::new(sw, color),
});
icon_line(
dl,
icon_pt(ox, oy, u, 10.5, 5.5),
icon_pt(ox, oy, u, 10.5, 2.5),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 10.5, 2.5),
icon_pt(ox, oy, u, 2.5, 2.5),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 2.5, 2.5),
icon_pt(ox, oy, u, 2.5, 10.5),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 2.5, 10.5),
icon_pt(ox, oy, u, 5.5, 10.5),
color,
sw,
);
}
EuvIconName::Check => {
icon_line(
dl,
icon_pt(ox, oy, u, 3.0, 8.4),
icon_pt(ox, oy, u, 6.6, 12.0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 6.6, 12.0),
icon_pt(ox, oy, u, 13.2, 4.4),
color,
sw,
);
}
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(
dl,
icon_pt(ox, oy, u, x0, y0 + arm),
icon_pt(ox, oy, u, x0, y0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, x0, y0),
icon_pt(ox, oy, u, x0 + arm, y0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, x1 - arm, y0),
icon_pt(ox, oy, u, x1, y0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, x1, y0),
icon_pt(ox, oy, u, x1, y0 + arm),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, x0, y1 - arm),
icon_pt(ox, oy, u, x0, y1),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, x0, y1),
icon_pt(ox, oy, u, x0 + arm, y1),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, x1 - arm, y1),
icon_pt(ox, oy, u, x1, y1),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, x1, y1),
icon_pt(ox, oy, u, x1, y1 - arm),
color,
sw,
);
}
EuvIconName::Minimize => {
let arm: f32 = 3.8;
icon_line(
dl,
icon_pt(ox, oy, u, 2.2, 6.0),
icon_pt(ox, oy, u, 6.0, 6.0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 6.0, 6.0),
icon_pt(ox, oy, u, 6.0, 2.2),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 10.0, 2.2),
icon_pt(ox, oy, u, 10.0, 6.0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 10.0, 6.0),
icon_pt(ox, oy, u, 13.8, 6.0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 2.2, 10.0),
icon_pt(ox, oy, u, 6.0, 10.0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 6.0, 10.0),
icon_pt(ox, oy, u, 6.0, 13.8),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 10.0, 13.8),
icon_pt(ox, oy, u, 10.0, 10.0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 10.0, 10.0),
icon_pt(ox, oy, u, 10.0 + arm, 10.0),
color,
sw,
);
}
EuvIconName::Close => {
icon_line(
dl,
icon_pt(ox, oy, u, 3.5, 3.5),
icon_pt(ox, oy, u, 12.5, 12.5),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 12.5, 3.5),
icon_pt(ox, oy, u, 3.5, 12.5),
color,
sw,
);
}
EuvIconName::Search => {
let d: f32 = 8.4 * u;
dl.push(DrawCommand::FillRoundedRect {
rect: Rect::new(ox + 2.4 * u, oy + 2.4 * u, d, d),
color: COLOR_TRANSPARENT,
radius: CornerRadius::all(RADIUS_PILL),
border: Border::new(sw, color),
});
icon_line(
dl,
icon_pt(ox, oy, u, 9.3, 9.3),
icon_pt(ox, oy, u, 13.8, 13.8),
color,
sw,
);
}
EuvIconName::Sun => {
let d: f32 = 5.6 * u;
dl.push(DrawCommand::FillRoundedRect {
rect: Rect::new(ox + 5.2 * u, oy + 5.2 * u, d, d),
color: COLOR_TRANSPARENT,
radius: CornerRadius::all(RADIUS_PILL),
border: Border::new(sw, color),
});
icon_line(
dl,
icon_pt(ox, oy, u, 8.0, 1.6),
icon_pt(ox, oy, u, 8.0, 3.3),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 8.0, 12.7),
icon_pt(ox, oy, u, 8.0, 14.4),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 1.6, 8.0),
icon_pt(ox, oy, u, 3.3, 8.0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 12.7, 8.0),
icon_pt(ox, oy, u, 14.4, 8.0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 3.5, 3.5),
icon_pt(ox, oy, u, 4.8, 4.8),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 11.2, 11.2),
icon_pt(ox, oy, u, 12.5, 12.5),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 12.5, 3.5),
icon_pt(ox, oy, u, 11.2, 4.8),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 4.8, 11.2),
icon_pt(ox, oy, u, 3.5, 12.5),
color,
sw,
);
}
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,
u,
c1x + r1 * theta1_top.cos(),
c1y + r1 * theta1_top.sin(),
);
let p_bot: Point = icon_pt(
ox,
oy,
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 t: f32 = (step as f32) / (outer_steps as f32);
let ang: f32 = theta1_bot + (theta1_end - theta1_bot) * t;
icon_pt(ox, oy, u, c1x + r1 * ang.cos(), c1y + r1 * ang.sin())
};
icon_line(dl, prev_outer, next_pt, color, sw);
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 t: f32 = (step as f32) / (inner_steps as f32);
let ang: f32 = theta2_top + (theta2_bot - theta2_top) * t;
icon_pt(ox, oy, u, c2x + r2 * ang.cos(), c2y + r2 * ang.sin())
};
icon_line(dl, prev_inner, next_pt, color, sw);
prev_inner = next_pt;
}
}
EuvIconName::Palette => {
let d: f32 = 11.6 * u;
dl.push(DrawCommand::FillRoundedRect {
rect: Rect::new(ox + 2.2 * u, oy + 2.2 * u, d, d),
color: COLOR_TRANSPARENT,
radius: CornerRadius::all(RADIUS_PILL),
border: Border::new(sw, color),
});
let dot_r: f32 = (1.35 * u).max(1.2);
dl.push(DrawCommand::Circle {
center: icon_pt(ox, oy, u, 6.0, 6.2),
radius: dot_r,
color,
});
dl.push(DrawCommand::Circle {
center: icon_pt(ox, oy, u, 10.0, 6.2),
radius: dot_r,
color,
});
dl.push(DrawCommand::Circle {
center: icon_pt(ox, oy, u, 8.0, 10.2),
radius: dot_r,
color,
});
}
EuvIconName::Menu => {
icon_line(
dl,
icon_pt(ox, oy, u, 2.5, 4.2),
icon_pt(ox, oy, u, 13.5, 4.2),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 2.5, 8.0),
icon_pt(ox, oy, u, 13.5, 8.0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 2.5, 11.8),
icon_pt(ox, oy, u, 13.5, 11.8),
color,
sw,
);
}
EuvIconName::Play => {
dl.push(DrawCommand::Triangle {
p0: icon_pt(ox, oy, u, 4.6, 3.0),
p1: icon_pt(ox, oy, u, 13.0, 8.0),
p2: icon_pt(ox, oy, u, 4.6, 13.0),
color,
});
}
EuvIconName::Pause => {
let bar_w: f32 = (2.6 * u).max(2.0);
let bar_h: f32 = 9.6 * u;
dl.push(DrawCommand::FillRoundedRect {
rect: Rect::new(ox + 4.0 * u, oy + 3.2 * u, bar_w, bar_h),
color,
radius: CornerRadius::all(1.0),
border: Border::default(),
});
dl.push(DrawCommand::FillRoundedRect {
rect: Rect::new(ox + 9.4 * u, oy + 3.2 * u, bar_w, bar_h),
color,
radius: CornerRadius::all(1.0),
border: Border::default(),
});
}
EuvIconName::Refresh => {
let r: 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,
u,
8.0 + r * start_ang.cos(),
8.0 + r * start_ang.sin(),
);
let mut prev: Point = head_pt;
for step in 1..=steps {
let t: f32 = (step as f32) / (steps as f32);
let ang: f32 = start_ang + sweep * t;
let cur: Point = icon_pt(ox, oy, u, 8.0 + r * ang.cos(), 8.0 + r * ang.sin());
icon_line(dl, prev, cur, color, sw);
prev = cur;
}
icon_line(dl, head_pt, icon_pt(ox, oy, u, 12.6, 2.8), color, sw);
icon_line(dl, head_pt, icon_pt(ox, oy, u, 9.6, 5.9), color, sw);
}
EuvIconName::Trash => {
icon_line(
dl,
icon_pt(ox, oy, u, 2.8, 4.4),
icon_pt(ox, oy, u, 13.2, 4.4),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 5.8, 4.4),
icon_pt(ox, oy, u, 5.8, 2.4),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 5.8, 2.4),
icon_pt(ox, oy, u, 10.2, 2.4),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 10.2, 2.4),
icon_pt(ox, oy, u, 10.2, 4.4),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 4.4, 4.4),
icon_pt(ox, oy, u, 5.0, 13.2),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 5.0, 13.2),
icon_pt(ox, oy, u, 11.0, 13.2),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 11.0, 13.2),
icon_pt(ox, oy, u, 11.6, 4.4),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 6.8, 6.8),
icon_pt(ox, oy, u, 6.8, 11.0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 9.2, 6.8),
icon_pt(ox, oy, u, 9.2, 11.0),
color,
sw,
);
}
EuvIconName::ChevronDown => {
icon_line(
dl,
icon_pt(ox, oy, u, 3.6, 5.8),
icon_pt(ox, oy, u, 8.0, 10.6),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 8.0, 10.6),
icon_pt(ox, oy, u, 12.4, 5.8),
color,
sw,
);
}
EuvIconName::ArrowLeft => {
icon_line(
dl,
icon_pt(ox, oy, u, 12.6, 8.0),
icon_pt(ox, oy, u, 3.6, 8.0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 7.4, 4.2),
icon_pt(ox, oy, u, 3.6, 8.0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 3.6, 8.0),
icon_pt(ox, oy, u, 7.4, 11.8),
color,
sw,
);
}
EuvIconName::ArrowRight => {
icon_line(
dl,
icon_pt(ox, oy, u, 3.4, 8.0),
icon_pt(ox, oy, u, 12.4, 8.0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 8.6, 4.2),
icon_pt(ox, oy, u, 12.4, 8.0),
color,
sw,
);
icon_line(
dl,
icon_pt(ox, oy, u, 12.4, 8.0),
icon_pt(ox, oy, u, 8.6, 11.8),
color,
sw,
);
}
}
}