v0.5.1: fix monitor Layout

This commit is contained in:
GABRIEL Sebastian 2026-11-12 14:10:46 +01:00
commit 3be878804b
7 changed files with 606 additions and 395 deletions

View file

@ -35,12 +35,9 @@ 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);
// NIBP occupies a dedicated box at the bottom of the numerical right column.
// Trace rows remain full height on the left.
let nibp_box_height = if p.show_nibp { (h * 0.24).clamp(135.0, 210.0).min(body_height * 0.55) }
else { 0.0 };
let trace_row_height = body_height / channels.len().max(1) as f64;
let vital_row_height = (body_height - nibp_box_height) / channels.len().max(1) as f64;
// 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;
let trace_left = pad + 6.0;
@ -67,26 +64,35 @@ pub fn draw(cr: &Context, width: i32, height: i32, p: &Parameters, sim: &Simulat
stroke_line(cr, split_x, header, split_x, h - pad, MUTED, 0.9);
for (index, (channel, title, color)) in channels.iter().copied().enumerate() {
let top = header + index as f64 * trace_row_height;
let bottom = top + trace_row_height;
stroke_line(cr, pad, bottom, split_x, bottom, MUTED, 0.65);
text(cr, title, trace_left + 4.0, top + trace_row_height * 0.17,
(trace_row_height * 0.11).clamp(10.0, 17.0), color, false);
let top = header + index as f64 * row_height;
let bottom = top + row_height;
stroke_line(cr, pad, bottom, w - pad, bottom, MUTED, 0.65);
text(cr, title, trace_left + 4.0, top + row_height * 0.17,
(row_height * 0.11).clamp(10.0, 17.0), color, false);
draw_trace(cr, channel, color, trace_left, trace_right,
top + trace_row_height * 0.25, bottom - trace_row_height * 0.06, p, sim);
let vital_top = header + index as f64 * vital_row_height;
stroke_line(cr, split_x, vital_top + vital_row_height,
w - pad, vital_top + vital_row_height, MUTED, 0.65);
top + row_height * 0.25, bottom - row_height * 0.06, p, sim);
draw_vitals(cr, channel, color, split_x + pad,
vital_top, vital_row_height, sidebar - 2.0 * pad, p, sim);
top, row_height, sidebar - 2.0 * pad, p, sim);
}
if p.show_nibp {
draw_nibp_box(cr, split_x + pad, h - pad - nibp_box_height,
sidebar - 2.0 * pad, nibp_box_height, 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);
}
}
/// 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)
}
fn draw_nibp_box(cr: &Context, x: f64, top: f64, width: f64, height: f64,
p: &Parameters, sim: &Simulator) {
let right = x + width;
@ -548,6 +554,29 @@ fn text(cr: &Context, value: &str, x: f64, baseline: f64,
mod tests {
use super::*;
#[test]
fn monitor_rows_align_waveforms_and_numbers_with_blank_nibp_left_cell() {
let header = 60.0;
let body_height = 700.0;
let (height, nibp_top) = monitor_rows(header, body_height, 4, true);
assert_eq!(height, 140.0);
assert_eq!(nibp_top, Some(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);
}
#[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));
}
#[test]
fn alarm_states_do_not_trigger_for_unavailable_readouts() {
let p = Parameters::default();