use super::{Context, Id};
use crate::components::table::TableState;
use std::collections::HashMap;
#[derive(Default)]
pub(crate) struct Tables {
pub(crate) states: HashMap<Id, TableState>,
resized: HashMap<(Id, Id), f32>,
}
impl Context {
pub(super) fn column_resize_press(&mut self, table: Id, column: Id) {
if let Some(state) = self.tables.states.get_mut(&table) {
if let Some(&width) = state.current_widths.get(&column) {
state.drag = Some((column, width));
}
}
}
pub(super) fn column_resize_move(&mut self, table: Id, column: Id, delta: f32) {
let Some((dragged, width)) = self.tables.states.get(&table).and_then(|s| s.drag) else {
return;
};
if dragged == column {
self.tables
.resized
.insert((table, column), (width + delta).max(0.0));
}
}
pub(super) fn cancel_column_resize(&mut self, table: Id) {
if let Some(state) = self.tables.states.get_mut(&table) {
state.drag = None;
}
}
pub(super) fn column_resize_holds(&self, table: Id, column: Id, window: Id) -> bool {
self.tables.states.get(&table).is_some_and(|state| {
state.last_frame == self.frame && state.resize_columns.contains(&column)
}) && self.visible_windows.contains(&window)
}
pub(crate) fn take_column_resize(&mut self, table: Id, column: Id) -> Option<f32> {
self.tables.resized.remove(&(table, column))
}
}