diff --git a/src/ui/host_grid.rs b/src/ui/host_grid.rs index 56472c4..b5f2494 100644 --- a/src/ui/host_grid.rs +++ b/src/ui/host_grid.rs @@ -271,13 +271,19 @@ fn render_header( 20 }), ); - icons::paint( + let chevron_t = ui.ctx().animate_bool_with_time( + ui.id().with("tb_new_menu_anim"), + *new_host_menu_open, + 0.14, + ); + icons::paint_rotated( &painter, chevron.center() + vec2(0.0, 0.5), bold::CARET_DOWN, 12.0, theme::TEXT_PRIMARY, IconStyle::Bold, + chevron_t * std::f32::consts::PI, ); if chresp.clicked() { *new_host_menu_open = !*new_host_menu_open; diff --git a/src/ui/icons.rs b/src/ui/icons.rs index 592906d..673d8be 100644 --- a/src/ui/icons.rs +++ b/src/ui/icons.rs @@ -36,6 +36,28 @@ pub fn paint( ); } +/// Paints a Tabler icon glyph centered on `center`, rotated by `angle` radians clockwise. +pub fn paint_rotated( + painter: &Painter, + center: Pos2, + glyph: &str, + size: f32, + color: Color32, + style: IconStyle, + angle: f32, +) { + if angle.abs() < 1e-4 { + paint(painter, center, glyph, size, color, style); + return; + } + let galley = painter.layout_no_wrap(glyph.to_owned(), font(size, style), color); + let rot = egui::emath::Rot2::from_angle(angle); + let pos = center + rot * (-galley.size() / 2.0); + let mut shape = egui::epaint::TextShape::new(pos, galley, color); + shape.angle = angle; + painter.add(shape); +} + /// Tabler Icons (outline, 2px stroke). #[allow(dead_code)] pub mod regular {