Checkpoint

This commit is contained in:
Antonio Scandurra 2023-10-17 21:54:28 +02:00
parent 61490fbaa8
commit a8697df9e3
8 changed files with 103 additions and 16 deletions

View file

@ -0,0 +1,13 @@
use crate::StyleRefinement;
pub trait Active {
fn set_active_style(&mut self, style: StyleRefinement);
fn active(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self
where
Self: Sized,
{
self.set_active_style(f(StyleRefinement::default()));
self
}
}

View file

@ -1,9 +1,9 @@
use crate::{ use crate::{
AnonymousElement, AnyElement, AppContext, BorrowWindow, Bounds, Clickable, DispatchPhase, Active, AnonymousElement, AnyElement, AppContext, BorrowWindow, Bounds, Click, DispatchPhase,
Element, ElementId, ElementIdentity, IdentifiedElement, Interactive, IntoAnyElement, LayoutId, Element, ElementId, ElementIdentity, Hover, IdentifiedElement, Interactive, IntoAnyElement,
MouseClickEvent, MouseDownEvent, MouseEventListeners, MouseMoveEvent, MouseUpEvent, Overflow, LayoutId, MouseClickEvent, MouseDownEvent, MouseEventListeners, MouseMoveEvent, MouseUpEvent,
ParentElement, Pixels, Point, ScrollWheelEvent, SharedString, Style, StyleRefinement, Styled, Overflow, ParentElement, Pixels, Point, ScrollWheelEvent, SharedString, Style, StyleRefinement,
ViewContext, Styled, ViewContext,
}; };
use collections::HashMap; use collections::HashMap;
use parking_lot::Mutex; use parking_lot::Mutex;
@ -449,7 +449,26 @@ where
} }
} }
impl<V> Clickable for Div<V, IdentifiedElement> where V: 'static + Send + Sync {} impl<V, K> Hover for Div<V, K>
where
V: 'static + Send + Sync,
K: ElementIdentity,
{
fn set_hover_style(&mut self, style: StyleRefinement) {
self.hover_style = style;
}
}
impl<V> Click for Div<V, IdentifiedElement> where V: 'static + Send + Sync {}
impl<V> Active for Div<V, IdentifiedElement>
where
V: 'static + Send + Sync,
{
fn set_active_style(&mut self, style: StyleRefinement) {
self.active_style = style;
}
}
fn paint_hover_listener<V>(bounds: Bounds<Pixels>, cx: &mut ViewContext<V>) fn paint_hover_listener<V>(bounds: Bounds<Pixels>, cx: &mut ViewContext<V>)
where where

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
div, AnonymousElement, AnyElement, BorrowWindow, Bounds, Clickable, Div, DivState, Element, div, Active, AnonymousElement, AnyElement, BorrowWindow, Bounds, Click, Div, DivState, Element,
ElementId, ElementIdentity, IdentifiedElement, Interactive, IntoAnyElement, LayoutId, ElementId, ElementIdentity, Hover, IdentifiedElement, Interactive, IntoAnyElement, LayoutId,
MouseEventListeners, Pixels, SharedString, StyleRefinement, Styled, ViewContext, MouseEventListeners, Pixels, SharedString, StyleRefinement, Styled, ViewContext,
}; };
use futures::FutureExt; use futures::FutureExt;
@ -141,4 +141,23 @@ where
} }
} }
impl<V> Clickable for Img<V, IdentifiedElement> where V: 'static + Send + Sync {} impl<V, K> Hover for Img<V, K>
where
V: 'static + Send + Sync,
K: ElementIdentity,
{
fn set_hover_style(&mut self, style: StyleRefinement) {
self.base.set_hover_style(style);
}
}
impl<V> Click for Img<V, IdentifiedElement> where V: 'static + Send + Sync {}
impl<V> Active for Img<V, IdentifiedElement>
where
V: 'static + Send + Sync,
{
fn set_active_style(&mut self, style: StyleRefinement) {
self.base.set_active_style(style)
}
}

View file

@ -1,7 +1,7 @@
use crate::{ use crate::{
div, AnonymousElement, AnyElement, Bounds, Clickable, Div, DivState, Element, ElementId, div, Active, AnonymousElement, AnyElement, Bounds, Click, Div, DivState, Element, ElementId,
ElementIdentity, IdentifiedElement, Interactive, IntoAnyElement, LayoutId, MouseEventListeners, ElementIdentity, Hover, IdentifiedElement, Interactive, IntoAnyElement, LayoutId,
Pixels, SharedString, StyleRefinement, Styled, MouseEventListeners, Pixels, SharedString, StyleRefinement, Styled,
}; };
use util::ResultExt; use util::ResultExt;
@ -116,4 +116,23 @@ where
} }
} }
impl<V> Clickable for Svg<V, IdentifiedElement> where V: 'static + Send + Sync {} impl<V, K> Hover for Svg<V, K>
where
V: 'static + Send + Sync,
K: ElementIdentity,
{
fn set_hover_style(&mut self, style: StyleRefinement) {
self.base.set_hover_style(style);
}
}
impl<V> Click for Svg<V, IdentifiedElement> where V: 'static + Send + Sync {}
impl<V> Active for Svg<V, IdentifiedElement>
where
V: 'static + Send + Sync,
{
fn set_active_style(&mut self, style: StyleRefinement) {
self.base.set_active_style(style)
}
}

View file

@ -1,3 +1,4 @@
mod active;
mod app; mod app;
mod assets; mod assets;
mod color; mod color;
@ -6,6 +7,7 @@ mod elements;
mod events; mod events;
mod executor; mod executor;
mod geometry; mod geometry;
mod hover;
mod image_cache; mod image_cache;
mod interactive; mod interactive;
mod platform; mod platform;
@ -20,6 +22,7 @@ mod util;
mod view; mod view;
mod window; mod window;
pub use active::*;
pub use anyhow::Result; pub use anyhow::Result;
pub use app::*; pub use app::*;
pub use assets::*; pub use assets::*;
@ -30,6 +33,7 @@ pub use events::*;
pub use executor::*; pub use executor::*;
pub use geometry::*; pub use geometry::*;
pub use gpui3_macros::*; pub use gpui3_macros::*;
pub use hover::*;
pub use image_cache::*; pub use image_cache::*;
pub use interactive::*; pub use interactive::*;
pub use platform::*; pub use platform::*;

13
crates/gpui3/src/hover.rs Normal file
View file

@ -0,0 +1,13 @@
use crate::StyleRefinement;
pub trait Hover {
fn set_hover_style(&mut self, style: StyleRefinement);
fn hover(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self
where
Self: Sized,
{
self.set_hover_style(f(StyleRefinement::default()));
self
}
}

View file

@ -146,7 +146,7 @@ pub trait Interactive: Element {
} }
} }
pub trait Clickable: Interactive { pub trait Click: Interactive {
fn on_click( fn on_click(
mut self, mut self,
handler: impl Fn(&mut Self::ViewState, &MouseClickEvent, &mut ViewContext<Self::ViewState>) handler: impl Fn(&mut Self::ViewState, &MouseClickEvent, &mut ViewContext<Self::ViewState>)

View file

@ -1,6 +1,6 @@
pub use gpui3::{ pub use gpui3::{
div, Clickable, Element, Hoverable, IntoAnyElement, ParentElement, ScrollState, Styled, div, Click, Element, Hover, IntoAnyElement, ParentElement, ScrollState, Styled, ViewContext,
ViewContext, WindowContext, WindowContext,
}; };
pub use crate::{theme, ButtonVariant, ElementExt, Theme}; pub use crate::{theme, ButtonVariant, ElementExt, Theme};