use super::parse_helpers::{ControlDirective, parse_float_range_control};
use super::{ShaderControlKind, ShaderControlWarning};
pub(super) fn parse_vec2(
directive: &ControlDirective<'_>,
warnings: &mut Vec<ShaderControlWarning>,
) -> Option<ShaderControlKind> {
directive.warn_unknown_fields(warnings, &["min", "max", "step", "label", "group"]);
if !directive.require_uniform_type(
warnings,
"vec2",
format!(
"Vec2 control for `{}` must attach to `uniform vec2`",
directive.uniform_name
),
) {
return None;
}
let (min, max, step) =
match parse_float_range_control("Vec2", directive.uniform_name, directive.key_values) {
Ok(values) => values,
Err(error) => {
directive.warn(warnings, error);
return None;
}
};
let label = directive.label(warnings, "Vec2");
Some(ShaderControlKind::Vec2 {
min,
max,
step,
label,
})
}
pub(super) fn parse_point(
directive: &ControlDirective<'_>,
warnings: &mut Vec<ShaderControlWarning>,
) -> Option<ShaderControlKind> {
directive.warn_unknown_fields(warnings, &["label", "group"]);
if !directive.require_uniform_type(
warnings,
"vec2",
format!(
"Point control for `{}` must attach to `uniform vec2`",
directive.uniform_name
),
) {
return None;
}
let label = directive.label(warnings, "Point");
Some(ShaderControlKind::Point { label })
}
pub(super) fn parse_range(
directive: &ControlDirective<'_>,
warnings: &mut Vec<ShaderControlWarning>,
) -> Option<ShaderControlKind> {
directive.warn_unknown_fields(warnings, &["min", "max", "step", "label", "group"]);
if !directive.require_uniform_type(
warnings,
"vec2",
format!(
"Range control for `{}` must attach to `uniform vec2`",
directive.uniform_name
),
) {
return None;
}
let (min, max, step) =
match parse_float_range_control("Range", directive.uniform_name, directive.key_values) {
Ok(values) => values,
Err(error) => {
directive.warn(warnings, error);
return None;
}
};
let label = directive.label(warnings, "Range");
Some(ShaderControlKind::Range {
min,
max,
step,
label,
})
}