use crate::{
components::form::inset_outline,
icons::{CarbonIcon, Icon},
theme::color,
tokens::{self, ColorRole},
};
use gpui_kit::{App, Div, ElementId, Entity, FocusHandle, Hsla, Rems, Window};
pub(crate) fn rem(px_value: f32) -> Rems {
gpui_kit::rems(px_value / tokens::REM_PX)
}
pub(crate) fn icon(name: CarbonIcon, size: f32, ink: Hsla) -> Icon {
Icon::carbon(name).size_length(rem(size)).color(ink)
}
pub(crate) fn hover(
id: impl Into<ElementId>,
window: &mut Window,
cx: &mut App,
) -> (bool, Entity<bool>) {
let store = window.use_keyed_state(id, cx, |_, _| false);
(*store.read(cx), store)
}
pub(crate) fn track_hover(store: Entity<bool>) -> impl Fn(&bool, &mut Window, &mut App) + 'static {
move |over, _, cx| {
store.update(cx, |h, cx| {
if *h != *over {
*h = *over;
cx.notify();
}
})
}
}
pub(crate) fn focus(
id: impl Into<ElementId>,
window: &mut Window,
cx: &mut App,
) -> (FocusHandle, bool) {
let handle = window
.use_keyed_state(id, cx, |_, cx| cx.focus_handle())
.read(cx)
.clone();
let visible = handle.is_focused(window) && crate::focus::focus_visible_mode(window);
(handle, visible)
}
pub(crate) type Handler = std::rc::Rc<dyn Fn(&mut Window, &mut App)>;
pub(crate) fn inset_frame(c: Hsla) -> Vec<gpui_kit::BoxShadow> {
vec![
gpui_kit::BoxShadow::new(gpui_kit::px(0.), gpui_kit::px(0.), c)
.spread_radius(gpui_kit::px(1.))
.inset(),
]
}
pub(crate) fn ring() -> Div {
inset_outline(2., color(ColorRole::Focus))
}