Actually fixed widgets![] release build.

This commit is contained in:
Samuel Guerra 2021-10-14 18:54:09 -03:00
parent 5d29bfabda
commit f940033dc6
4 changed files with 64 additions and 29 deletions

View File

@ -75,7 +75,7 @@ pub use ui_list::*;
// proc-macros used internally during widget creation.
#[doc(hidden)]
pub use zero_ui_proc_macros::{property_new, widget_declare, widget_inherit, widget_new};
pub use zero_ui_proc_macros::{property_new, static_list, widget_declare, widget_inherit, widget_new};
/// Expands an `impl` block into an [`UiNode`] trait implementation.
///

View File

@ -763,20 +763,8 @@ macro_rules! __nodes {
$crate::UiNodeList::chain_nodes(w8, $crate::__nodes!($($w_rest),+))
})
};
(
$(
$(#[$meta:meta])* $node:expr
),*
$(,)?
) => {
$crate::opaque_nodes({
let nodes = $crate::UiNodeList0;
$(
$(#[$meta])*
let nodes = nodes.push($node);
)*
nodes
})
($($tt:tt)*) => {
$crate::opaque_nodes($crate::static_list!($crate::UiNodeList0; $($tt)*))
};
}
@ -790,20 +778,8 @@ macro_rules! __widgets {
$crate::WidgetList::chain(w8, $crate::__widgets!($($w_rest),+))
})
};
(
$(
$(#[$meta:meta])* $wgt:expr
),*
$(,)?
) => {
$crate::opaque_widgets({
let widgets = $crate::WidgetList0;
$(
$(#[$meta])*
let widgets = widgets.push($wgt);
)*
widgets
})
($($tt:tt)*) => {
$crate::opaque_widgets($crate::static_list!($crate::WidgetList0; $($tt)*))
};
}

View File

@ -14,6 +14,7 @@ mod util;
mod derive_service;
pub(crate) mod expr_var;
mod hex_color;
mod static_list;
mod when_var;
mod impl_ui_node;
@ -135,3 +136,9 @@ pub fn trace(input: TokenStream) -> TokenStream {
eprintln!("{}", input.to_string());
input
}
#[doc(hidden)]
#[proc_macro]
pub fn static_list(input: TokenStream) -> TokenStream {
static_list::expand(input)
}

View File

@ -0,0 +1,52 @@
use proc_macro2::TokenStream;
use syn::{bracketed, parse::Parse, parse_macro_input, Expr, Token};
pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let Input { init, attrs, exprs } = parse_macro_input!(input as Input);
let r = quote! {
{
let l = #init;
#(
#attrs
let l = l.push(#exprs);
)*
l
}
};
r.into()
}
struct Input {
init: Expr,
attrs: Vec<TokenStream>,
exprs: Vec<Expr>,
}
impl Parse for Input {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
let init = input.parse::<Expr>()?;
let _ = input.parse::<Token![;]>()?;
let mut attrs = vec![];
let mut exprs = vec![];
while !input.is_empty() {
let mut attr = TokenStream::new();
while input.peek(Token![#]) {
let _ = input.parse::<Token![#]>().unwrap();
let a;
let _ = bracketed!(a in input);
let a = a.parse::<TokenStream>().unwrap();
attr.extend(quote! { #[#a] });
}
attrs.push(attr);
exprs.push(input.parse::<Expr>()?);
if input.peek(Token![,]) {
input.parse::<Token![,]>().unwrap();
}
}
Ok(Input { init, attrs, exprs })
}
}