Files
gridcraft/crates/ui-egui/tests/it/pivot_pane.rs
T
skylar taylor-barrick 41769f1d16 Migrate GridCraft to egui 0.37 (#2543)
* E37: migrate GridCraft to egui 0.37

Pin the reviewed fork and shared dependencies, adapt input and rendering to the
new frame lifecycle, and preserve bounded capture handling and font notices.
Add representative accessibility checks and meaningful control labels.

Validation: full repository CI passed all ten stages, with 2,249 tests passed,
zero failed and one existing timing test ignored. Native workflows and paired
performance qualification remain documented separately.

* egui037: record final published pins and local qualification

* M0.37: fix RTL clipping and preserve screenshot budgets

* test: share migrated GridCraft UI harness setup

* egui037: document migrated UI and regression contracts

* egui-037: align popup test fonts and avoid redundant tooltip probes
2026-10-25 14:55:00 -04:00

60 lines
2.4 KiB
Rust

//! Pivot field buttons use the surface color for the active theme.
use egui::{Color32, RawInput, Rect, Shape, pos2, vec2};
use gridcraft_engine::Session;
use gridcraft_ui_egui::theme;
use serde_json::json;
/// Builds a pivot report at D3 and returns the painted shapes after six frames in the caller's light or dark mode.
fn render_pivot_field_buttons(dark: bool) -> Vec<Shape> {
let mut session = Session::new();
session.new_workbook();
session.execute("range.setValues", json!({"range": "A1", "values": [["Region", "Sales"], ["East", 100], ["West", 80]]})).unwrap();
session
.execute("insert.pivotTable", json!({"source": "Sheet1!A1:B3", "destination": "Sheet1!D3", "rows": ["Region"], "values": ["Sales"]}))
.unwrap();
session.execute("selection.set", json!({"cell": "D3"})).unwrap();
let mut app = crate::common::app(session);
app.ui.dark = dark;
let ctx = egui::Context::default();
let mut output = egui::FullOutput::default();
for _ in 0..6 {
output = ctx.run_ui(RawInput { screen_rect: Some(Rect::from_min_size(pos2(0.0, 0.0), vec2(1200.0, 800.0))), ..Default::default() }, |ui| {
let ctx = ui.ctx().clone();
app.logic(&ctx);
app.ui(ui);
});
output.textures_delta.clear();
}
output.shapes.into_iter().map(|shape| shape.shape).collect()
}
fn field_button_fill(shapes: &[Shape], label: &str) -> Color32 {
let text = shapes
.iter()
.find_map(|shape| match shape {
Shape::Text(text) if text.galley.text() == label => Some(text),
_ => None,
})
.unwrap_or_else(|| panic!("pivot field button {label:?} was not painted"));
let text_rect = text.galley.rect.translate(text.pos.to_vec2());
shapes
.iter()
.filter_map(|shape| match shape {
Shape::Rect(rect) if rect.rect.contains(text_rect.center()) => Some(rect),
_ => None,
})
.min_by(|a, b| a.rect.area().total_cmp(&b.rect.area()))
.unwrap_or_else(|| panic!("pivot field button {label:?} has no painted background"))
.fill
}
#[test]
fn pivot_field_button_surfaces_follow_the_active_theme() {
for (dark, expected) in [(false, theme::Tokens::light().ribbon), (true, theme::Tokens::dark().ribbon)] {
let shapes = render_pivot_field_buttons(dark);
assert_eq!(field_button_fill(&shapes, "Region ▾"), expected, "dark mode: {dark}");
}
}