Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

fix(ui): remove the gap beneath Spectrum document tabs (#2265)

Nigel Ihza Firdausy91a2b587251d
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index 267445d3a..77ff3188a 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -1458,7 +1458,14 @@ fn documents(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
return;
}
if !app.ui.view.hides_tabs() || opening {
+ // Flat Spectrum tabs sit directly against the canvas. The parent's default vertical
+ // item spacing would otherwise leave a visible gap below the tab strip (#2188).
+ let spacing = ui.spacing().item_spacing.y;
+ if crate::theme::Tokens::get(ui.ctx()).pro {
+ ui.spacing_mut().item_spacing.y = 0.0;
+ }
app.tab_strip = Some(tabs(app, ui));
+ ui.spacing_mut().item_spacing.y = spacing;
drop_slot_line(app, ui);
}
if let Some(job) = app.jobs.focus.or_else(|| (n == 0).then(|| app.jobs.opens.last().map(|o| o.job)).flatten()) {
@@ -4618,6 +4625,30 @@ mod tests {
}
}
+ #[test]
+ fn spectrum_document_tabs_meet_canvas_without_a_gap() {
+ for kind in [crate::theme::ThemeKind::Pro, crate::theme::ThemeKind::ProMedium] {
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({"width": 80, "height": 60})).unwrap();
+ app.sync_views();
+ let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(680.0, 480.0)).build_ui_state(
+ |ui, (app, ready): &mut (PhotocraftApp, bool)| {
+ if *ready {
+ egui::CentralPanel::default().frame(egui::Frame::NONE).show(ui, |ui| document_area(app, ui));
+ }
+ },
+ (app, false),
+ );
+ PhotocraftApp::setup_context(&h.ctx, kind);
+ h.state_mut().1 = true;
+ h.run_steps(3);
+ let app = &h.state().0;
+ let strip = app.tab_strip.as_ref().expect("a document opens with tabs").rect;
+ let gap = app.last_canvas_rect.top() - strip.bottom();
+ assert!(gap.abs() < 0.1, "{kind:?}: document strip should touch canvas, got {gap} pt");
+ }
+ }
+
#[test]
fn large_tabs_preference_increases_tab_strip_height() {
use egui_kittest::kittest::Queryable;
diff --git a/crates/ui-egui/src/scrollbars.rs b/crates/ui-egui/src/scrollbars.rs
index 77948d4ef..05f1edf58 100644
--- a/crates/ui-egui/src/scrollbars.rs
+++ b/crates/ui-egui/src/scrollbars.rs
@@ -397,7 +397,8 @@ mod tests {
assert!(c1[0] < c0[0] - 10.0, "{c0:?} -> {c1:?}");
} else {
assert!((len - (r.width() - THICKNESS)).abs() < 1.0, "the thumb fills the track: {len}");
- assert_eq!(c1, c0, "Overscroll off keeps a fitting image centred");
+ // Within float error: the fit zoom is not a round number for every canvas height.
+ assert!((c1[0] - c0[0]).abs() < 0.01 && (c1[1] - c0[1]).abs() < 0.01, "Overscroll off keeps a fitting image centred: {c0:?} -> {c1:?}");
}
}
}