diff --git a/mslicer/src/ui/drag_and_drop.rs b/mslicer/src/ui/drag_and_drop.rs index fc2a385..2c7f546 100644 --- a/mslicer/src/ui/drag_and_drop.rs +++ b/mslicer/src/ui/drag_and_drop.rs @@ -5,12 +5,15 @@ use std::{ path::Path, }; -use egui::{Align2, Color32, Context, FontId, Id, LayerId, Order}; +use egui::{pos2, Align2, Color32, Context, FontFamily, FontId, Id, LayerId, Order}; +use egui_phosphor::regular::{FILES, FILE_TEXT}; use crate::app::App; +const HOVER_BACKGROUND: Color32 = Color32::from_rgba_premultiplied(0, 0, 0, 200); + pub fn update(app: &mut App, ctx: &Context) { - let is_hovering = ctx.input(|x| !x.raw.hovered_files.is_empty()); + let hovering = ctx.input(|x| x.raw.hovered_files.len()); ctx.input(|x| { for file in &x.raw.dropped_files { if let Some(path) = &file.path { @@ -27,16 +30,31 @@ pub fn update(app: &mut App, ctx: &Context) { } }); - if is_hovering { + if hovering > 0 { let painter = ctx.layer_painter(LayerId::new(Order::Foreground, Id::new("drag_and_drop"))); let rect = ctx.screen_rect(); - painter.rect_filled(rect, 0.0, Color32::from_rgba_premultiplied(0, 0, 0, 200)); + let center = rect.center(); + painter.rect_filled(rect, 0.0, HOVER_BACKGROUND); + + let icon = if hovering == 1 { FILE_TEXT } else { FILES }; let text = "Drop files to import"; - let font = FontId::default(); - let text_height = ctx.fonts(|x| x.row_height(&font)); - let text_pos = rect.center() - egui::vec2(0.0, text_height); - painter.text(text_pos, Align2::CENTER_CENTER, text, font, Color32::WHITE); + + painter.text( + pos2(center.x, center.y - 54.0), + Align2::CENTER_CENTER, + icon, + FontId::new(64.0, FontFamily::Proportional), + Color32::WHITE, + ); + + painter.text( + center, + Align2::CENTER_CENTER, + text, + FontId::default(), + Color32::WHITE, + ); } }