use crate::ShellColors;
use gpui::{AnyElement, App, Pixels, Window, WindowAppearance};
use std::{fmt, rc::Rc};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ShellControl {
Minimize,
Maximize,
Restore,
Close,
}
impl ShellControl {
pub fn accessible_label(self) -> &'static str {
match self {
Self::Minimize => "Minimize window",
Self::Maximize => "Maximize window",
Self::Restore => "Restore window",
Self::Close => "Close window",
}
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct ShellControlState {
pub control: ShellControl,
pub hovered: bool,
pub pressed: bool,
pub focused: bool,
pub window_active: bool,
pub appearance: WindowAppearance,
pub high_contrast: bool,
pub colors: ShellColors,
pub focus_color: u32,
pub scale: f32,
pub target_size: Pixels,
pub preview: bool,
}
type Render = dyn Fn(&ShellControlState, &mut Window, &mut App) -> AnyElement;
#[derive(Clone)]
pub struct ShellControlPresenter(Rc<Render>);
impl ShellControlPresenter {
pub fn new(
render: impl Fn(&ShellControlState, &mut Window, &mut App) -> AnyElement + 'static,
) -> Self {
Self(Rc::new(render))
}
pub(crate) fn render(
&self,
state: &ShellControlState,
window: &mut Window,
cx: &mut App,
) -> AnyElement {
(self.0)(state, window, cx)
}
}
impl fmt::Debug for ShellControlPresenter {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("ShellControlPresenter")
}
}