mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-27 06:38:12 +08:00
Collapse typed levels in To Graphic like the pre-flip list conversion
This commit is contained in:
@@ -110,12 +110,18 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, Vec<RegistryEntry>> {
|
|||||||
.map(|entry| (graphene_std::vector::morph::IDENTIFIER.clone(), entry)),
|
.map(|entry| (graphene_std::vector::morph::IDENTIFIER.clone(), entry)),
|
||||||
);
|
);
|
||||||
// Element-wise coercion into `Graphic` for single-typed leveled inputs,
|
// Element-wise coercion into `Graphic` for single-typed leveled inputs,
|
||||||
// served by the to_graphic rows.
|
// served by the hidden elementwise rows.
|
||||||
node_types.extend(
|
node_types.extend(
|
||||||
graphene_std::graphic::to_graphic_entries()
|
graphene_std::graphic::to_graphic_element_entries()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|entry| (ProtoNodeIdentifier::new("graphene_core::ops::IntoNode<Graphic>"), entry)),
|
.map(|entry| (ProtoNodeIdentifier::new("graphene_core::ops::IntoNode<Graphic>"), entry)),
|
||||||
);
|
);
|
||||||
|
// The typed-level collapse rows of To Graphic, served under its identifier.
|
||||||
|
node_types.extend(
|
||||||
|
graphene_std::graphic::to_graphic_typed_entries()
|
||||||
|
.into_iter()
|
||||||
|
.map(|entry| (graphene_std::graphic::to_graphic::IDENTIFIER.clone(), entry)),
|
||||||
|
);
|
||||||
// The transitional level bridge: a leveled wire materializes into the legacy
|
// The transitional level bridge: a leveled wire materializes into the legacy
|
||||||
// list an unconverted consumer expects. The rows are keyed under the legacy
|
// list an unconverted consumer expects. The rows are keyed under the legacy
|
||||||
// convert identifiers and die with the last legacy consumer.
|
// convert identifiers and die with the last legacy consumer.
|
||||||
|
|||||||
@@ -489,10 +489,33 @@ fn wrap_graphic_extent<T>(_content: ListIn<'_, T>, _level: LevelIn) -> GPoll<Ext
|
|||||||
GPoll::Final(Extent::Exactly(1))
|
GPoll::Final(Extent::Exactly(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts the level's elements into `Graphic` elements. A `Graphic` level passes through
|
/// Converts graphical content into a `Graphic` level. A `Graphic` level passes through
|
||||||
/// unchanged. The legacy list rows accept an unconverted producer's list value as one element.
|
/// unchanged; a typed level nests as one graphic lane, keeping the pre-flip list
|
||||||
|
/// collapse (`to_graphic_typed` serves those rows). The legacy list rows accept an
|
||||||
|
/// unconverted producer's list value as one element.
|
||||||
#[node_macro::node(category("General"))]
|
#[node_macro::node(category("General"))]
|
||||||
pub fn to_graphic<T: Into<Graphic> + Clone + Send + Sync + core_types::CacheHash + 'static>(
|
pub fn to_graphic<T: Into<Graphic> + Clone + Send + Sync + core_types::CacheHash + 'static>(
|
||||||
|
_: impl Ctx,
|
||||||
|
#[implementations(
|
||||||
|
Graphic,
|
||||||
|
List<Graphic>,
|
||||||
|
List<Vector>,
|
||||||
|
List<Raster<CPU>>,
|
||||||
|
List<Raster<GPU>>,
|
||||||
|
List<Color>,
|
||||||
|
List<GradientStops>,
|
||||||
|
List<String>,
|
||||||
|
)]
|
||||||
|
content: T,
|
||||||
|
) -> Graphic {
|
||||||
|
content.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The elementwise `Graphic` coercion the compiler-inserted converts use: each
|
||||||
|
/// lane's element converts on its own, so a typed wire feeds a graphic input
|
||||||
|
/// without changing the level's shape. Registered under the convert identifier.
|
||||||
|
#[node_macro::node(category(""))]
|
||||||
|
pub fn to_graphic_element<T: Into<Graphic> + Clone + Send + Sync + core_types::CacheHash + 'static>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Graphic,
|
Graphic,
|
||||||
@@ -515,6 +538,22 @@ pub fn to_graphic<T: Into<Graphic> + Clone + Send + Sync + core_types::CacheHash
|
|||||||
content.into()
|
content.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The typed-level conversion: the whole level nests as one graphic lane, as
|
||||||
|
/// the pre-flip `Into<Graphic>` list collapse did. Registered under the to
|
||||||
|
/// graphic identifier.
|
||||||
|
#[node_macro::node(category(""), extent(wrap_graphic_extent))]
|
||||||
|
pub fn to_graphic_typed<T: Clone + Send + Sync + core_types::CacheHash + 'static>(
|
||||||
|
_: impl Ctx + ExtractIndex + InjectIndex + Copy,
|
||||||
|
#[implementations(Vector, Raster<CPU>, Raster<GPU>, Color, GradientStops, String)] content: IList<T>,
|
||||||
|
) -> Result<IList<Graphic>, Interrupt> {
|
||||||
|
// SAFETY: a materialized input's frames are arena-resident.
|
||||||
|
let item = unsafe { core_types::record::GroupItem::from_resident(content.batch()) };
|
||||||
|
Ok(Graphic::Group(core_types::record::Group {
|
||||||
|
row: None,
|
||||||
|
content: core_types::record::GroupContent::Run(item),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
/// The transitional level bridge: the wire's records as the legacy list an
|
/// The transitional level bridge: the wire's records as the legacy list an
|
||||||
/// unconverted consumer expects, attributes copied through their erased
|
/// unconverted consumer expects, attributes copied through their erased
|
||||||
/// reads. Registered under the legacy convert identifiers; the rows die with
|
/// reads. Registered under the legacy convert identifiers; the rows die with
|
||||||
@@ -531,7 +570,8 @@ pub fn level_to_list<T: Clone + Send + Sync + CacheHash + 'static>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub use _level_to_list_mod::level_to_list_entries;
|
pub use _level_to_list_mod::level_to_list_entries;
|
||||||
pub use _to_graphic_mod::to_graphic_entries;
|
pub use _to_graphic_element_mod::to_graphic_element_entries;
|
||||||
|
pub use _to_graphic_typed_mod::to_graphic_typed_entries;
|
||||||
|
|
||||||
/// Removes a level of nesting from a `Graphic[]`, or all nesting if "Fully Flatten" is enabled.
|
/// Removes a level of nesting from a `Graphic[]`, or all nesting if "Fully Flatten" is enabled.
|
||||||
#[node_macro::node(category("General"), extent(flatten_graphic_extent))]
|
#[node_macro::node(category("General"), extent(flatten_graphic_extent))]
|
||||||
|
|||||||
Reference in New Issue
Block a user