Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions crates/app/src/ui/canvas/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
123 changes: 50 additions & 73 deletions crates/app/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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`).
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<R>(
panel: egui::Panel,
Expand Down Expand Up @@ -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::<Rect>(panel_id.with("plotium_card_rect")));
let Some(card_rect) = card_rect else {
.data(|data| data.get_temp::<Rect>(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.
Expand All @@ -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;
Expand All @@ -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))
{
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down
54 changes: 9 additions & 45 deletions crates/app/src/ui/ribbon_chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -197,40 +183,18 @@ fn text_width(ui: &Ui, text: impl Into<WidgetText>, 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)]
Expand Down
16 changes: 8 additions & 8 deletions crates/app/src/ui/settings_dialog/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
Expand Down Expand Up @@ -205,8 +205,8 @@ mod tests {
assert_eq!(
ChromeGeometry::for_platform(DesktopPlatform::MacOs),
ChromeGeometry {
control: 6,
surface: 10,
control: 8,
surface: 12,
}
);
assert_eq!(
Expand All @@ -219,8 +219,8 @@ mod tests {
assert_eq!(
ChromeGeometry::for_platform(DesktopPlatform::Linux),
ChromeGeometry {
control: 6,
surface: 10,
control: 8,
surface: 12,
}
);
}
Expand Down
Loading
Loading