diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 2ff3bd8e..fc48b565 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -500,7 +500,7 @@ fn main() -> eframe::Result<()> { .with_min_inner_size(MIN_WINDOW_PT) .with_title("Plotium") .with_icon(application_icon()); - let viewport = ui::configure_ribbon_viewport(viewport); + let viewport = ui::window_shell::configure_viewport(viewport); let mut wgpu_options = eframe::egui_wgpu::WgpuConfiguration { desired_maximum_frame_latency: desired_maximum_frame_latency(), ..Default::default() diff --git a/crates/app/src/ui/canvas/mod.rs b/crates/app/src/ui/canvas/mod.rs index 914425b0..e4c385b8 100644 --- a/crates/app/src/ui/canvas/mod.rs +++ b/crates/app/src/ui/canvas/mod.rs @@ -277,8 +277,7 @@ pub fn render_central(app: &mut PlotiumApp, ui: &mut Ui) { let page = page_screen_rect(app.session.board, &app.doc.canvases[ci], rect); let frame_stroke = Stroke::new(1.0_f32, ui.visuals().widgets.noninteractive.bg_stroke.color); - // Pages float on the board the way chrome cards float on the workspace: a - // soft shadow keeps a white page legible on the light workspace fill. + // A soft shadow keeps a white page legible on the light workspace fill. let page_shadow = egui::epaint::Shadow { offset: [0, 2], blur: 10, diff --git a/crates/app/src/ui/mod.rs b/crates/app/src/ui/mod.rs index ff69898c..722055e6 100644 --- a/crates/app/src/ui/mod.rs +++ b/crates/app/src/ui/mod.rs @@ -63,6 +63,7 @@ mod trace_alignment; mod trace_composer; #[cfg(any(target_os = "macos", test))] mod window_lifecycle; +pub(crate) mod window_shell; mod windows; mod workspace_geometry; @@ -76,12 +77,11 @@ use plotium_core::actions::Action; use plotium_core::export::{ExportPageScope, ExportScopeKind, ExportSettings}; use plotium_core::operation::OperationOutcome; use plotium_core::state::{Interaction, PlotiumApp, Selection}; -pub(crate) use ribbon_chrome::{ - RibbonChrome, configure_viewport as configure_ribbon_viewport, current as current_ribbon_chrome, -}; +pub(crate) use ribbon_chrome::{RibbonChrome, current as current_ribbon_chrome}; pub(crate) use settings_dialog::apply_chrome_theme; use settings_dialog::{settings_window, sync_chrome_theme}; use shortcuts::*; +use window_shell::workspace_fill; pub(crate) use windows::handle_close_request; use windows::*; use workspace_geometry::resolve as workspace_geometry; @@ -177,25 +177,28 @@ pub fn render( } let dark = ui.visuals().dark_mode; - // The gaps between chrome cards show whatever the root panel painted, so + // Gaps around workspace cards show whatever the root panel painted, so // lay the workspace colour under everything first. ui.painter() .rect_filled(ui.max_rect(), 0.0, workspace_fill(dark)); + // The title bar and the Ribbon form one surface that meets the window + // edges; a single divider separates it from the workspace below. #[cfg(not(target_os = "macos"))] egui::Panel::top("title_bar") - .frame(flush_frame(dark, egui::Margin::ZERO)) + .frame(window_shell::edge_frame(dark, egui::Margin::ZERO)) .show_separator_line(false) .show_inside(ui, |ui| { title_bar::render(app, clipboard_table_paste, ui); }); - egui::Panel::top("ribbon") + let ribbon = egui::Panel::top("ribbon") .frame(ribbon_chrome::frame(dark)) .show_separator_line(false) .show_inside(ui, |ui| { ribbon::render(app, clipboard_table_paste, ui, ribbon_chrome); }); + window_shell::paint_separator(ui, ribbon.response.rect, window_shell::Side::Bottom, dark); feedback_banner(app, ui, dark); activity::observe(app); @@ -217,12 +220,11 @@ pub fn render( data_sheet_dock(app, ui, dark); canvas::clear_navigation_rect(&ctx); egui::CentralPanel::default() - .frame(egui::Frame::new().fill(workspace_fill(dark)).inner_margin( - central_workspace_margin( - app.session.primary_sidebar_visible, - app.session.secondary_sidebar_visible, - ), - )) + .frame( + egui::Frame::new() + .fill(workspace_fill(dark)) + .inner_margin(CENTRAL_WORKSPACE_MARGIN), + ) .show_inside(ui, |ui| { // Same stable id scope as the sidebars: the central panel's ids // must not shift when a sidebar toggles (see `show_sidebar`). @@ -276,6 +278,8 @@ pub fn render( file_drop::handle(app, &ctx); #[cfg(not(target_os = "macos"))] title_bar::resize_zones(&ctx); + #[cfg(not(any(target_os = "macos", windows)))] + window_shell::paint_window_outline(&ctx, dark); let now = ctx.input(|i| i.time); app.finish_pending_wheel_zoom(now, false); @@ -363,16 +367,16 @@ const SIDEBAR_RESIZE_GRAB_RADIUS: f32 = 2.0; const SIDEBAR_HIGHLIGHT_RADIUS: f32 = 90.0; const SIDEBAR_HIGHLIGHT_SAMPLE_STEP: f32 = 6.0; -fn central_workspace_margin(primary_visible: bool, secondary_visible: bool) -> egui::Margin { - egui::Margin { - left: if primary_visible { 8 } else { 4 }, - right: if secondary_visible { 8 } else { 4 }, - top: 4, - bottom: 2, - } -} +/// Keeps the board clear of the sidebar resize grab, which straddles the +/// sidebar divider, so the board never takes that drag. +const CENTRAL_WORKSPACE_MARGIN: egui::Margin = egui::Margin { + left: 4, + right: 4, + top: 4, + bottom: 2, +}; -/// Keep the resize interaction local to the visible card edge while replacing +/// Keep the resize interaction local to the sidebar divider while replacing /// egui's full-height, high-contrast separator with restrained feedback. fn show_resizable_sidebar( panel: egui::Panel, @@ -419,16 +423,16 @@ fn sidebar_resize_enabled(ui: &Ui, panel_id: Id, edge: SidebarEdge) -> bool { { return true; } - let card_rect = ui + let sidebar_rect = ui .ctx() - .data(|data| data.get_temp::(panel_id.with("plotium_card_rect"))); - let Some(card_rect) = card_rect else { + .data(|data| data.get_temp::(panel_id.with("plotium_sidebar_rect"))); + let Some(sidebar_rect) = sidebar_rect else { return true; }; let on_edge = ui .ctx() .pointer_hover_pos() - .is_some_and(|pointer| sidebar_edge_hit_rect(card_rect, edge).contains(pointer)); + .is_some_and(|pointer| sidebar_edge_hit_rect(sidebar_rect, edge).contains(pointer)); if on_edge && previous_response.is_none() { // The resizer was omitted on the previous pass. Register it now and // schedule the pass on which egui can hit-test its new rectangle. @@ -437,33 +441,26 @@ fn sidebar_resize_enabled(ui: &Ui, panel_id: Id, edge: SidebarEdge) -> bool { on_edge } -fn sidebar_edge_hit_rect(card_rect: Rect, edge: SidebarEdge) -> Rect { +fn sidebar_edge_hit_rect(sidebar_rect: Rect, edge: SidebarEdge) -> Rect { let x = match edge { - SidebarEdge::Left => card_rect.left(), - SidebarEdge::Right => card_rect.right(), + SidebarEdge::Left => sidebar_rect.left(), + SidebarEdge::Right => sidebar_rect.right(), }; - let corner_radius = 8.0; - Rect::from_min_max( - Pos2::new( - x - SIDEBAR_RESIZE_GRAB_RADIUS, - card_rect.top() + corner_radius, - ), - Pos2::new( - x + SIDEBAR_RESIZE_GRAB_RADIUS, - card_rect.bottom() - corner_radius, - ), + Rect::from_x_y_ranges( + (x - SIDEBAR_RESIZE_GRAB_RADIUS)..=(x + SIDEBAR_RESIZE_GRAB_RADIUS), + sidebar_rect.y_range(), ) } fn paint_sidebar_resize_edge( ui: &Ui, panel_id: Id, - card_rect: Rect, + sidebar_rect: Rect, edge: SidebarEdge, dark: bool, ) { ui.ctx().data_mut(|data| { - data.insert_temp(panel_id.with("plotium_card_rect"), card_rect); + data.insert_temp(panel_id.with("plotium_sidebar_rect"), sidebar_rect); }); let Some(response) = ui.ctx().read_response(panel_id.with("__resize")) else { return; @@ -472,8 +469,7 @@ fn paint_sidebar_resize_edge( return; } - let corner_radius = 8.0; - let straight_edge = sidebar_edge_hit_rect(card_rect, edge); + let straight_edge = sidebar_edge_hit_rect(sidebar_rect, edge); let hover_pointer = ui.ctx().pointer_hover_pos(); if !response.dragged() && !hover_pointer.is_some_and(|pointer| straight_edge.contains(pointer)) { @@ -496,12 +492,16 @@ fn paint_sidebar_resize_edge( let Some(pointer) = pointer else { return; }; + // Centre the highlight on the 1 px divider painted inside the sidebar. + let ppp = ui.painter().pixels_per_point(); let x = match edge { - SidebarEdge::Left => card_rect.left(), - SidebarEdge::Right => card_rect.right(), + SidebarEdge::Left => window_shell::separator_center(sidebar_rect.left(), 1.0, ppp), + SidebarEdge::Right => window_shell::separator_center(sidebar_rect.right(), -1.0, ppp), }; - let min_y = (card_rect.top() + corner_radius).max(pointer.y - SIDEBAR_HIGHLIGHT_RADIUS); - let max_y = (card_rect.bottom() - corner_radius).min(pointer.y + SIDEBAR_HIGHLIGHT_RADIUS); + let min_y = sidebar_rect.top().max(pointer.y - SIDEBAR_HIGHLIGHT_RADIUS); + let max_y = sidebar_rect + .bottom() + .min(pointer.y + SIDEBAR_HIGHLIGHT_RADIUS); if min_y >= max_y { return; } @@ -532,17 +532,6 @@ fn sidebar_highlight_alpha(distance: f32) -> f32 { 1.0 - t * t * (3.0 - 2.0 * t) } -/// Chrome layering: the Ribbon and sidebars sit as rounded cards on a slightly -/// darker workspace instead of being fenced off by separator lines. Fills stay -/// near-neutral so the chrome never skews colour judgement of plot data. -fn workspace_fill(dark: bool) -> Color32 { - if dark { - Color32::from_rgb(21, 22, 24) - } else { - Color32::from_rgb(243, 244, 246) - } -} - pub(super) enum ModalKind { /// Command-palette style: no backdrop dim and anchored near the top of the /// window, so the workspace stays readable while searching (the convention @@ -576,17 +565,13 @@ pub(super) fn modal(ctx: &egui::Context, id: &str, kind: ModalKind) -> egui::Mod } fn card_frame(dark: bool, outer_margin: egui::Margin) -> egui::Frame { - let (fill, stroke, shadow_alpha) = if dark { - ( - Color32::from_rgb(34, 35, 38), - Color32::from_white_alpha(12), - 96, - ) + let (stroke, shadow_alpha) = if dark { + (Color32::from_white_alpha(12), 96) } else { - (Color32::WHITE, Color32::from_black_alpha(15), 20) + (Color32::from_black_alpha(15), 20) }; egui::Frame::new() - .fill(fill) + .fill(window_shell::chrome_fill(dark)) .stroke(Stroke::new(1.0_f32, stroke)) .corner_radius(settings_dialog::surface_corner_radius()) .inner_margin(8) @@ -599,14 +584,6 @@ fn card_frame(dark: bool, outer_margin: egui::Margin) -> egui::Frame { }) } -/// The menu strip blends into the workspace rather than floating on it. -#[cfg(not(target_os = "macos"))] -fn flush_frame(dark: bool, inner_margin: egui::Margin) -> egui::Frame { - egui::Frame::new() - .fill(workspace_fill(dark)) - .inner_margin(inner_margin) -} - #[cfg(test)] #[path = "sidebar_tests.rs"] mod sidebar_tests; diff --git a/crates/app/src/ui/ribbon_chrome.rs b/crates/app/src/ui/ribbon_chrome.rs index 3dcd582f..1ff218ef 100644 --- a/crates/app/src/ui/ribbon_chrome.rs +++ b/crates/app/src/ui/ribbon_chrome.rs @@ -43,20 +43,6 @@ pub(crate) fn current(_ctx: &egui::Context, _frame: &eframe::Frame) -> RibbonChr RibbonChrome::default() } -pub(crate) fn configure_viewport(viewport: egui::ViewportBuilder) -> egui::ViewportBuilder { - // Windows and Linux draw a VS Code style title bar inside the content area; - // macOS keeps the native traffic lights and system menu. - #[cfg(not(target_os = "macos"))] - let viewport = viewport.with_decorations(false); - #[cfg(target_os = "macos")] - let viewport = viewport - .with_fullsize_content_view(true) - .with_titlebar_shown(false) - .with_title_shown(false) - .with_titlebar_buttons_shown(true); - viewport -} - pub(super) fn inline_project_title(app: &PlotiumApp) -> String { let project = app .doc @@ -197,40 +183,18 @@ fn text_width(ui: &Ui, text: impl Into, fallback: TextStyle) -> f32 } pub(super) fn frame(dark: bool) -> egui::Frame { - #[cfg(target_os = "macos")] - { - // The task row occupies the native title-bar area, so its surface must - // meet the window edges instead of floating below them as a card. - super::card_frame( - dark, - egui::Margin { - left: 0, - right: 0, - top: 0, - bottom: 4, - }, - ) - .corner_radius(0) - .inner_margin(egui::Margin { + // On macOS the task row occupies the native title-bar area; elsewhere it + // continues the surface of the drawn title bar above it. + let top = if cfg!(target_os = "macos") { 0 } else { 4 }; + super::window_shell::edge_frame( + dark, + egui::Margin { left: 8, right: 8, - top: 0, + top, bottom: 8, - }) - .shadow(egui::epaint::Shadow::NONE) - } - #[cfg(not(target_os = "macos"))] - { - super::card_frame( - dark, - egui::Margin { - left: 8, - right: 8, - top: 4, - bottom: 4, - }, - ) - } + }, + ) } #[cfg(test)] diff --git a/crates/app/src/ui/settings_dialog/chrome.rs b/crates/app/src/ui/settings_dialog/chrome.rs index 83f50529..9d5663e9 100644 --- a/crates/app/src/ui/settings_dialog/chrome.rs +++ b/crates/app/src/ui/settings_dialog/chrome.rs @@ -26,16 +26,16 @@ impl ChromeGeometry { const fn for_platform(platform: DesktopPlatform) -> Self { match platform { DesktopPlatform::MacOs => Self { - control: 6, - surface: 10, + control: 8, + surface: 12, }, DesktopPlatform::Windows => Self { control: 4, surface: 8, }, DesktopPlatform::Linux => Self { - control: 6, - surface: 10, + control: 8, + surface: 12, }, } } @@ -205,8 +205,8 @@ mod tests { assert_eq!( ChromeGeometry::for_platform(DesktopPlatform::MacOs), ChromeGeometry { - control: 6, - surface: 10, + control: 8, + surface: 12, } ); assert_eq!( @@ -219,8 +219,8 @@ mod tests { assert_eq!( ChromeGeometry::for_platform(DesktopPlatform::Linux), ChromeGeometry { - control: 6, - surface: 10, + control: 8, + surface: 12, } ); } diff --git a/crates/app/src/ui/sidebar_tests.rs b/crates/app/src/ui/sidebar_tests.rs index cecf952d..f94c8bf9 100644 --- a/crates/app/src/ui/sidebar_tests.rs +++ b/crates/app/src/ui/sidebar_tests.rs @@ -172,15 +172,22 @@ fn highlight_falls_off_symmetrically_to_zero() { } #[test] -fn central_margin_preserves_sidebar_gaps_only_when_present() { - let both = central_workspace_margin(true, true); - assert_eq!((both.left, both.right), (8, 8)); - - let primary_only = central_workspace_margin(true, false); - assert_eq!((primary_only.left, primary_only.right), (8, 4)); +fn board_margin_keeps_the_resize_grab_off_the_board() { + let margin = CENTRAL_WORKSPACE_MARGIN; + assert_eq!((margin.left, margin.right), (4, 4)); + assert!(f32::from(margin.left) > SIDEBAR_RESIZE_GRAB_RADIUS); + assert!(f32::from(margin.right) > SIDEBAR_RESIZE_GRAB_RADIUS); +} - let neither = central_workspace_margin(false, false); - assert_eq!((neither.left, neither.right), (4, 4)); +#[test] +fn resize_grab_spans_the_full_sidebar_height() { + let sidebar = Rect::from_min_max(Pos2::new(0.0, 80.0), Pos2::new(240.0, 700.0)); + for (edge, x) in [(SidebarEdge::Right, 240.0), (SidebarEdge::Left, 0.0)] { + let hit = sidebar_edge_hit_rect(sidebar, edge); + assert_eq!(hit.y_range(), sidebar.y_range()); + assert_eq!(hit.center().x, x); + assert_eq!(hit.width(), 2.0 * SIDEBAR_RESIZE_GRAB_RADIUS); + } } #[test] @@ -234,7 +241,17 @@ fn cursor_at_edge_offset(edge: SidebarEdge, offset: f32) -> egui::CursorIcon { edge, true, ); - egui::CentralPanel::default().show_inside(ui, |_| {}); + // A draggable board behind the real workspace margin must not + // take the grab from the divider. + egui::CentralPanel::default() + .frame(egui::Frame::NONE.inner_margin(CENTRAL_WORKSPACE_MARGIN)) + .show_inside(ui, |ui| { + ui.interact( + ui.max_rect(), + Id::new("board"), + egui::Sense::click_and_drag(), + ); + }); }, ) }; diff --git a/crates/app/src/ui/sidebars.rs b/crates/app/src/ui/sidebars.rs index 0ab59022..6fbe2ff5 100644 --- a/crates/app/src/ui/sidebars.rs +++ b/crates/app/src/ui/sidebars.rs @@ -23,12 +23,7 @@ pub(super) fn render(app: &mut PlotiumApp, ui: &mut Ui, dark: bool, workspace_wi let max_width = (workspace_width - other_width - MIN_WORKSPACE_WIDTH).clamp(min_width, 420.0); let panel = egui::Panel::left("primary_sidebar") - .frame(egui::Frame::NONE.inner_margin(egui::Margin { - left: 8, - right: 0, - top: 4, - bottom: 8, - })) + .frame(egui::Frame::NONE) .show_separator_line(false) .resizable(true) .default_size( @@ -69,12 +64,7 @@ pub(super) fn render(app: &mut PlotiumApp, ui: &mut Ui, dark: bool, workspace_wi let max_width = (workspace_width - other_width - MIN_WORKSPACE_WIDTH).clamp(min_width, 460.0); let panel = egui::Panel::right("secondary_sidebar") - .frame(egui::Frame::NONE.inner_margin(egui::Margin { - left: 0, - right: 8, - top: 4, - bottom: 8, - })) + .frame(egui::Frame::NONE) .show_separator_line(false) .resizable(true) .default_size( @@ -177,9 +167,9 @@ fn show_sidebar( .global_scope(true), |ui| { let size = ui.available_size(); - let frame = card_frame(dark, egui::Margin::ZERO); + let frame = window_shell::edge_frame(dark, window_shell::EDGE_INSET); let inset = frame.total_margin().sum(); - frame + let rect = frame .show(ui, |ui| { ui.set_min_size((size - inset).max(Vec2::ZERO)); if primary { @@ -189,7 +179,14 @@ fn show_sidebar( } }) .response - .rect + .rect; + let divider = if primary { + window_shell::Side::Right + } else { + window_shell::Side::Left + }; + window_shell::paint_separator(ui, rect, divider, dark); + rect }, ) .inner diff --git a/crates/app/src/ui/switcher.rs b/crates/app/src/ui/switcher.rs index 15c3f749..0da80a75 100644 --- a/crates/app/src/ui/switcher.rs +++ b/crates/app/src/ui/switcher.rs @@ -79,8 +79,10 @@ pub fn segmented(ui: &mut Ui, current: &mut PrimaryView) -> bool { let width = ui.available_width(); let (track_rect, _) = ui.allocate_exact_size(Vec2::new(width, TRACK_HEIGHT), Sense::hover()); - let track_radius = CornerRadius::same(9); - let segment_radius = CornerRadius::same(6); + // The pill uses the platform control radius; the track's radius adds the + // inset so both curves stay concentric. + let segment_radius = ui.visuals().widgets.inactive.corner_radius; + let track_radius = CornerRadius::same(segment_radius.nw.saturating_add(SEGMENT_INSET as u8)); let painter = ui.painter().clone(); painter.rect_filled(track_rect, track_radius, track_fill); @@ -102,8 +104,7 @@ pub fn segmented(ui: &mut Ui, current: &mut PrimaryView) -> bool { Pos2::new(inner.left() + pill_pos * slot_w, inner.top()), Vec2::new(slot_w, inner.height()), ); - // The pill floats like the chrome cards do: no hairline box, just a soft - // drop shadow lifting it off the track. + // No hairline box, just a soft drop shadow lifting the pill off the track. let pill_shadow = egui::epaint::Shadow { offset: [0, 1], blur: 4, diff --git a/crates/app/src/ui/title_bar.rs b/crates/app/src/ui/title_bar.rs index 4bdb9b65..04f18ea8 100644 --- a/crates/app/src/ui/title_bar.rs +++ b/crates/app/src/ui/title_bar.rs @@ -211,9 +211,8 @@ pub(super) fn resize_zones(ctx: &egui::Context) { if maximized || fullscreen { return; } + use super::window_shell::{RESIZE_CORNER as CORNER, RESIZE_EDGE as EDGE}; use egui::ResizeDirection as Dir; - const EDGE: f32 = 5.0; - const CORNER: f32 = 12.0; let rect = ctx.content_rect(); let (left, right, top, bottom) = (rect.left(), rect.right(), rect.top(), rect.bottom()); let zones = [ diff --git a/crates/app/src/ui/window_shell.rs b/crates/app/src/ui/window_shell.rs new file mode 100644 index 00000000..8b23f9b5 --- /dev/null +++ b/crates/app/src/ui/window_shell.rs @@ -0,0 +1,190 @@ +//! Window shell independent of any one window's state: viewport decorations, +//! the two surface fills, and the chrome that meets the window edges. + +use egui::{Color32, Margin, Rect, Stroke, Ui}; + +/// Windows and Linux resize the undecorated window from zones this deep along +/// each edge and this square at each corner (`title_bar::resize_zones`). +pub(crate) const RESIZE_EDGE: f32 = 5.0; +pub(crate) const RESIZE_CORNER: f32 = 12.0; + +/// Content inset of edge chrome: clear of the resize edges by at least 1 pt, +/// and of the corner zones along the bottom. +pub(crate) const EDGE_INSET: Margin = Margin { + left: 8, + right: 8, + top: 8, + bottom: 12, +}; + +const _: () = assert!( + EDGE_INSET.left as f32 >= RESIZE_EDGE + 1.0 + && EDGE_INSET.right as f32 >= RESIZE_EDGE + 1.0 + && EDGE_INSET.bottom as f32 >= RESIZE_CORNER +); + +pub(crate) fn configure_viewport(viewport: egui::ViewportBuilder) -> egui::ViewportBuilder { + // Windows and Linux draw a VS Code style title bar inside the content area; + // macOS keeps the native traffic lights and system menu. + #[cfg(not(target_os = "macos"))] + let viewport = viewport.with_decorations(false); + #[cfg(target_os = "macos")] + let viewport = viewport + .with_fullsize_content_view(true) + .with_titlebar_shown(false) + .with_title_shown(false) + .with_titlebar_buttons_shown(true); + viewport +} + +/// The recessed surface behind the board. Fills stay near-neutral so the +/// chrome never skews colour judgement of plot data. +pub(crate) fn workspace_fill(dark: bool) -> Color32 { + if dark { + Color32::from_rgb(21, 22, 24) + } else { + Color32::from_rgb(243, 244, 246) + } +} + +/// The raised surface of the title bar, Ribbon, sidebars, and task cards. +pub(crate) fn chrome_fill(dark: bool) -> Color32 { + if dark { + Color32::from_rgb(34, 35, 38) + } else { + Color32::WHITE + } +} + +const SEPARATOR_WIDTH: f32 = 1.0; + +pub(crate) fn separator_stroke(dark: bool) -> Stroke { + let color = if dark { + Color32::from_white_alpha(20) + } else { + Color32::from_black_alpha(26) + }; + Stroke::new(SEPARATOR_WIDTH, color) +} + +/// Chrome that meets the window edges: no outer margin, corners, or shadow. +/// Neighbouring surfaces are divided by [`paint_separator`] instead. +pub(crate) fn edge_frame(dark: bool, inner_margin: Margin) -> egui::Frame { + egui::Frame::new() + .fill(chrome_fill(dark)) + .inner_margin(inner_margin) +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub(crate) enum Side { + Left, + Right, + Bottom, +} + +/// A 1 px divider drawn inside `rect` along `side`, so it never spills onto +/// the neighbouring surface. +pub(crate) fn paint_separator(ui: &Ui, rect: Rect, side: Side, dark: bool) { + let stroke = separator_stroke(dark); + let painter = ui.painter_at(rect); + let ppp = painter.pixels_per_point(); + match side { + Side::Left => painter.vline( + separator_center(rect.left(), 1.0, ppp), + rect.y_range(), + stroke, + ), + Side::Right => painter.vline( + separator_center(rect.right(), -1.0, ppp), + rect.y_range(), + stroke, + ), + Side::Bottom => painter.hline( + rect.x_range(), + separator_center(rect.bottom(), -1.0, ppp), + stroke, + ), + }; +} + +/// Centre of a divider drawn just inside `edge`, toward `inward` (+1 or -1), +/// snapped with the tessellator's own rule so the line does not move again +/// when tessellated; overlays drawn on the divider use the same centre. +pub(crate) fn separator_center(edge: f32, inward: f32, pixels_per_point: f32) -> f32 { + let mut center = edge + inward * SEPARATOR_WIDTH / 2.0; + Stroke::new(SEPARATOR_WIDTH, Color32::WHITE) + .round_center_to_pixel(pixels_per_point, &mut center); + center +} + +/// Linux compositors draw no shadow or border around an undecorated window, +/// so a 1 px outline separates it from same-coloured windows behind it. +/// Windows restores its DWM frame in `main.rs`; macOS keeps the native frame. +#[cfg(not(any(target_os = "macos", windows)))] +pub(crate) fn paint_window_outline(ctx: &egui::Context, dark: bool) { + let (maximized, fullscreen) = ctx.input(|input| { + let viewport = input.viewport(); + ( + viewport.maximized.unwrap_or(false), + viewport.fullscreen.unwrap_or(false), + ) + }); + if maximized || fullscreen { + return; + } + let color = if dark { + Color32::from_white_alpha(36) + } else { + Color32::from_black_alpha(56) + }; + ctx.layer_painter(egui::LayerId::new( + egui::Order::Foreground, + egui::Id::new("plotium_window_outline"), + )) + .rect_stroke( + ctx.content_rect(), + 0.0, + Stroke::new(1.0_f32, color), + egui::StrokeKind::Inside, + ); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn separator_stays_inside_pixel_aligned_edges_without_resnapping() { + for ppp in [1.0_f32, 1.5, 2.0] { + let pixel = 1.0 / ppp; + for edge in [240.0, 240.0 + pixel, 0.0] { + for inward in [-1.0, 1.0] { + let center = separator_center(edge, inward, ppp); + let near = center - inward * SEPARATOR_WIDTH / 2.0; + let far = center + inward * SEPARATOR_WIDTH / 2.0; + let inside = (near - edge) * inward >= -1e-4 && (far - edge) * inward > 0.0; + assert!( + inside, + "ppp={ppp} edge={edge} inward={inward} center={center}" + ); + assert_eq!( + separator_center(center - inward * SEPARATOR_WIDTH / 2.0, inward, ppp), + center + ); + } + } + } + } + + #[test] + fn edge_frame_has_no_card_geometry() { + for dark in [false, true] { + let frame = edge_frame(dark, EDGE_INSET); + assert_eq!(frame.outer_margin, Margin::ZERO); + assert_eq!(frame.corner_radius, egui::CornerRadius::ZERO); + assert_eq!(frame.shadow, egui::epaint::Shadow::NONE); + assert_eq!(frame.stroke, Stroke::NONE); + assert_ne!(frame.fill, workspace_fill(dark)); + } + } +} diff --git a/crates/app/src/ui/workspace_geometry.rs b/crates/app/src/ui/workspace_geometry.rs index 78289614..2aa909ab 100644 --- a/crates/app/src/ui/workspace_geometry.rs +++ b/crates/app/src/ui/workspace_geometry.rs @@ -74,8 +74,9 @@ pub(super) fn resolve(app: &PlotiumApp, host_rect: Rect, ctx: &egui::Context) -> board_rect = host_rect; } let mut task_card_bounds = board_rect; + // Sidebars reach the window bottom; keep cards the same gap above it. if let Some(sidebar) = sidebars.secondary.or(sidebars.primary) { - task_card_bounds.max.y = sidebar.bottom(); + task_card_bounds.max.y = sidebar.bottom() - SIDEBAR_GAP; } // Cards float over the board only, never over the docked data sheet. if let Some(dock) = super::data_sheet::dock_rect(ctx) { @@ -173,6 +174,9 @@ mod tests { assert_eq!(geometry.board_rect.left(), primary.right() + SIDEBAR_GAP); assert_eq!(geometry.board_rect.right(), secondary.left() - SIDEBAR_GAP); - assert_eq!(geometry.task_card_bounds.bottom(), secondary.bottom()); + assert_eq!( + geometry.task_card_bounds.bottom(), + secondary.bottom() - SIDEBAR_GAP + ); } }