pub struct Matrix<'a, const COLS: usize, const ROWS: usize> {
    columns: &'a [osc::Column<ROWS>; COLS],
    selected_column: usize,
    selected_row: usize,
    metronome_position: f32,
}

impl<'a, const COLS: usize, const ROWS: usize> Matrix<'a, COLS, ROWS> {
    pub fn new(
        columns: &'a [osc::Column<ROWS>; COLS],
        selected_column: usize,
        selected_row: usize,
        metronome_position: f32,
    ) -> Self {
        Self {
            columns,
            selected_column,
            selected_row,
            metronome_position,
        }
    }
}

impl<'a, const COLS: usize, const ROWS: usize> egui::Widget for Matrix<'a, COLS, ROWS> {
    fn ui(self, ui: &mut egui::Ui) -> egui::Response {
        ui.columns(self.columns.len(), |ui| {
            for (i, column) in self.columns.iter().enumerate() {
                let selected_row = if i == self.selected_column {
                    Some(self.selected_row)
                } else {
                    None
                };
                ui[i].add(super::Column::new(
                    column,
                    selected_row,
                    self.metronome_position,
                ));
            }
        });
        ui.response()
    }
}
