PhotoCraft: An open-source, photo editor written by scratch in pure Rust
fix(ui): panel footer buttons are no longer cut off at the bottom (part of #6238)
ArchersInteld27546970f5d
diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rsindex 2acbdf3c8..2719b3907 100644--- a/crates/ui-egui/src/widgets.rs+++ b/crates/ui-egui/src/widgets.rs@@ -183,6 +183,9 @@ pub fn panel_footer<R>(ui: &mut Ui, add: impl FnOnce(&mut Ui) -> R) -> R {ui.painter().line_segment([pos2(r.left() - m.left as f32, y), pos2(r.right() + m.right as f32, y)], Stroke::new(1.0, t.separator));let bar = Rect::from_min_size(pos2(r.left(), r.top() + 1.0), vec2(r.width(), FOOTER_BAR));let mut bar_ui = ui.new_child(egui::UiBuilder::new().max_rect(bar).layout(egui::Layout::right_to_left(egui::Align::Center)));+ // The bar runs on over the body's bottom margin, past where the body's own clip ends: without+ // this its buttons were cut off there, a 26 px hover highlight drawn about 21 px tall.+ bar_ui.set_clip_rect(bar_ui.clip_rect().union(bar));bar_ui.spacing_mut().item_spacing.x = 2.0;add(&mut bar_ui)}@@ -1863,6 +1866,32 @@ mod tests {}use egui_kittest::{Harness, kittest::Queryable};+ /// A panel footer's buttons are drawn whole. The bar runs on over the body's bottom margin, so a+ /// body that clips where its content ends (as the panels do) cut the bottom off every button:+ /// the hover highlight of a 26 px button was about 21 px tall in the Paths, Layers and Channels+ /// panels (#6238).+ #[test]+ fn panel_footer_buttons_are_not_clipped_by_the_body() {+ let mut h = Harness::new_ui_state(+ |ui, s: &mut Option<(egui::Rect, egui::Rect, egui::Rect)>| {+ // A body exactly as tall as the footer takes, clipped there.+ let body = egui::Rect::from_min_size(ui.max_rect().min, egui::vec2(220.0, super::footer_height(ui)));+ let mut body_ui = ui.new_child(egui::UiBuilder::new().max_rect(body));+ body_ui.set_clip_rect(body);+ super::panel_footer(&mut body_ui, |bar| {+ let b = crate::icons::button(bar, "square", 26.0, false, "Button");+ *s = Some((b.rect, bar.clip_rect(), body));+ });+ },+ None,+ );+ crate::PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::Studio);+ h.run();+ let (button, clip, body) = h.state().expect("the footer drew its button");+ assert!(button.bottom() > body.bottom(), "the bar really overruns the body, or this test proves nothing: {button:?} vs {body:?}");+ assert!(clip.contains_rect(button), "the whole button is inside the clip: {button:?} not in {clip:?}");+ }+/// #3789: a plain text field is one boxed, outline-free input whose text-selection colour stays/// local, so it isn't recoloured for the rest of the frame (selected rows, slider trails).#[test]