v0.5.9 — Touch-optimized ECG settings

Restyled the ECG settings window with light-grey text/controls, a neutral
0.8-pixel outer border and thin 0.8-pixel Cairo separators matching the
monitor. Replaced the on-monitor HR limit text entries with large 5-bpm
**−/+** buttons and independent **ON/OFF** controls; the ECG lead remains a
touch-selectable dropdown. Pending changes still require Apply, and Cancel
leaves the shared parameters unchanged. No signal generation was altered.
This commit is contained in:
GABRIEL Sebastian 2026-11-12 16:36:07 +01:00
commit 3f191e4c46
8 changed files with 673 additions and 73 deletions

View file

@ -539,31 +539,146 @@ ART and pleth are delayed. VT can be perfusing; PVT, VF and asystole are pulsele
window
}
/// Dark ECG control panel matching the green-on-black bedside monitor.
/// Installed only once, with a CSS class scoped to this popup.
/// Neutral black-and-light-grey ECG control panel. Match the monitor's
/// MUTED divider color, with 0.8-pixel outer borders and 0.8-pixel Cairo
/// dividers (the same thickness as the main monitor header divider).
fn install_ecg_menu_style() {
if let Some(display) = gdk::Display::default() {
let provider = gtk::CssProvider::new();
provider.load_from_data(
"window.ecg-settings { background-color: #000000; }
window.ecg-settings box { background-color: #000000; }
window.ecg-settings label { color: #42ff63; }
window.ecg-settings label.menu-error { color: #ff4d50; }
window.ecg-settings entry { color: #42ff63; background-color: #101b13;
border: 1px solid #377547; min-height: 42px; }
window.ecg-settings dropdown { color: #42ff63; background-color: #101b13;
min-height: 44px; }
window.ecg-settings button { min-height: 44px; }
window.ecg-settings button.ecg-apply { color: #000000;
background-image: none; background-color: #42ff63; font-weight: bold; }
window.ecg-settings button.ecg-close { color: #42ff63;
background-image: none; background-color: #152219; }"
window.ecg-settings box.ecg-panel {
background-color: #000000; border: 0.8px solid #6b757d;
}
window.ecg-settings label { color: #e5e9eb; }
window.ecg-settings label.menu-error { color: #ff8080; }
window.ecg-settings label.ecg-limit-value {
color: #e5e9eb; font-weight: bold; font-size: 19px;
}
window.ecg-settings dropdown {
color: #e5e9eb; background-color: #141414;
border: 1px solid #6b757d; min-height: 48px;
}
window.ecg-settings dropdown button {
color: #e5e9eb; background-color: #141414;
}
window.ecg-settings button {
color: #e5e9eb; background-image: none;
background-color: #171717; border: 1px solid #6b757d;
min-height: 48px; min-width: 52px;
}
window.ecg-settings button:hover { background-color: #303437; }
window.ecg-settings button.ecg-apply {
color: #000000; background-color: #e5e9eb; font-weight: bold;
}
window.ecg-settings button.ecg-close { background-color: #171717; }"
);
gtk::style_context_add_provider_for_display(
&display, &provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION);
}
}
/// Cairo divider with the same line thickness and color as the bedside
/// monitor's header separator (render.rs: MUTED, 0.8 logical pixels).
fn ecg_menu_divider() -> gtk::DrawingArea {
let separator = gtk::DrawingArea::new();
separator.set_hexpand(true);
separator.set_content_height(2);
separator.set_draw_func(|_area, cr, width, height| {
cr.set_source_rgb(0.42, 0.46, 0.49);
cr.set_line_width(0.8);
let y = f64::from(height) / 2.0;
cr.move_to(0.0, y);
cr.line_to(f64::from(width), y);
let _ = cr.stroke();
});
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<i32>, last_enabled: i32, direction: i32) -> i32 {
current.map_or(last_enabled, |value| {
(value + TOUCH_HR_STEP * direction).clamp(0, MAX_HR_ALARM)
})
}
fn show_touch_hr_limit(value: Option<i32>, number: &gtk::Label,
toggle: &gtk::Button) {
number.set_text(&value.map_or("OFF".to_owned(), |v| v.to_string()));
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: &gtk::Box, caption: &str,
initial: Option<i32>, default: i32) -> Rc<Cell<Option<i32>>> {
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,
@ -583,23 +698,32 @@ fn open_ecg_menu(app: &Application, monitor: &ApplicationWindow,
.transient_for(monitor)
.modal(true)
.resizable(false)
.default_width(450)
.default_height(340)
.default_width(550)
.default_height(410)
.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, 15);
content.set_margin_top(22);
content.set_margin_bottom(22);
content.set_margin_start(22);
content.set_margin_end(22);
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");
content.append(&title);
content.append(&gtk::Separator::new(Orientation::Horizontal));
inner.append(&title);
inner.append(&ecg_menu_divider());
let lead_row = gtk::Box::new(Orientation::Horizontal, 12);
let lead_label = gtk::Label::new(Some("ECG lead"));
@ -610,34 +734,27 @@ fn open_ecg_menu(app: &Application, monitor: &ApplicationWindow,
lead_selector.set_hexpand(true);
lead_row.append(&lead_label);
lead_row.append(&lead_selector);
content.append(&lead_row);
inner.append(&lead_row);
inner.append(&ecg_menu_divider());
let limits_header = gtk::Label::new(Some("HR alarm limits · bpm"));
limits_header.set_xalign(0.0);
content.append(&limits_header);
let limits_row = gtk::Box::new(Orientation::Horizontal, 10);
let lower = alarm_entry(limits.lower, "OFF");
let upper = alarm_entry(limits.upper, "OFF");
lower.set_hexpand(true);
upper.set_hexpand(true);
limits_row.append(&gtk::Label::new(Some("↓ Lower")));
limits_row.append(&lower);
limits_row.append(&gtk::Label::new(Some("↑ Upper")));
limits_row.append(&upper);
content.append(&limits_row);
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(
"Leave either limit empty to disable that alarm boundary."
"+/− adjusts by 5 bpm. OFF disables the limit; ON restores it."
));
hint.set_wrap(true);
hint.set_xalign(0.0);
content.append(&hint);
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);
content.append(&error);
inner.append(&error);
let buttons = gtk::Box::new(Orientation::Horizontal, 12);
buttons.set_halign(gtk::Align::End);
@ -652,13 +769,7 @@ fn open_ecg_menu(app: &Application, monitor: &ApplicationWindow,
apply.connect_clicked({
let weak = dialog.downgrade();
move |_| {
let (Ok(lo), Ok(hi)) = (
parse_alarm_bound(&lower, 240), parse_alarm_bound(&upper, 240)
) else {
error.set_text("Alarm limits must be 0–240 bpm, or blank (OFF).");
return;
};
let new_limits = AlarmLimits { lower: lo, upper: hi };
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;
@ -679,7 +790,7 @@ fn open_ecg_menu(app: &Application, monitor: &ApplicationWindow,
});
buttons.append(&cancel);
buttons.append(&apply);
content.append(&buttons);
inner.append(&buttons);
dialog.set_child(Some(&content));
let escape = gtk::EventControllerKey::new();
@ -696,6 +807,25 @@ fn open_ecg_menu(app: &Application, monitor: &ApplicationWindow,
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);
}
#[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);
}
}
/// Frame a parameter section with an optional monitor-colored left sidebar.
/// A DrawingArea keeps the color independent of the user's GTK theme/CSS.
fn group(parent: &gtk::Box, title: &str, accent: Option<AccentColor>) -> gtk::Box {