mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-19 02:17:35 +03:00
Add a compile test for the element derive
This commit is contained in:
parent
ffffbbea1f
commit
7970406694
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -3172,6 +3172,7 @@ dependencies = [
|
|||||||
name = "gpui_macros"
|
name = "gpui_macros"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"gpui",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
|
@ -201,6 +201,10 @@ pub trait Element<V: View>: 'static {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait RenderElement {
|
||||||
|
fn render<V: View>(&mut self, view: &mut V, cx: &mut ViewContext<V>) -> AnyElement<V>;
|
||||||
|
}
|
||||||
|
|
||||||
trait AnyElementState<V: View> {
|
trait AnyElementState<V: View> {
|
||||||
fn layout(
|
fn layout(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -14,3 +14,5 @@ syn = "1.0"
|
|||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
gpui = { path = "../gpui" }
|
||||||
|
@ -283,8 +283,12 @@ pub fn element_derive(input: TokenStream) -> TokenStream {
|
|||||||
|
|
||||||
// The name of the struct/enum
|
// The name of the struct/enum
|
||||||
let name = input.ident;
|
let name = input.ident;
|
||||||
|
let must_implement = format_ident!("{}MustImplementRenderElement", name);
|
||||||
|
|
||||||
let expanded = quote! {
|
let expanded = quote! {
|
||||||
|
trait #must_implement : gpui::elements::RenderElement {}
|
||||||
|
impl #must_implement for #name {}
|
||||||
|
|
||||||
impl<V: gpui::View> gpui::elements::Element<V> for #name {
|
impl<V: gpui::View> gpui::elements::Element<V> for #name {
|
||||||
type LayoutState = gpui::elements::AnyElement<V>;
|
type LayoutState = gpui::elements::AnyElement<V>;
|
||||||
type PaintState = ();
|
type PaintState = ();
|
||||||
@ -307,7 +311,7 @@ pub fn element_derive(input: TokenStream) -> TokenStream {
|
|||||||
visible_bounds: gpui::geometry::rect::RectF,
|
visible_bounds: gpui::geometry::rect::RectF,
|
||||||
element: &mut gpui::elements::AnyElement<V>,
|
element: &mut gpui::elements::AnyElement<V>,
|
||||||
view: &mut V,
|
view: &mut V,
|
||||||
cx: &mut gpui::ViewContext<V>,
|
cx: &mut gpui::PaintContext<V>,
|
||||||
) {
|
) {
|
||||||
element.paint(scene, bounds.origin(), visible_bounds, view, cx);
|
element.paint(scene, bounds.origin(), visible_bounds, view, cx);
|
||||||
}
|
}
|
||||||
@ -332,7 +336,7 @@ pub fn element_derive(input: TokenStream) -> TokenStream {
|
|||||||
_: &(),
|
_: &(),
|
||||||
view: &V,
|
view: &V,
|
||||||
cx: &gpui::ViewContext<V>,
|
cx: &gpui::ViewContext<V>,
|
||||||
) -> serde_json::Value {
|
) -> gpui::serde_json::Value {
|
||||||
element.debug(view, cx)
|
element.debug(view, cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
crates/gpui_macros/tests/test.rs
Normal file
14
crates/gpui_macros/tests/test.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
use gpui::{elements::RenderElement, View, ViewContext};
|
||||||
|
use gpui_macros::Element;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_derive_render_element() {
|
||||||
|
#[derive(Element)]
|
||||||
|
struct TestElement {}
|
||||||
|
|
||||||
|
impl RenderElement for TestElement {
|
||||||
|
fn render<V: View>(&mut self, _: &mut V, _: &mut ViewContext<V>) -> gpui::AnyElement<V> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user