Checkpoint

This commit is contained in:
Antonio Scandurra
2023-10-19 23:39:22 +02:00
parent 4a6c8ff809
commit d69105bb77
7 changed files with 59 additions and 140 deletions
-25
View File
@@ -1,25 +0,0 @@
use crate::{SharedString, StyleRefinement};
pub trait Active {
fn set_active_style(&mut self, group_name: Option<SharedString>, style: StyleRefinement);
fn active(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self
where
Self: Sized,
{
self.set_active_style(None, f(StyleRefinement::default()));
self
}
fn group_active(
mut self,
group_name: impl Into<SharedString>,
f: impl FnOnce(StyleRefinement) -> StyleRefinement,
) -> Self
where
Self: Sized,
{
self.set_active_style(Some(group_name.into()), f(StyleRefinement::default()));
self
}
}
+4 -35
View File
@@ -1,10 +1,9 @@
use crate::{
Active, AnyElement, BorrowWindow, Bounds, Element, ElementFocusability, ElementId,
AnyElement, BorrowWindow, Bounds, Element, ElementFocusability, ElementId,
ElementInteractivity, Focus, FocusHandle, FocusListeners, Focusable, GlobalElementId,
GroupBounds, GroupStyle, Hover, InteractiveElementState, IntoAnyElement, LayoutId,
NonFocusable, Overflow, ParentElement, Pixels, Point, SharedString, StatefulInteractivity,
StatefullyInteractive, StatelessInteractivity, StatelesslyInteractive, Style, StyleRefinement,
Styled, ViewContext,
GroupBounds, InteractiveElementState, IntoAnyElement, LayoutId, NonFocusable, Overflow,
ParentElement, Pixels, Point, SharedString, StatefulInteractivity, StatefullyInteractive,
StatelessInteractivity, StatelesslyInteractive, Style, StyleRefinement, Styled, ViewContext,
};
use parking_lot::Mutex;
use refineable::Refineable;
@@ -332,22 +331,6 @@ where
}
}
impl<V, I, F> Hover for Div<V, I, F>
where
I: ElementInteractivity<V>,
F: ElementFocusability<V>,
V: 'static + Send + Sync,
{
fn set_hover_style(&mut self, group: Option<SharedString>, style: StyleRefinement) {
let stateless = self.interactivity.as_stateless_mut();
if let Some(group) = group {
stateless.group_hover_style = Some(GroupStyle { group, style });
} else {
stateless.hover_style = style;
}
}
}
impl<V, F> StatefullyInteractive for Div<V, StatefulInteractivity<V>, F>
where
F: ElementFocusability<V>,
@@ -357,17 +340,3 @@ where
&mut self.interactivity
}
}
impl<V, F> Active for Div<V, StatefulInteractivity<V>, F>
where
F: ElementFocusability<V>,
V: 'static + Send + Sync,
{
fn set_active_style(&mut self, group: Option<SharedString>, style: StyleRefinement) {
if let Some(group) = group {
self.interactivity.group_active_style = Some(GroupStyle { group, style });
} else {
self.interactivity.active_style = style;
}
}
}
+2 -23
View File
@@ -1,6 +1,6 @@
use crate::{
div, Active, AnyElement, BorrowWindow, Bounds, Div, Element, ElementFocusability, ElementId,
ElementInteractivity, Focus, FocusListeners, Focusable, Hover, InteractiveElementState,
div, AnyElement, BorrowWindow, Bounds, Div, Element, ElementFocusability, ElementId,
ElementInteractivity, Focus, FocusListeners, Focusable, InteractiveElementState,
IntoAnyElement, LayoutId, NonFocusable, Pixels, SharedString, StatefulInteractivity,
StatefullyInteractive, StatelessInteractivity, StatelesslyInteractive, StyleRefinement, Styled,
ViewContext,
@@ -162,17 +162,6 @@ where
}
}
impl<V, I, F> Hover for Img<V, I, F>
where
V: 'static + Send + Sync,
I: ElementInteractivity<V>,
F: ElementFocusability<V>,
{
fn set_hover_style(&mut self, group: Option<SharedString>, style: StyleRefinement) {
self.base.set_hover_style(group, style);
}
}
impl<V, F> StatefullyInteractive for Img<V, StatefulInteractivity<V>, F>
where
V: 'static + Send + Sync,
@@ -183,16 +172,6 @@ where
}
}
impl<V, F> Active for Img<V, StatefulInteractivity<V>, F>
where
V: 'static + Send + Sync,
F: ElementFocusability<V>,
{
fn set_active_style(&mut self, group: Option<SharedString>, style: StyleRefinement) {
self.base.set_active_style(group, style)
}
}
impl<V, I> Focus for Img<V, I, Focusable<V>>
where
V: 'static + Send + Sync,
+4 -26
View File
@@ -1,9 +1,8 @@
use crate::{
div, Active, AnyElement, Bounds, Div, Element, ElementFocusability, ElementId,
ElementInteractivity, Focus, FocusListeners, Focusable, Hover, InteractiveElementState,
IntoAnyElement, LayoutId, NonFocusable, Pixels, SharedString, StatefulInteractivity,
StatefullyInteractive, StatelessInteractivity, StatelesslyInteractive, StyleRefinement, Styled,
ViewContext,
div, AnyElement, Bounds, Div, Element, ElementFocusability, ElementId, ElementInteractivity,
Focus, FocusListeners, Focusable, InteractiveElementState, IntoAnyElement, LayoutId,
NonFocusable, Pixels, SharedString, StatefulInteractivity, StatefullyInteractive,
StatelessInteractivity, StatelesslyInteractive, StyleRefinement, Styled, ViewContext,
};
use util::ResultExt;
@@ -136,17 +135,6 @@ where
}
}
impl<V, I, F> Hover for Svg<V, I, F>
where
V: 'static + Send + Sync,
I: ElementInteractivity<V>,
F: ElementFocusability<V>,
{
fn set_hover_style(&mut self, group: Option<SharedString>, style: StyleRefinement) {
self.base.set_hover_style(group, style);
}
}
impl<V, F> StatefullyInteractive for Svg<V, StatefulInteractivity<V>, F>
where
V: 'static + Send + Sync,
@@ -157,16 +145,6 @@ where
}
}
impl<V, F> Active for Svg<V, StatefulInteractivity<V>, F>
where
V: 'static + Send + Sync,
F: ElementFocusability<V>,
{
fn set_active_style(&mut self, group: Option<SharedString>, style: StyleRefinement) {
self.base.set_active_style(group, style)
}
}
impl<V, I> Focus for Svg<V, I, Focusable<V>>
where
V: 'static + Send + Sync,
-4
View File
@@ -1,5 +1,4 @@
mod action;
mod active;
mod app;
mod assets;
mod color;
@@ -8,7 +7,6 @@ mod elements;
mod executor;
mod focus;
mod geometry;
mod hover;
mod image_cache;
mod interactive;
mod keymap;
@@ -25,7 +23,6 @@ mod view;
mod window;
pub use action::*;
pub use active::*;
pub use anyhow::Result;
pub use app::*;
pub use assets::*;
@@ -36,7 +33,6 @@ pub use executor::*;
pub use focus::*;
pub use geometry::*;
pub use gpui3_macros::*;
pub use hover::*;
pub use image_cache::*;
pub use interactive::*;
pub use keymap::*;
-25
View File
@@ -1,25 +0,0 @@
use crate::{SharedString, StyleRefinement};
pub trait Hover {
fn set_hover_style(&mut self, group_name: Option<SharedString>, style: StyleRefinement);
fn hover(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self
where
Self: Sized,
{
self.set_hover_style(None, f(StyleRefinement::default()));
self
}
fn group_hover(
mut self,
group_name: impl Into<SharedString>,
f: impl FnOnce(StyleRefinement) -> StyleRefinement,
) -> Self
where
Self: Sized,
{
self.set_hover_style(Some(group_name.into()), f(StyleRefinement::default()));
self
}
}
+49 -2
View File
@@ -1,6 +1,7 @@
use crate::{
point, Action, Bounds, DispatchContext, DispatchPhase, Element, FocusHandle, Keystroke,
Modifiers, Pixels, Point, StatefulInteractivity, StatelessInteractivity, ViewContext,
point, Action, Bounds, DispatchContext, DispatchPhase, Element, FocusHandle, GroupStyle,
Keystroke, Modifiers, Pixels, Point, SharedString, StatefulInteractivity,
StatelessInteractivity, StyleRefinement, ViewContext,
};
use std::{
any::{Any, TypeId},
@@ -147,6 +148,29 @@ pub trait StatelesslyInteractive: Element {
self
}
fn hover(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self
where
Self: Sized,
{
self.stateless_interactivity().hover_style = f(StyleRefinement::default());
self
}
fn group_hover(
mut self,
group_name: impl Into<SharedString>,
f: impl FnOnce(StyleRefinement) -> StyleRefinement,
) -> Self
where
Self: Sized,
{
self.stateless_interactivity().group_hover_style = Some(GroupStyle {
group: group_name.into(),
style: f(StyleRefinement::default()),
});
self
}
fn on_key_down(
mut self,
listener: impl Fn(
@@ -218,6 +242,29 @@ pub trait StatelesslyInteractive: Element {
pub trait StatefullyInteractive: StatelesslyInteractive {
fn stateful_interactivity(&mut self) -> &mut StatefulInteractivity<Self::ViewState>;
fn active(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self
where
Self: Sized,
{
self.stateful_interactivity().active_style = f(StyleRefinement::default());
self
}
fn group_active(
mut self,
group_name: impl Into<SharedString>,
f: impl FnOnce(StyleRefinement) -> StyleRefinement,
) -> Self
where
Self: Sized,
{
self.stateful_interactivity().group_active_style = Some(GroupStyle {
group: group_name.into(),
style: f(StyleRefinement::default()),
});
self
}
fn on_click(
mut self,
handler: impl Fn(&mut Self::ViewState, &MouseClickEvent, &mut ViewContext<Self::ViewState>)