mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-31 06:06:48 -06:00
The status bar always showed Average, Count and Sum for a selection of several cells and had no menu. A right-click on it now opens a menu with Average, Count, Numerical Count, Minimum, Maximum and Sum, as in Excel. Average, Count and Sum are on by default; the other three are off. The text on the status bar can no longer be selected, so a right-click on the mode text or a statistic opens the menu as well. The zoom and view controls handle their own clicks as before. The choice is a preference set with the new view.statusBar command and kept in prefs.json. A prefs.json without it keeps the defaults.
61 lines
2.2 KiB
Rust
61 lines
2.2 KiB
Rust
//! Right-clicking the status bar opens a menu that turns its selection statistics on and off.
|
|
|
|
use egui::{Event, Modifiers, PointerButton, Pos2, pos2, vec2};
|
|
use egui_kittest::kittest::Queryable;
|
|
use gridcraft_engine::Session;
|
|
use gridcraft_ui_egui::SheetApp;
|
|
use serde_json::json;
|
|
|
|
type Harness = egui_kittest::Harness<'static, SheetApp>;
|
|
|
|
fn harness() -> Harness {
|
|
let mut session = Session::new();
|
|
session.new_workbook();
|
|
for (cell, input) in [("A1", "4"), ("A2", "-1"), ("A3", "9")] {
|
|
session.execute("cell.set", json!({"cell": cell, "input": input})).unwrap();
|
|
}
|
|
session.execute("selection.set", json!({"range": "A1:A3"})).unwrap();
|
|
let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 800.0)).build_ui_state(
|
|
|ui, app: &mut SheetApp| {
|
|
app.logic(ui.ctx());
|
|
app.ui(ui);
|
|
},
|
|
SheetApp::new(session, Default::default()),
|
|
);
|
|
h.run_steps(4);
|
|
h
|
|
}
|
|
|
|
fn right_click(h: &mut Harness, pos: Pos2) {
|
|
h.input_mut().events.push(Event::PointerMoved(pos));
|
|
h.run_steps(1);
|
|
for pressed in [true, false] {
|
|
h.input_mut().events.push(Event::PointerButton { pos, button: PointerButton::Secondary, pressed, modifiers: Modifiers::NONE });
|
|
h.run_steps(1);
|
|
}
|
|
h.run_steps(3);
|
|
}
|
|
|
|
#[test]
|
|
fn right_clicking_the_status_bar_turns_on_minimum() {
|
|
let mut h = harness();
|
|
assert!(h.query_by_label("Sum: 12").is_some(), "Sum is on by default");
|
|
assert!(h.query_by_label("Minimum: -1").is_none(), "Minimum is off by default");
|
|
// An empty stretch of the 26-point status bar, between the mode text and the statistics.
|
|
right_click(&mut h, pos2(300.0, 787.0));
|
|
h.get_by_label("Minimum").click();
|
|
h.run_steps(4);
|
|
assert!(h.state().session.prefs.status_bar.minimum);
|
|
assert!(h.query_by_label("Minimum: -1").is_some(), "the status bar shows the minimum of the selection");
|
|
}
|
|
|
|
#[test]
|
|
fn right_clicking_the_status_bar_text_opens_the_menu() {
|
|
for text in ["Sum: 12", "Ready"] {
|
|
let mut h = harness();
|
|
let pos = h.get_by_label(text).rect().center();
|
|
right_click(&mut h, pos);
|
|
assert!(h.query_by_label("Numerical Count").is_some(), "a right-click on {text:?} opens the statistics menu");
|
|
}
|
|
}
|