Shaders: add gcore-shaders and make graster-nodes no-std (#2925)

* gcore-shaders: add crate, move `color` and `blending` from gcore

* gcore-shaders: move `AsU32`

* gcore-shaders: move `ChoiceType`, switch `Cow` for `&str`, adjust node macro

* gcore-shaders: move `registry::types`

* gcore-shaders: move `context::Ctx`

* raster-nodes: make it `no_std` with `std` feature

* gcore-shaders: fix doctest
This commit is contained in:
Firestar99
2025-07-25 19:53:26 +02:00
committed by GitHub
parent 4d5a1a6ff1
commit 4fec24893e
28 changed files with 364 additions and 247 deletions

View File

@@ -111,13 +111,21 @@ fn derive_enum(enum_attributes: &[Attribute], name: Ident, input: syn::DataEnum)
})
.collect();
let crate_name = proc_macro_crate::crate_name("graphene-core")
.map_err(|e| syn::Error::new(Span::call_site(), format!("Failed to find location of graphene_core. Make sure it is imported as a dependency: {}", e)))?;
let crate_name = match crate_name {
proc_macro_crate::FoundCrate::Itself => quote!(crate),
proc_macro_crate::FoundCrate::Name(name) => {
let identifier = Ident::new(&name, Span::call_site());
quote! { #identifier }
let crate_name = {
let crate_name = proc_macro_crate::crate_name("graphene-core-shaders")
.or_else(|_e| proc_macro_crate::crate_name("graphene-core"))
.map_err(|e| {
syn::Error::new(
Span::call_site(),
format!("Failed to find location of 'graphene_core' or 'graphene-core-shaders'. Make sure it is imported as a dependency: {}", e),
)
})?;
match crate_name {
proc_macro_crate::FoundCrate::Itself => quote!(crate),
proc_macro_crate::FoundCrate::Name(name) => {
let identifier = Ident::new(&name, Span::call_site());
quote! { #identifier }
}
}
};
@@ -140,19 +148,19 @@ fn derive_enum(enum_attributes: &[Attribute], name: Ident, input: syn::DataEnum)
let docstring = match &variant.basic_item.description {
Some(s) => {
let s = s.trim();
quote! { Some(::std::borrow::Cow::Borrowed(#s)) }
quote! { Some(#s) }
}
None => quote! { None },
};
let icon = match &variant.basic_item.icon {
Some(s) => quote! { Some(::std::borrow::Cow::Borrowed(#s)) },
Some(s) => quote! { Some(#s) },
None => quote! { None },
};
quote! {
(
#name::#vname, #crate_name::registry::VariantMetadata {
name: ::std::borrow::Cow::Borrowed(#vname_str),
label: ::std::borrow::Cow::Borrowed(#label),
#name::#vname, #crate_name::choice_type::VariantMetadata {
name: #vname_str,
label: #label,
docstring: #docstring,
icon: #icon,
}
@@ -174,10 +182,10 @@ fn derive_enum(enum_attributes: &[Attribute], name: Ident, input: syn::DataEnum)
}
}
impl #crate_name::registry::ChoiceTypeStatic for #name {
const WIDGET_HINT: #crate_name::registry::ChoiceWidgetHint = #crate_name::registry::ChoiceWidgetHint::#widget_hint;
impl #crate_name::choice_type::ChoiceTypeStatic for #name {
const WIDGET_HINT: #crate_name::choice_type::ChoiceWidgetHint = #crate_name::choice_type::ChoiceWidgetHint::#widget_hint;
const DESCRIPTION: Option<&'static str> = #enum_description;
fn list() -> &'static [&'static [(Self, #crate_name::registry::VariantMetadata)]] {
fn list() -> &'static [&'static [(Self, #crate_name::choice_type::VariantMetadata)]] {
&[ #(#group)* ]
}
}