use crate::ui::widgets::atomic::tooltip::TooltipState;
use crate::ui::widgets::composite::context_menu::ContextMenuState;
use super::types::{ChromeColors, ChromeHit};
#[derive(Debug, Clone, Default)]
pub struct TabState {
pub id: String,
pub hovered: bool,
pub pressed: bool,
pub close_hovered: bool,
}
impl TabState {
pub fn new(id: impl Into<String>) -> Self {
Self {
id: id.into(),
hovered: false,
pressed: false,
close_hovered: false,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct ChromeState {
pub hovered: ChromeHit,
pub is_maximized: bool,
pub dragging_window: bool,
pub tabs_state: Vec<TabState>,
pub active_tab_id: Option<String>,
pub tab_widths: Vec<f64>,
pub tooltip: TooltipState,
pub context_menu: ContextMenuState,
pub colors: ChromeColors,
pub chrome_button: Option<super::types::ChromeButton>,
pub title: String,
}
impl ChromeState {
pub fn new() -> Self {
Self::default()
}
pub fn sync_tabs(&mut self, ids: &[&str]) {
self.tabs_state.retain(|ts| ids.contains(&ts.id.as_str()));
for &id in ids {
if !self.tabs_state.iter().any(|ts| ts.id == id) {
self.tabs_state.push(TabState::new(id));
}
}
let ordered: Vec<TabState> = ids
.iter()
.filter_map(|&id| {
self.tabs_state.iter().find(|ts| ts.id == id).cloned()
})
.collect();
self.tabs_state = ordered;
}
pub fn update_tab_widths(
&mut self,
text_widths: &[f64],
tab_padding_h: f64,
tab_close_size: f64,
) {
self.tab_widths = text_widths
.iter()
.map(|&tw| tab_padding_h + tw + tab_close_size + tab_padding_h)
.collect();
}
pub fn clear_hover(&mut self) {
self.hovered = ChromeHit::None;
self.chrome_button = None;
for ts in &mut self.tabs_state {
ts.hovered = false;
ts.pressed = false;
ts.close_hovered = false;
}
}
}