Add a derive macro for Element

To turn any struct into a composite element, you can implement a render method
with the following signature:

fn render<V: View>(&mut self, view: &mut V, cx: &mut ViewContext<V>) -> AnyElement<V>;

Then add #[derive(Element)] to the struct definition.

This will make it easier to introduce higher-level components that are expressed in
terms of other elements.
This commit is contained in:
Nathan Sobo 2023-06-25 07:51:50 -06:00
parent 82bd5fb564
commit bede668b14
3 changed files with 69 additions and 94 deletions

View file

@ -26,7 +26,7 @@ pub mod color;
pub mod json;
pub mod keymap_matcher;
pub mod platform;
pub use gpui_macros::test;
pub use gpui_macros::{test, Element};
pub use window::{Axis, SizeConstraint, Vector2FExt, WindowContext};
pub use anyhow;