--- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "patient-monitor-simulation" -version = "0.6.2" +version = "0.6.3" edition = "2021" license = "MIT" description = "Synthetic patient-monitor simulation for teaching (not for clinical use)" --- a/README.de.md +++ b/README.de.md @@ -1,4 +1,4 @@ -# Patient Monitor Simulation (PaMSim) — v0.6.2 +# Patient Monitor Simulation (PaMSim) — v0.6.3 Ein mit Rust und GTK4 entwickelter Patient*innenmonitor-Simulator mit zwei Fenstern für die Lehre unter Fedora Linux. @@ -73,16 +73,18 @@ auch bei ausgeschalteter Automatik. Dann bleibt die Intervallanzeige leer und der Monitor zeigt `AUTO OFF`. -### Anordnung der ART-Alarmgrenzen (v0.6.2) - -Das Touchmenü für die invasive arterielle Druckmessung ordnet **SYS, MAP und -DIA** in drei Spalten an. Die obere Bedienzeile enthält die **oberen (↑)** -Alarmgrenzen, die zweite die **unteren (↓)** Alarmgrenzen. **PPV** folgt unter -SYS mit eigenen oberen und unteren Grenzwerten. Die bisherigen großen -**+ / Wert / − / EIN-AUS**-Schaltflächen und ihre Bedienlogik bleiben erhalten. -Die Gestaltung verwendet weiterhin Schwarz, Hellgrau und schmale Rahmenlinien. -Alle anderen Parametermenüs bleiben unverändert. Alarmverarbeitung und -Voreinstellungen sind von dieser Layoutänderung nicht betroffen. +### Horizontale Matrix für Alarmgrenzen (v0.6.3) + +Alle fünf Touchmenüs des Monitors verwenden dieselbe kompakte Matrix. +Jeder Parameter belegt eine Zeile (bei ART: **SYS**, **MAP**, **DIA**, +**PPV**); die **untere (↓)** und **obere (↑)** Alarmgrenze stehen +nebeneinander. Die Schaltflächen jedes Grenzwerts sind von links nach +rechts **+ · Wert · − · OFF/ON** angeordnet. Die Schaltfläche zum +Deaktivieren liegt unmittelbar rechts von Minus. Größe, Gestaltung, +Schrittweite, Wiederherstellung des letzten Werts sowie Apply/Cancel +bleiben erhalten. Bei Platzmangel lässt sich die Matrix scrollen, während +Apply und Cancel zugänglich bleiben. Andere Einstellungen bleiben dem +Admin-Fenster vorbehalten. ## Thoraxkompressionen (v0.5.4) --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Patient Monitor Simulation (PaMSim) — v0.6.2 +# Patient Monitor Simulation (PaMSim) — v0.6.3 A Rust/GTK4 patient-monitor simulator with two main windows for teaching on Fedora Linux. @@ -67,16 +67,17 @@ is off. The interval bar is empty and the monitor displays `AUTO OFF` whenever automatic measurements are disabled. -### ART alarm-limit arrangement (v0.6.2) - -The ART touchscreen alarm panel groups **SYS, MAP and DIA** in three -side-by-side columns. The first control row adjusts their **upper (↑)** limits; -the second adjusts their **lower (↓)** limits. **PPV** appears below SYS, with -its own upper and lower controls. Each bound retains the existing large -**+ / value / − / ON-OFF** buttons, including previous-value restoration. -The groups share the monitor's neutral black/grey palette and thin borders. -All other module menus retain their previous arrangement. This is a layout -change only; thresholds, presets and alarm evaluation are unchanged. +### Horizontal touchscreen alarm matrix (v0.6.3) + +All five monitor touch menus now share a compact horizontal alarm-limit matrix. +Each parameter occupies its own row (for ART: **SYS**, **MAP**, **DIA**, +**PPV**), with **↓ Lower** and **↑ Upper** displayed in adjacent columns. +Within each limit cell, the touch controls are ordered **+ · value · − · +OFF/ON** (the OFF/ON button is immediately right of minus). The original +large button styling, per-parameter increments, last-value restoration, +optional bounds and Apply/Cancel semantics are unchanged. The matrix scrolls +if necessary while Apply and Cancel remain accessible below it. Other +physiological and NIBP controls remain Admin-only. ## Chest compressions (v0.5.4) --- a/src/ui.rs +++ b/src/ui.rs @@ -122,12 +122,9 @@ let p = params.borrow(); render::monitor_hit_test(x, y, canvas.width(), canvas.height(), &p) }; - match touched { - Some(render::TouchChannel::Ecg) => open_ecg_menu(&app, &window, - params.clone(), admin_changed.clone(), monitor_menu.clone()), - Some(channel) => open_module_menu(&app, &window, params.clone(), - admin_changed.clone(), monitor_menu.clone(), channel), - None => (), + if let Some(channel) = touched { + open_module_menu(&app, &window, params.clone(), + admin_changed.clone(), monitor_menu.clone(), channel); } } }); @@ -609,14 +606,14 @@ color: #000000; background-color: #e5e9eb; font-weight: bold; } window.ecg-settings button.ecg-close { background-color: #171717; } - window.ecg-settings box.art-limit-frame { + window.ecg-settings box.alarm-limit-frame { border: 0.8px solid #6b757d; padding: 12px; } - window.ecg-settings label.art-limit-heading { + window.ecg-settings label.alarm-limit-heading { font-weight: bold; font-size: 17px; } - window.ecg-settings label.art-limit-arrow { - font-size: 21px; + window.ecg-settings label.alarm-limit-column-heading { + font-size: 15px; font-weight: bold; }" ); gtk::style_context_add_provider_for_display( @@ -641,14 +638,12 @@ separator } -const TOUCH_HR_STEP: i32 = 5; -const MAX_HR_ALARM: i32 = 240; - -/// When a limit is OFF, either +/- first restores its previous value (or -/// a sensible initial value). Subsequent presses adjust it by 5 bpm. -fn stepped_hr_limit(current: Option, last_enabled: i32, direction: i32) -> i32 { - current.map_or(last_enabled, |value| { - (value + TOUCH_HR_STEP * direction).clamp(0, MAX_HR_ALARM) +/// Apply a touchscreen step to an alarm value. When the alarm is disabled, +/// either +/- first restores its last enabled value (unchanged behavior). +fn stepped_alarm_limit(current: Option, previous: i32, + direction: i32, step: i32, maximum: i32) -> i32 { + current.map_or(previous, |value| { + (value + step * direction).clamp(0, maximum) }) } @@ -658,200 +653,23 @@ toggle.set_label(if value.is_some() { "OFF" } else { "ON" }); } -/// Large, keyboard-free +/- and ON/OFF controls. Returning a Cell permits -/// Apply to read the draft value without changing the shared configuration. -fn ecg_touch_limit(parent: >k::Box, caption: &str, - initial: Option, default: i32) -> Rc>> { - let state = Rc::new(Cell::new(initial)); - let previous = Rc::new(Cell::new(initial.unwrap_or(default))); - let row = gtk::Box::new(Orientation::Horizontal, 10); - - let heading = gtk::Label::new(Some(caption)); - heading.set_xalign(0.0); - heading.set_width_chars(10); - row.append(&heading); - - let minus = gtk::Button::with_label("−"); - minus.set_tooltip_text(Some("Decrease alarm limit by 5 bpm")); - minus.set_size_request(54, 50); - row.append(&minus); - - let display = gtk::Label::new(None); - display.add_css_class("ecg-limit-value"); - display.set_width_chars(5); - display.set_xalign(0.5); - row.append(&display); - - let plus = gtk::Button::with_label("+"); - plus.set_tooltip_text(Some("Increase alarm limit by 5 bpm")); - plus.set_size_request(54, 50); - row.append(&plus); - - let enable_toggle = gtk::Button::new(); - enable_toggle.set_tooltip_text(Some("Enable or disable this alarm limit")); - enable_toggle.set_size_request(78, 50); - row.append(&enable_toggle); - show_touch_hr_limit(initial, &display, &enable_toggle); - - for (button, direction) in [(minus, -1), (plus, 1)] { - let state = state.clone(); - let previous = previous.clone(); - let display = display.clone(); - let enable_toggle = enable_toggle.clone(); - button.connect_clicked(move |_| { - let next = stepped_hr_limit(state.get(), previous.get(), direction); - state.set(Some(next)); - previous.set(next); - show_touch_hr_limit(Some(next), &display, &enable_toggle); - }); - } - enable_toggle.connect_clicked({ - let state = state.clone(); - let previous = previous.clone(); - let display = display.clone(); - move |button| { - let new_value = match state.get() { - Some(value) => { - previous.set(value); - None - } - None => Some(previous.get()), - }; - state.set(new_value); - show_touch_hr_limit(new_value, &display, button); - } - }); - parent.append(&row); - state -} - -/// Displayed only for touches in the ECG row. The monitor window can remain -/// fullscreen. The dialog is modal to that monitor, including on Wayland. -fn open_ecg_menu(app: &Application, monitor: &ApplicationWindow, - params: SharedParams, on_change: AdminChanged, - open_menu: MonitorMenuHandle) { - if let Some(existing) = open_menu.borrow().as_ref().and_then(|weak| weak.upgrade()) { - existing.present(); - return; - } - let limits = params.borrow().alarms.hr; - let dialog = gtk::Window::builder() - .application(app) - .title("ECG settings") - .transient_for(monitor) - .modal(true) - .resizable(false) - .default_width(550) - .default_height(345) - .build(); - dialog.add_css_class("ecg-settings"); - dialog.set_decorated(false); - *open_menu.borrow_mut() = Some(dialog.downgrade()); - - let content = gtk::Box::new(Orientation::Vertical, 12); - content.add_css_class("ecg-panel"); - content.set_margin_top(1); - content.set_margin_bottom(1); - content.set_margin_start(1); - content.set_margin_end(1); - // Inner padding keeps controls away from the thin panel border. - let inner = gtk::Box::new(Orientation::Vertical, 12); - inner.set_margin_top(20); - inner.set_margin_bottom(20); - inner.set_margin_start(20); - inner.set_margin_end(20); - content.append(&inner); - - let title = gtk::Label::new(Some("ECG / SETTINGS")); - title.set_xalign(0.0); - title.add_css_class("title-2"); - inner.append(&title); - inner.append(&ecg_menu_divider()); - - let limits_header = gtk::Label::new(Some("HR alarm limits · bpm")); - limits_header.set_xalign(0.0); - inner.append(&limits_header); - let lower = ecg_touch_limit(&inner, "↓ Lower", limits.lower, 60); - let upper = ecg_touch_limit(&inner, "↑ Upper", limits.upper, 100); - let hint = gtk::Label::new(Some( - "+/− adjusts by 5 bpm. OFF disables the limit; ON restores it." - )); - hint.set_wrap(true); - hint.set_xalign(0.0); - inner.append(&hint); - inner.append(&ecg_menu_divider()); - - let error = gtk::Label::new(None); - error.add_css_class("menu-error"); - error.set_xalign(0.0); - error.set_wrap(true); - inner.append(&error); - - let buttons = gtk::Box::new(Orientation::Horizontal, 12); - buttons.set_halign(gtk::Align::End); - let cancel = gtk::Button::with_label("Cancel"); - cancel.add_css_class("ecg-close"); - cancel.connect_clicked({ - let weak = dialog.downgrade(); - move |_| { if let Some(window) = weak.upgrade() { window.close(); } } - }); - let apply = gtk::Button::with_label("Apply"); - apply.add_css_class("ecg-apply"); - apply.connect_clicked({ - let weak = dialog.downgrade(); - move |_| { - let new_limits = AlarmLimits { lower: lower.get(), upper: upper.get() }; - if !new_limits.valid() { - error.set_text("The lower limit must not exceed the upper limit."); - return; - } - let alarm_changed = { - let mut p = params.borrow_mut(); - let changed = p.alarms.hr != new_limits; - p.alarms.hr = new_limits; - changed - }; - if let Some(callback) = on_change.borrow().as_ref() { - callback(alarm_changed); - } - if let Some(window) = weak.upgrade() { window.close(); } - } - }); - buttons.append(&cancel); - buttons.append(&apply); - inner.append(&buttons); - dialog.set_child(Some(&content)); - - let escape = gtk::EventControllerKey::new(); - escape.connect_key_pressed({ - let weak = dialog.downgrade(); - move |_, key, _, _| { - if key == gdk::Key::Escape { - if let Some(window) = weak.upgrade() { window.close(); } - glib::Propagation::Stop - } else { glib::Propagation::Proceed } - } - }); - dialog.add_controller(escape); - dialog.present(); -} - #[cfg(test)] mod ecg_touch_menu_tests { use super::*; #[test] - fn touch_step_uses_five_bpm_and_respects_bounds() { - assert_eq!(stepped_hr_limit(Some(60), 60, 1), 65); - assert_eq!(stepped_hr_limit(Some(60), 60, -1), 55); - assert_eq!(stepped_hr_limit(Some(240), 240, 1), 240); - assert_eq!(stepped_hr_limit(Some(0), 0, -1), 0); + fn touch_step_preserves_per_parameter_increment_and_bounds() { + assert_eq!(stepped_alarm_limit(Some(60), 60, 1, 5, 240), 65); + assert_eq!(stepped_alarm_limit(Some(60), 60, -1, 5, 240), 55); + assert_eq!(stepped_alarm_limit(Some(240), 240, 1, 5, 240), 240); + assert_eq!(stepped_alarm_limit(Some(0), 0, -1, 5, 240), 0); + assert_eq!(stepped_alarm_limit(Some(90), 90, 1, 1, 100), 91); } #[test] fn disabled_alarm_reenables_at_last_saved_value() { - assert_eq!(stepped_hr_limit(None, 60, 1), 60); - assert_eq!(stepped_hr_limit(None, 100, -1), 100); + assert_eq!(stepped_alarm_limit(None, 60, 1, 5, 240), 60); + assert_eq!(stepped_alarm_limit(None, 100, -1, 5, 240), 100); } #[test] @@ -896,6 +714,9 @@ }; } match channel { + render::TouchChannel::Ecg => { + limits!("HR", "bpm", hr, 240, 5, 60, 100); + } render::TouchChannel::Spo2 => { limits!("SpO₂", "%", spo2, 100, 1, 90, 100); limits!("Pulse rate", "bpm", pr, 240, 5, 50, 120); @@ -915,102 +736,40 @@ limits!("NIBP MAP", "mmHg", nibp_map, 260, 5, 60, 100); limits!("NIBP diastolic", "mmHg", nibp_dia, 260, 5, 40, 100); } - render::TouchChannel::Ecg => {} } specs } -/// Generic unit-aware limit control with large +/- and ON/OFF touch buttons. -/// Unlike the ECG-only helper, the increment and permitted range are per value. +/// A compact alarm-limit cell: [+] value [−] [OFF/ON]. Its buttons retain +/// the old size/style, step size, last-value restoration and draft semantics. #[allow(clippy::too_many_arguments)] -fn module_touch_limit(parent: >k::Box, caption: &str, initial: Option, - fallback: i32, step: i32, maximum: i32) -> Rc>> { +fn alarm_matrix_cell(initial: Option, fallback: i32, step: i32, + maximum: i32) -> (gtk::Box, Rc>>) { let state = Rc::new(Cell::new(initial)); let previous = Rc::new(Cell::new(initial.unwrap_or(fallback))); - let row = gtk::Box::new(Orientation::Horizontal, 10); - let caption_label = gtk::Label::new(Some(caption)); - caption_label.set_width_chars(10); - caption_label.set_xalign(0.0); - row.append(&caption_label); - let minus = gtk::Button::with_label("−"); - minus.set_size_request(54, 50); - let display = gtk::Label::new(None); - display.add_css_class("ecg-limit-value"); - display.set_xalign(0.5); - display.set_width_chars(5); + let controls = gtk::Box::new(Orientation::Horizontal, 5); + controls.set_hexpand(true); + controls.set_halign(gtk::Align::Center); + let plus = gtk::Button::with_label("+"); plus.set_size_request(54, 50); - let toggle = gtk::Button::new(); - toggle.set_size_request(78, 50); - show_touch_hr_limit(initial, &display, &toggle); - row.append(&minus); - row.append(&display); - row.append(&plus); - row.append(&toggle); - for (button, direction) in [(minus, -1), (plus, 1)] { - let state = state.clone(); - let previous = previous.clone(); - let display = display.clone(); - let toggle = toggle.clone(); - button.connect_clicked(move |_| { - let new_value = state.get().map_or(previous.get(), |current| { - (current + direction * step).clamp(0, maximum) - }); - state.set(Some(new_value)); - previous.set(new_value); - show_touch_hr_limit(Some(new_value), &display, &toggle); - }); - } - toggle.connect_clicked({ - let state = state.clone(); - let previous = previous.clone(); - let display = display.clone(); - move |button| { - let new_value = match state.get() { - Some(value) => { previous.set(value); None } - None => Some(previous.get()), - }; - state.set(new_value); - show_touch_hr_limit(new_value, &display, button); - } - }); - parent.append(&row); - state -} - -/// ART-only keyboard-free limit editor: the existing button appearance and -/// callback semantics are retained, but its widgets are stacked vertically -/// for the SYS/MAP/DIA columns and the PPV controls below them. -#[allow(clippy::too_many_arguments)] -fn art_touch_limit(grid: >k::Grid, column: i32, row: i32, - initial: Option, fallback: i32, - step: i32, maximum: i32) -> Rc>> { - let state = Rc::new(Cell::new(initial)); - let previous = Rc::new(Cell::new(initial.unwrap_or(fallback))); - let controls = gtk::Box::new(Orientation::Vertical, 7); - controls.set_halign(gtk::Align::Center); - controls.set_hexpand(true); - - let plus = gtk::Button::with_label("+"); - plus.set_size_request(54, 50); - plus.set_halign(gtk::Align::Center); - controls.append(&plus); - + plus.set_tooltip_text(Some("Increase alarm limit")); let display = gtk::Label::new(None); display.add_css_class("ecg-limit-value"); display.set_width_chars(5); display.set_xalign(0.5); - controls.append(&display); - let minus = gtk::Button::with_label("−"); minus.set_size_request(54, 50); - minus.set_halign(gtk::Align::Center); - controls.append(&minus); - + minus.set_tooltip_text(Some("Decrease alarm limit")); let toggle = gtk::Button::new(); toggle.set_size_request(78, 50); - toggle.set_halign(gtk::Align::Center); + toggle.set_tooltip_text(Some("Enable or disable this alarm limit")); show_touch_hr_limit(initial, &display, &toggle); + + // Requested left-to-right order: plus, value, minus, OFF. + controls.append(&plus); + controls.append(&display); + controls.append(&minus); controls.append(&toggle); for (button, direction) in [(plus, 1), (minus, -1)] { @@ -1019,12 +778,11 @@ let display = display.clone(); let toggle = toggle.clone(); button.connect_clicked(move |_| { - let new_value = state.get().map_or(previous.get(), |current| { - (current + direction * step).clamp(0, maximum) - }); - state.set(Some(new_value)); - previous.set(new_value); - show_touch_hr_limit(Some(new_value), &display, &toggle); + let next = stepped_alarm_limit(state.get(), previous.get(), + direction, step, maximum); + state.set(Some(next)); + previous.set(next); + show_touch_hr_limit(Some(next), &display, &toggle); }); } toggle.connect_clicked({ @@ -1032,65 +790,74 @@ let previous = previous.clone(); let display = display.clone(); move |button| { - let new_value = match state.get() { + let next = match state.get() { Some(value) => { previous.set(value); None } None => Some(previous.get()), }; - state.set(new_value); - show_touch_hr_limit(new_value, &display, button); - } - }); - grid.attach(&controls, column, row, 1, 1); - state -} - -/// Map the four ART parameters to the three-column alarm grid. Row 1 is -/// upper thresholds, row 2 lower; PPV occupies column SYS in rows 4 and 5. -fn art_alarm_position(index: usize) -> (i32, i32, i32, i32, &'static str) { - match index { - 0 => (1, 0, 1, 2, "SYS"), - 1 => (2, 0, 1, 2, "MAP"), - 2 => (3, 0, 1, 2, "DIA"), - 3 => (1, 3, 4, 5, "PPV"), - _ => unreachable!("ART has exactly four alarm parameters"), - } -} - -/// The ART alarm menu groups SYS/MAP/DIA into columns with upper limits in -/// the first row and lower limits in the second; PPV occupies the first -/// parameter column beneath them. It reuses the same alarm draft/Apply path. -fn art_alarm_grid(specs: Vec, drafts: &mut Vec) -> gtk::Box { - let frame = gtk::Box::new(Orientation::Vertical, 16); - frame.add_css_class("art-limit-frame"); + state.set(next); + show_touch_hr_limit(next, &display, button); + } + }); + (controls, state) +} + +/// Short names in the alarm matrix; full labels remain available as tooltips. +fn alarm_matrix_label(name: &str) -> &str { + match name { + "ART systolic" | "NIBP systolic" => "SYS", + "ART MAP" | "NIBP MAP" => "MAP", + "ART diastolic" | "NIBP diastolic" => "DIA", + "Pulse rate" => "PR", + "Respiratory rate" => "RR", + other => other, + } +} + +/// Common touchscreen matrix for ECG, SpO2, ART, CO2 and NIBP. +/// Each parameter occupies one horizontal row; lower and upper limits have +/// identical columns and the action order [+] value [−] [OFF/ON]. +fn alarm_limit_matrix(specs: Vec, + drafts: &mut Vec) -> gtk::Box { + let frame = gtk::Box::new(Orientation::Vertical, 8); + frame.add_css_class("alarm-limit-frame"); frame.set_hexpand(true); let heading = gtk::Label::new(Some("Alarm Limits")); - heading.add_css_class("art-limit-heading"); + heading.add_css_class("alarm-limit-heading"); heading.set_xalign(0.0); frame.append(&heading); let grid = gtk::Grid::new(); grid.set_hexpand(true); - grid.set_column_spacing(12); - grid.set_row_spacing(23); - - for (row, arrow) in [(1, "↑"), (2, "↓"), (4, "↑"), (5, "↓")] { - let label = gtk::Label::new(Some(arrow)); - label.add_css_class("art-limit-arrow"); - label.set_width_chars(2); - grid.attach(&label, 0, row, 1, 1); - } - for (i, spec) in specs.into_iter().enumerate() { - let (column, title_row, upper_row, lower_row, title) = art_alarm_position(i); - let label = gtk::Label::new(Some(title)); - label.add_css_class("art-limit-heading"); - label.set_hexpand(true); - grid.attach(&label, column, title_row, 1, 1); - - let upper = art_touch_limit(&grid, column, upper_row, spec.limits.upper, + grid.set_column_spacing(8); + grid.set_row_spacing(8); + + for (column, text) in [(1, "↓ Lower"), (2, "↑ Upper")] { + let label = gtk::Label::new(Some(text)); + label.add_css_class("alarm-limit-column-heading"); + label.set_halign(gtk::Align::Center); + grid.attach(&label, column, 0, 1, 1); + } + + for (index, spec) in specs.into_iter().enumerate() { + // An empty narrow divider row keeps each parameter visually distinct. + let base = 1 + (index as i32) * 2; + if index > 0 { + grid.attach(&ecg_menu_divider(), 0, base - 1, 3, 1); + } + let label = gtk::Label::new(Some(alarm_matrix_label(spec.name))); + label.set_xalign(0.0); + label.set_tooltip_text(Some(&format!("{} ({})", spec.name, spec.unit))); + label.add_css_class("alarm-limit-heading"); + label.set_width_chars(5); + grid.attach(&label, 0, base, 1, 1); + + let (lower_controls, lower) = alarm_matrix_cell(spec.limits.lower, + spec.restore_lower, spec.step, spec.maximum); + let (upper_controls, upper) = alarm_matrix_cell(spec.limits.upper, spec.restore_upper, spec.step, spec.maximum); - let lower = art_touch_limit(&grid, column, lower_row, spec.limits.lower, - spec.restore_lower, spec.step, spec.maximum); + grid.attach(&lower_controls, 1, base, 1, 1); + grid.attach(&upper_controls, 2, base, 1, 1); drafts.push(TouchAlarmDraft { name: spec.name, lower, upper, apply: spec.apply, }); @@ -1128,7 +895,7 @@ render::TouchChannel::Art => "ART / SETTINGS", render::TouchChannel::Capno => "CO₂ / SETTINGS", render::TouchChannel::Nibp => "NIBP / SETTINGS", - render::TouchChannel::Ecg => return, + render::TouchChannel::Ecg => "ECG / SETTINGS", }; let dialog = gtk::Window::builder() .application(app) @@ -1136,8 +903,13 @@ .transient_for(monitor) .modal(true) .resizable(true) - .default_width(if channel == render::TouchChannel::Art { 720 } else { 560 }) - .default_height(if channel == render::TouchChannel::Art { 790 } else { 610 }) + .default_width(800) + .default_height(match channel { + render::TouchChannel::Art => 560, + render::TouchChannel::Nibp => 490, + render::TouchChannel::Ecg => 310, + _ => 420, + }) .build(); dialog.add_css_class("ecg-settings"); dialog.set_decorated(false); @@ -1166,45 +938,22 @@ inner.append(&heading); inner.append(&ecg_menu_divider()); - // Every numeric alarm has two optional bounds, editable without a keyboard. + // A shared horizontal matrix is used in every monitor-side touch menu. let specs = module_alarm_specs(channel, ¤t); let mut alarm_drafts = Vec::new(); - if channel == render::TouchChannel::Art { - // The ART panel uses the requested column/row arrangement. Other - // channels retain their current one-parameter-at-a-time layout. - inner.append(&art_alarm_grid(specs, &mut alarm_drafts)); - } else { - for spec in specs { - let label = gtk::Label::new(Some(&format!("{} alarm limits · {}", spec.name, spec.unit))); - label.set_xalign(0.0); - inner.append(&label); - let lower = module_touch_limit(&inner, "↓ Lower", spec.limits.lower, - spec.restore_lower, spec.step, spec.maximum); - let upper = module_touch_limit(&inner, "↑ Upper", spec.limits.upper, - spec.restore_upper, spec.step, spec.maximum); - alarm_drafts.push(TouchAlarmDraft { - name: spec.name, lower, upper, apply: spec.apply, - }); - inner.append(&ecg_menu_divider()); - } - } + inner.append(&alarm_limit_matrix(specs, &mut alarm_drafts)); let error = gtk::Label::new(None); error.set_xalign(0.0); error.add_css_class("menu-error"); error.set_wrap(true); - // The ART layout is taller; keep validation and buttons visible while - // the alarm-limit controls scroll on smaller monitor touchscreens. + // Validation and Apply/Cancel stay fixed when the matrix scrolls. let footer = gtk::Box::new(Orientation::Vertical, 8); - if channel == render::TouchChannel::Art { - footer.set_margin_start(20); - footer.set_margin_end(20); - footer.set_margin_top(8); - footer.set_margin_bottom(12); - footer.append(&error); - } else { - inner.append(&error); - } + footer.set_margin_start(20); + footer.set_margin_end(20); + footer.set_margin_top(8); + footer.set_margin_bottom(12); + footer.append(&error); let buttons = gtk::Box::new(Orientation::Horizontal, 12); buttons.set_halign(gtk::Align::End); let cancel = gtk::Button::with_label("Cancel"); @@ -1244,12 +993,8 @@ }); buttons.append(&cancel); buttons.append(&apply); - if channel == render::TouchChannel::Art { - footer.append(&buttons); - content.append(&footer); - } else { - inner.append(&buttons); - } + footer.append(&buttons); + content.append(&footer); dialog.set_child(Some(&content)); let escape = gtk::EventControllerKey::new(); @@ -1286,21 +1031,29 @@ } #[test] - fn art_menu_columns_follow_sys_map_dia_and_ppv_order() { - assert_eq!(art_alarm_position(0), (1, 0, 1, 2, "SYS")); - assert_eq!(art_alarm_position(1), (2, 0, 1, 2, "MAP")); - assert_eq!(art_alarm_position(2), (3, 0, 1, 2, "DIA")); - assert_eq!(art_alarm_position(3), (1, 3, 4, 5, "PPV")); - let specs = module_alarm_specs(render::TouchChannel::Art, &Parameters::default()); - assert_eq!(specs.iter().map(|spec| spec.name).collect::>(), - ["ART systolic", "ART MAP", "ART diastolic", "PPV"]); - let mut alarms = AlarmSettings::default(); + fn alarm_matrix_order_and_labels() { + let p = Parameters::default(); + for (channel, names) in [ + (render::TouchChannel::Ecg, vec!["HR"]), + (render::TouchChannel::Spo2, vec!["SpO₂", "PR"]), + (render::TouchChannel::Art, vec!["SYS", "MAP", "DIA", "PPV"]), + (render::TouchChannel::Capno, vec!["EtCO₂", "RR"]), + (render::TouchChannel::Nibp, vec!["SYS", "MAP", "DIA"]), + ] { + let specs = module_alarm_specs(channel, &p); + let actual: Vec<_> = specs.iter() + .map(|spec| alarm_matrix_label(spec.name)).collect(); + assert_eq!(actual, names); + } + // Same underlying ART alarm setters are retained after rearrangement. + let specs = module_alarm_specs(render::TouchChannel::Art, &p); let limits = [ AlarmLimits { lower: Some(80), upper: Some(180) }, AlarmLimits { lower: Some(60), upper: Some(100) }, AlarmLimits { lower: None, upper: None }, AlarmLimits { lower: None, upper: Some(10) }, ]; + let mut alarms = AlarmSettings::default(); for (spec, value) in specs.into_iter().zip(limits.iter().copied()) { (spec.apply)(&mut alarms, value); }