Move the "Text" category nodes from gcore/src/logic.rs to text/src/lib.rs (#4042)

Move the String category nodes from gcore/src/logic.rs to text/src/lib.rs
This commit is contained in:
Keavon Chambers
2026-04-23 18:12:28 -07:00
committed by GitHub
parent 1444c333ab
commit a59fed9d1c
13 changed files with 240 additions and 238 deletions

View File

@@ -9,6 +9,7 @@ license = "MIT OR Apache-2.0"
[dependencies]
core-types = { workspace = true }
node-macro = { workspace = true }
graphic-types = { workspace = true }
vector-types = { workspace = true }
# Workspace dependencies

View File

@@ -1,8 +1,11 @@
use core_types::registry::types::{Fraction, Percentage, PixelSize, TextArea};
use core_types::Context;
use core_types::registry::types::{Fraction, Percentage, PixelSize};
use core_types::table::Table;
use core_types::transform::Footprint;
use core_types::{Color, Ctx, num_traits};
use glam::{DAffine2, DVec2};
use graphic_types::raster_types::{CPU, GPU, Raster};
use graphic_types::{Artboard, Graphic, Vector};
use log::warn;
use math_parser::ast;
use math_parser::context::{EvalContext, NothingMap, ValueProvider};
@@ -735,6 +738,53 @@ fn logical_not(
!input
}
/// Evaluates either the "If True" or "If False" input branch based on whether the input condition is true or false.
#[node_macro::node(category("Math: Logic"))]
async fn switch<T, C: Send + 'n + Clone>(
#[implementations(Context)] ctx: C,
condition: bool,
#[expose]
#[implementations(
Context -> String,
Context -> bool,
Context -> f32,
Context -> f64,
Context -> u32,
Context -> u64,
Context -> DVec2,
Context -> DAffine2,
Context -> Table<Artboard>,
Context -> Table<Graphic>,
Context -> Table<Vector>,
Context -> Table<Raster<CPU>>,
Context -> Table<Raster<GPU>>,
Context -> Table<Color>,
Context -> Table<GradientStops>,
)]
if_true: impl Node<C, Output = T>,
#[expose]
#[implementations(
Context -> String,
Context -> bool,
Context -> f32,
Context -> f64,
Context -> u32,
Context -> u64,
Context -> DVec2,
Context -> DAffine2,
Context -> Table<Artboard>,
Context -> Table<Graphic>,
Context -> Table<Vector>,
Context -> Table<Raster<CPU>>,
Context -> Table<Raster<GPU>>,
Context -> Table<Color>,
Context -> Table<GradientStops>,
)]
if_false: impl Node<C, Output = T>,
) -> T {
if condition { if_true.eval(ctx).await } else { if_false.eval(ctx).await }
}
/// Constructs a bool value which may be set to true or false.
#[node_macro::node(category("Value"))]
fn bool_value(_: impl Ctx, _primary: (), #[name("Bool")] bool_value: bool) -> bool {
@@ -823,12 +873,6 @@ fn sample_gradient(_: impl Ctx, _primary: (), gradient: Table<GradientStops>, po
Table::new_from_element(color)
}
/// Constructs a string value which may be set to any plain text.
#[node_macro::node(category("Value"))]
fn string_value(_: impl Ctx, _primary: (), string: TextArea) -> String {
string
}
/// Constructs a footprint value which may be set to any transformation of a unit square describing a render area, and a render resolution at least 1x1 integer pixels.
#[node_macro::node(category("Value"))]
fn footprint_value(_: impl Ctx, _primary: (), transform: DAffine2, #[default(100., 100.)] resolution: PixelSize) -> Footprint {