use gpui_kit::prelude::*;
use gpui_kit::{Pixels, px};
#[derive(Clone, Copy)]
pub(super) enum ColWidth {
Fixed(f32),
Flex(f32),
}
impl ColWidth {
pub(super) const fn floor(self) -> f32 {
match self {
ColWidth::Fixed(width) | ColWidth::Flex(width) => width,
}
}
}
pub(super) fn sized<E: Styled>(cell: E, width: ColWidth) -> E {
match width {
ColWidth::Fixed(width) => cell.flex_none().w(px(width)).min_w(px(width)),
ColWidth::Flex(min) => cell.flex_1().min_w(px(min)),
}
}
pub(super) fn table_min_width(columns: &[ColWidth]) -> Pixels {
px(columns.iter().map(|column| column.floor() + 8.).sum())
}
pub(super) const COL_KEY: ColWidth = ColWidth::Fixed(48.);
pub(super) const COL_NAME: ColWidth = ColWidth::Flex(140.);
pub(super) const COL_TYPE: ColWidth = ColWidth::Fixed(150.);
pub(super) const COL_NULLABLE: ColWidth = ColWidth::Fixed(80.);
pub(super) const COL_DEFAULT: ColWidth = ColWidth::Flex(120.);
pub(super) const COL_ACTIONS: ColWidth = ColWidth::Fixed(110.);
pub(super) const COL_INDEX_NAME: ColWidth = ColWidth::Flex(150.);
pub(super) const COL_INDEX_KIND: ColWidth = ColWidth::Fixed(160.);
pub(super) const COL_INDEX_COLUMNS: ColWidth = ColWidth::Flex(180.);
pub(super) const COL_FK_NAME: ColWidth = ColWidth::Flex(130.);
pub(super) const COL_FK_REFERENCE: ColWidth = ColWidth::Flex(220.);
pub(super) const COL_FK_ACTION: ColWidth = ColWidth::Fixed(110.);