wip: scaffold proc crate and view macro

This commit is contained in:
🪞👃🪞 2025-05-03 17:04:21 +03:00
parent 21f7f6b38a
commit 2c797fd41f
9 changed files with 135 additions and 5 deletions

80
proc/src/proc_view.rs Normal file
View file

@ -0,0 +1,80 @@
use proc_macro::TokenStream;
use proc_macro2::{TokenStream as TokenStream2};
pub(crate) fn view_impl (meta: TokenStream, item: TokenStream) -> TokenStream {
let ViewMeta { output, define, attrs } = syn::parse_macro_input!(meta as ViewMeta);
let ViewItem { target, mapped, items } = syn::parse_macro_input!(item as ViewItem);
quote::quote! {
#attrs
impl #target {
#items
}
impl ::tengri::Content<#output> for #target {
fn content (&self) -> impl Render<#output> {
self.size.of(::tengri::View(self, #define))
}
}
impl<'a> ::tengri::ViewContext<'a, #output> for #target {
fn get_content_sym (&'a self, value: &Value<'a>) -> Option<RenderBox<'a, #output>> {
match value {
#mapped
_ => panic!("expected Sym(content), got: {value:?}")
}
//if let Value::Sym(s) = value {
//match *s {
//$($sym => Some($body.boxed()),)*
//_ => None
//}
//} else {
//panic!("expected Sym(content), got: {value:?}")
//}
}
}
}.into()
}
struct ViewMeta {
attrs: &'static str,
output: &'static str,
define: &'static str,
}
impl syn::parse::Parse for ViewMeta {
fn parse (input: syn::parse::ParseStream) -> syn::parse::Result<Self> {
Ok(Self {
attrs: "",
output: "",
define: "",
})
}
}
struct ViewItem {
items: &'static str,
target: &'static str,
mapped: &'static str,
}
impl syn::parse::Parse for ViewItem {
fn parse (input: syn::parse::ParseStream) -> syn::parse::Result<Self> {
Ok(Self {
items: "",
target: "",
mapped: "",
})
}
}
#[cfg(test)] #[test] fn test_view () {
let _: syn::ItemImpl = syn::parse_quote! {
#[tengri::view(Tui)]
impl SomeView {
#[tengri::view(":view")]
fn view (&self) -> impl Content<TuiOut> + use<'_> {
"view"
}
}
};
}