v0.5.7 — Four-group numerical measurement row

This commit is contained in:
GABRIEL Sebastian 2026-11-12 16:02:08 +01:00
commit a09cd2c4ee
7 changed files with 478 additions and 47 deletions

View file

@ -35,13 +35,13 @@ pub fn draw(cr: &Context, width: i32, height: i32, p: &Parameters, sim: &Simulat
let header = (h * 0.083).clamp(32.0, 68.0);
let channels = visible_channels(p);
let body_height = (h - header - pad).max(20.0);
// A single grid governs both columns. NIBP has an empty waveform cell
// on the left, so all numeric boxes line up with their waveform rows.
let (row_height, nibp_top) = monitor_rows(header, body_height, channels.len(), p.show_nibp);
let sidebar = (w * 0.235).clamp(125.0, 370.0).min(w * 0.44);
let split_x = w - sidebar - pad;
// Waveforms occupy three quarters of the drawable width and numeric
// values one quarter. The final row is four equal-sized numeric cells.
let (row_height, measurements_top) = monitor_rows(header, body_height, channels.len());
let (split_x, quarter_width) = monitor_columns(w, pad);
let numeric_width = (quarter_width - 2.0 * pad).max(1.0);
let trace_left = pad + 6.0;
let trace_right = (split_x - pad).max(trace_left + 40.0);
let trace_right = (split_x - pad).max(trace_left + 1.0);
let text_scale = (w.min(h * 1.7) / 850.0).clamp(0.65, 1.5);
let patient_title = if p.patient_name.trim().is_empty() {
@ -72,25 +72,58 @@ pub fn draw(cr: &Context, width: i32, height: i32, p: &Parameters, sim: &Simulat
draw_trace(cr, channel, color, trace_left, trace_right,
top + row_height * 0.25, bottom - row_height * 0.06, p, sim);
draw_vitals(cr, channel, color, split_x + pad,
top, row_height, sidebar - 2.0 * pad, p, sim);
top, row_height, numeric_width, p, sim);
}
if let Some(top) = nibp_top {
// Intentionally blank waveform cell to the left of the NIBP box.
stroke_line(cr, pad, top + row_height, w - pad, top + row_height, MUTED, 0.65);
draw_nibp_box(cr, split_x + pad, top,
sidebar - 2.0 * pad, row_height, p, sim);
}
// The last row contains four adjacent measurement groups, each spanning
// exactly one quarter of the drawable width. The fourth is the normal
// right-hand NIBP numeric column. The other groups are future placeholders.
draw_measurements_row(cr, pad, measurements_top, row_height, quarter_width,
numeric_width, p, sim);
}
/// Compute the same row boundaries for the waveform and numeric columns.
/// NIBP, when visible, occupies the final row and leaves its left cell empty.
fn monitor_rows(header: f64, body_height: f64, trace_count: usize, show_nibp: bool)
-> (f64, Option<f64>) {
let row_count = trace_count + usize::from(show_nibp);
let row_height = body_height / row_count.max(1) as f64;
let nibp_top = show_nibp.then_some(header + trace_count as f64 * row_height);
(row_height, nibp_top)
/// Left/right split and the width of each bottom-row group. Outer margins
/// are excluded, so 75% / 25% holds at all window sizes (no width clamping).
fn monitor_columns(window_width: f64, pad: f64) -> (f64, f64) {
let quarter_width = (window_width - 2.0 * pad).max(1.0) / 4.0;
(pad + 3.0 * quarter_width, quarter_width)
}
/// The bottom measurement row always exists, even when NIBP is hidden: the
/// remaining three groups are reserved for future parameters. Waveform rows
/// above it still reflow when individual channels are hidden.
fn monitor_rows(header: f64, body_height: f64, trace_count: usize) -> (f64, f64) {
let row_height = body_height / (trace_count + 1) as f64;
let measurements_top = header + trace_count as f64 * row_height;
(row_height, measurements_top)
}
const FUTURE_MEASUREMENT_LABELS: [&str; 3] = ["CO / CI", "SVRI · GEDI · ELWI", ""];
#[allow(clippy::too_many_arguments)]
fn draw_measurements_row(cr: &Context, left: f64, top: f64, height: f64,
quarter_width: f64, numeric_width: f64,
p: &Parameters, sim: &Simulator) {
let bottom = top + height;
stroke_line(cr, left, bottom, left + 4.0 * quarter_width, bottom, MUTED, 0.65);
let label_size = (height * 0.135).clamp(11.0, 19.0);
for (index, label) in FUTURE_MEASUREMENT_LABELS.iter().enumerate() {
let cell_left = left + index as f64 * quarter_width;
if index > 0 {
stroke_line(cr, cell_left, top, cell_left, bottom, MUTED, 0.65);
}
if !label.is_empty() {
// Placeholder labels only: no numerical values or simulated data.
fitted_text(cr, label, cell_left + quarter_width * 0.06,
top + height * 0.24, label_size,
quarter_width * 0.88, LIGHT_GREY);
}
}
// The existing global column separator supplies the fourth divider.
if p.show_nibp {
draw_nibp_box(cr, left + 3.0 * quarter_width + (quarter_width - numeric_width) * 0.5, top,
numeric_width, height, p, sim);
}
}
fn draw_nibp_box(cr: &Context, x: f64, top: f64, width: f64, height: f64,
@ -555,26 +588,41 @@ mod tests {
use super::*;
#[test]
fn monitor_rows_align_waveforms_and_numbers_with_blank_nibp_left_cell() {
fn monitor_rows_align_waveforms_and_bottom_measurements() {
let header = 60.0;
let body_height = 700.0;
let (height, nibp_top) = monitor_rows(header, body_height, 4, true);
let (height, measurements_top) = monitor_rows(header, body_height, 4);
assert_eq!(height, 140.0);
assert_eq!(nibp_top, Some(620.0));
assert_eq!(measurements_top, 620.0);
// Every waveform row and its corresponding numeric row share boundaries.
for index in 0..4 {
let top = header + index as f64 * height;
let bottom = top + height;
assert_eq!(bottom, header + (index + 1) as f64 * height);
}
assert_eq!(nibp_top.unwrap() + height, header + body_height);
assert_eq!(measurements_top + height, header + body_height);
}
#[test]
fn monitor_rows_reflow_when_nibp_or_waveforms_are_hidden() {
assert_eq!(monitor_rows(60.0, 700.0, 4, false), (175.0, None));
assert_eq!(monitor_rows(60.0, 700.0, 0, true), (700.0, Some(60.0)));
assert_eq!(monitor_rows(60.0, 700.0, 0, false), (700.0, None));
fn bottom_measurements_remain_when_nibp_or_waveforms_are_hidden() {
// Hiding NIBP only clears the fourth cell; the placeholders stay.
assert_eq!(monitor_rows(60.0, 700.0, 4), (140.0, 620.0));
assert_eq!(monitor_rows(60.0, 700.0, 2), (700.0 / 3.0, 60.0 + 2.0 * (700.0 / 3.0)));
assert_eq!(monitor_rows(60.0, 700.0, 0), (700.0, 60.0));
}
#[test]
fn waveform_split_is_three_quarters_and_bottom_groups_are_equal() {
for (width, pad) in [(800.0, 10.0), (1280.0, 20.0), (2560.0, 20.0)] {
let (split, group) = monitor_columns(width, pad);
let usable = width - 2.0 * pad;
assert!((split - (pad + 0.75 * usable)).abs() < 1e-9);
assert!((group - 0.25 * usable).abs() < 1e-9);
assert!((split - (pad + 3.0 * group)).abs() < 1e-9);
assert!((pad + 4.0 * group - (width - pad)).abs() < 1e-9);
}
assert_eq!(FUTURE_MEASUREMENT_LABELS,
["CO / CI", "SVRI · GEDI · ELWI", ""]);
}
#[test]