Cleanup drag and drop UI
This commit is contained in:
@@ -5,12 +5,15 @@ use std::{
|
|||||||
path::Path,
|
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;
|
use crate::app::App;
|
||||||
|
|
||||||
|
const HOVER_BACKGROUND: Color32 = Color32::from_rgba_premultiplied(0, 0, 0, 200);
|
||||||
|
|
||||||
pub fn update(app: &mut App, ctx: &Context) {
|
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| {
|
ctx.input(|x| {
|
||||||
for file in &x.raw.dropped_files {
|
for file in &x.raw.dropped_files {
|
||||||
if let Some(path) = &file.path {
|
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 painter = ctx.layer_painter(LayerId::new(Order::Foreground, Id::new("drag_and_drop")));
|
||||||
let rect = ctx.screen_rect();
|
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 text = "Drop files to import";
|
||||||
let font = FontId::default();
|
|
||||||
let text_height = ctx.fonts(|x| x.row_height(&font));
|
painter.text(
|
||||||
let text_pos = rect.center() - egui::vec2(0.0, text_height);
|
pos2(center.x, center.y - 54.0),
|
||||||
painter.text(text_pos, Align2::CENTER_CENTER, text, font, Color32::WHITE);
|
Align2::CENTER_CENTER,
|
||||||
|
icon,
|
||||||
|
FontId::new(64.0, FontFamily::Proportional),
|
||||||
|
Color32::WHITE,
|
||||||
|
);
|
||||||
|
|
||||||
|
painter.text(
|
||||||
|
center,
|
||||||
|
Align2::CENTER_CENTER,
|
||||||
|
text,
|
||||||
|
FontId::default(),
|
||||||
|
Color32::WHITE,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user