use std::{cell::Cell, rc::Rc};
use gpui::{Div, ElementId, MouseButton, Stateful, Window, div, prelude::*, px};
use theme::Theme;
#[derive(Clone, Default)]
pub struct DragState(Rc<Cell<bool>>);
pub fn titlebar(
id: impl Into<ElementId>,
drag: &DragState,
traffic_lights: bool,
window: &Window,
) -> Stateful<Div> {
let (armed, disarm, release) = (drag.0.clone(), drag.0.clone(), drag.0.clone());
let moving = drag.0.clone();
div()
.id(id)
.w_full()
.h(px(Theme::TITLEBAR_HEIGHT))
.flex()
.flex_row()
.items_center()
.when(traffic_lights && !window.is_fullscreen(), |bar| {
bar.pl(px(Theme::TRAFFIC_LIGHT_INSET))
})
.on_mouse_down(MouseButton::Left, move |_, _, _| armed.set(true))
.on_mouse_up(MouseButton::Left, move |_, _, _| release.set(false))
.on_mouse_down_out(move |_, _, _| disarm.set(false))
.on_mouse_move(move |_, window, _| {
if moving.replace(false) {
window.start_window_move();
}
})
.on_click(|click, window, _| {
if click.click_count() == 2 {
window.titlebar_double_click();
}
})
}