use crate::widget::roi_stats::RoiStats;
use crate::widget::stats_widget::{format_coord, format_stat};
#[derive(Clone, Debug, PartialEq)]
pub struct RoiStatsRow {
pub label: String,
pub stats: RoiStats,
}
#[derive(Default)]
pub struct RoiStatsWidget {
rows: Vec<RoiStatsRow>,
}
impl RoiStatsWidget {
pub fn new() -> Self {
Self::default()
}
pub fn rows(&self) -> &[RoiStatsRow] {
&self.rows
}
pub fn set_rows(&mut self, rows: Vec<RoiStatsRow>) {
self.rows = rows;
}
pub fn ui(&mut self, ui: &mut egui::Ui) {
egui::Grid::new("roi_stats_grid")
.striped(true)
.show(ui, |ui| {
ui.strong("ROI");
ui.strong("N");
ui.strong("min");
ui.strong("max");
ui.strong("mean");
ui.strong("sum");
ui.strong("integral");
ui.strong("COM");
ui.strong("coord min");
ui.strong("coord max");
ui.end_row();
for row in &self.rows {
ui.label(&row.label);
ui.label(row.stats.count.to_string());
ui.label(format_stat(row.stats.min));
ui.label(format_stat(row.stats.max));
ui.label(format_stat(row.stats.mean));
ui.label(format_stat(Some(row.stats.sum)));
ui.label(format_stat(Some(row.stats.integral)));
ui.label(format_coord(row.stats.com));
ui.label(format_coord(row.stats.coord_min));
ui.label(format_coord(row.stats.coord_max));
ui.end_row();
}
});
}
}