diff --git a/crates/linkshot-app/src/app.rs b/crates/linkshot-app/src/app.rs index 5088368..a6f3907 100644 --- a/crates/linkshot-app/src/app.rs +++ b/crates/linkshot-app/src/app.rs @@ -81,6 +81,9 @@ pub struct App { pending: Option, pub capture_visible: bool, pub editor_visible: bool, + /// Editor geometry chosen when its viewport opened. egui turns any change in a viewport's builder + /// into a move/resize command, so feeding back the remembered rect every frame fights the user's drag. + editor_open_geometry: Option<(Option<[f32; 2]>, [f32; 2], [f32; 2])>, pub capture_toggled: bool, pub hotkeys: Hotkeys, pub tray: Tray, @@ -162,6 +165,7 @@ impl App { pending: None, capture_visible: !background, editor_visible: false, + editor_open_geometry: None, capture_toggled: false, hotkeys: if headless_dark.is_some() { Hotkeys::disabled() } else { let c = ctx.clone(); Hotkeys::new(move || crate::keepalive::wake(&c)) }, tray: if headless_dark.is_some() { Tray::disabled() } else { let c = ctx.clone(); Tray::new(move || crate::keepalive::wake(&c)) }, @@ -929,8 +933,11 @@ impl eframe::App for App { } // Editor viewport. + if !self.editor_visible { self.editor_open_geometry = None; } if self.editor_visible { - let (pos, size, min) = self.editor_window_geometry(); + let geometry = match self.editor_open_geometry { Some(g) => g, None => self.editor_window_geometry() }; + self.editor_open_geometry = Some(geometry); + let (pos, size, min) = geometry; let mut builder = egui::ViewportBuilder::default() .with_title("LinkShot Editor") .with_app_id("linkshot") diff --git a/crates/linkshot-app/src/editor/mod.rs b/crates/linkshot-app/src/editor/mod.rs index 7a67aea..a78f80a 100644 --- a/crates/linkshot-app/src/editor/mod.rs +++ b/crates/linkshot-app/src/editor/mod.rs @@ -518,6 +518,8 @@ pub fn editor_ui(app: &mut App, ctx: &egui::Context, actions: &mut Vec) ctx.request_repaint_after(std::time::Duration::from_millis(500)); } else { app.editor.status = None; } } + // Last, so the edge strips win the hit test over whatever is drawn underneath them. + resize_edges(ui, ctx, full); }); dialogs(app, ctx, actions); video_view::gif_dialog_ui(app, ctx); @@ -631,6 +633,31 @@ fn doc_details(app: &App) -> String { } } +/// The Editor has no system frame (`with_decorations(false)`), so it gets no resize border from the +/// window manager: thin strips along the edges and corners hand a drag to it as a native resize. +fn resize_edges(ui: &mut egui::Ui, ctx: &egui::Context, full: Rect) { + use egui::{CursorIcon as C, ResizeDirection as D}; + if ctx.input(|i| i.viewport().maximized.unwrap_or(false) || i.viewport().fullscreen.unwrap_or(false)) { return; } + const EDGE: f32 = 5.0; + const CORNER: f32 = 12.0; + let (l, r, t, b) = (full.left(), full.right(), full.top(), full.bottom()); + let zones = [ + (Rect::from_min_max(Pos2::new(l, t), Pos2::new(l + CORNER, t + CORNER)), D::NorthWest, C::ResizeNorthWest), + (Rect::from_min_max(Pos2::new(r - CORNER, t), Pos2::new(r, t + CORNER)), D::NorthEast, C::ResizeNorthEast), + (Rect::from_min_max(Pos2::new(l, b - CORNER), Pos2::new(l + CORNER, b)), D::SouthWest, C::ResizeSouthWest), + (Rect::from_min_max(Pos2::new(r - CORNER, b - CORNER), Pos2::new(r, b)), D::SouthEast, C::ResizeSouthEast), + (Rect::from_min_max(Pos2::new(l + CORNER, t), Pos2::new(r - CORNER, t + EDGE)), D::North, C::ResizeNorth), + (Rect::from_min_max(Pos2::new(l + CORNER, b - EDGE), Pos2::new(r - CORNER, b)), D::South, C::ResizeSouth), + (Rect::from_min_max(Pos2::new(l, t + CORNER), Pos2::new(l + EDGE, b - CORNER)), D::West, C::ResizeWest), + (Rect::from_min_max(Pos2::new(r - EDGE, t + CORNER), Pos2::new(r, b - CORNER)), D::East, C::ResizeEast), + ]; + for (i, (rect, dir, cursor)) in zones.into_iter().enumerate() { + let resp = ui.interact(rect, ui.id().with(("resize-edge", i)), Sense::drag()); + if resp.hovered() || resp.dragged() { ctx.set_cursor_icon(cursor); } + if resp.drag_started() { ctx.send_viewport_cmd(egui::ViewportCommand::BeginResize(dir)); } + } +} + fn caption_row(app: &mut App, ui: &mut egui::Ui, rect: Rect, ctx: &egui::Context, actions: &mut Vec) { let pal = app.pal; ui.painter().rect_filled(rect, 0.0, pal.main_panel);