WIP
This commit is contained in:
parent
b910c85f7f
commit
eec39dc23c
4 changed files with 41 additions and 8 deletions
33
crates/gpui/playground/docs/thoughts.md
Normal file
33
crates/gpui/playground/docs/thoughts.md
Normal file
|
@ -0,0 +1,33 @@
|
|||
```rs
|
||||
#[derive(Styled, Interactive)]
|
||||
pub struct Div {
|
||||
declared_style: StyleRefinement,
|
||||
interactions: Interactions
|
||||
}
|
||||
|
||||
pub trait Styled {
|
||||
fn declared_style(&mut self) -> &mut StyleRefinement;
|
||||
fn compute_style(&mut self) -> Style {
|
||||
Style::default().refine(self.declared_style())
|
||||
}
|
||||
|
||||
// All the tailwind classes, modifying self.declared_style()
|
||||
}
|
||||
|
||||
impl Style {
|
||||
pub fn paint_background<V>(layout: Layout, cx: &mut PaintContext<V>);
|
||||
pub fn paint_foreground<V>(layout: Layout, cx: &mut PaintContext<V>);
|
||||
}
|
||||
|
||||
pub trait Interactive<V> {
|
||||
fn interactions(&mut self) -> &mut Interactions<V>;
|
||||
|
||||
fn on_click(self, )
|
||||
}
|
||||
|
||||
struct Interactions<V> {
|
||||
click: SmallVec<[<Rc<dyn Fn(&mut V, &dyn Any, )>; 1]>,
|
||||
}
|
||||
|
||||
|
||||
```
|
|
@ -2,7 +2,7 @@ use std::{cell::Cell, marker::PhantomData, rc::Rc};
|
|||
|
||||
use gpui::{
|
||||
geometry::{rect::RectF, vector::Vector2F},
|
||||
scene::MouseMove,
|
||||
platform::MouseMovedEvent,
|
||||
EngineLayout, ViewContext,
|
||||
};
|
||||
use refineable::Refineable;
|
||||
|
@ -40,6 +40,8 @@ impl<V: 'static, E: Element<V>> Element<V> for Hoverable<V, E> {
|
|||
}
|
||||
|
||||
fn computed_style(&mut self, cx: &mut ViewContext<V>) -> &StyleRefinement {
|
||||
dbg!(self.computed_style.is_some());
|
||||
|
||||
self.computed_style.get_or_insert_with(|| {
|
||||
let mut style = self.child.computed_style(cx).clone();
|
||||
if self.hovered.get() {
|
||||
|
@ -83,9 +85,10 @@ impl<V: 'static, E: Element<V>> Element<V> for Hoverable<V, E> {
|
|||
order,
|
||||
window_bounds,
|
||||
false,
|
||||
move |view, event: &MouseMove, cx| {
|
||||
move |view, event: &MouseMovedEvent, cx| {
|
||||
let mouse_within_bounds = bounds.contains_point(cx.mouse_position());
|
||||
if mouse_within_bounds != hovered.get() {
|
||||
dbg!("hovered", mouse_within_bounds);
|
||||
hovered.set(mouse_within_bounds);
|
||||
cx.repaint();
|
||||
}
|
||||
|
|
|
@ -228,10 +228,9 @@ impl Event {
|
|||
Event::ModifiersChanged { .. } => None,
|
||||
Event::MouseDown(event) => Some(event),
|
||||
Event::MouseUp(event) => Some(event),
|
||||
_ => None,
|
||||
// Event::MouseMoved(event) => Some(event),
|
||||
// Event::MouseExited(event) => Some(event),
|
||||
// Event::ScrollWheel(event) => Some(event),
|
||||
Event::MouseMoved(event) => Some(event),
|
||||
Event::MouseExited(event) => Some(event),
|
||||
Event::ScrollWheel(event) => Some(event),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,8 +147,6 @@ pub fn derive_refineable(input: TokenStream) -> TokenStream {
|
|||
}
|
||||
};
|
||||
|
||||
println!("{}", gen);
|
||||
|
||||
gen.into()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue