use super::parse_helpers::ControlDirective;
use super::{ShaderControlKind, ShaderControlWarning};
pub(super) fn parse_checkbox(
directive: &ControlDirective<'_>,
warnings: &mut Vec<ShaderControlWarning>,
) -> Option<ShaderControlKind> {
directive.warn_unknown_fields(warnings, &["label", "group"]);
if !directive.require_uniform_type(
warnings,
"bool",
format!(
"Checkbox control for `{}` must attach to `uniform bool`",
directive.uniform_name
),
) {
return None;
}
let label = directive.label(warnings, "Checkbox");
Some(ShaderControlKind::Checkbox { label })
}
pub(super) fn parse_color(
directive: &ControlDirective<'_>,
warnings: &mut Vec<ShaderControlWarning>,
) -> Option<ShaderControlKind> {
directive.warn_unknown_fields(warnings, &["alpha", "label", "group"]);
if directive.uniform_type != "vec3" && directive.uniform_type != "vec4" {
directive.warn(
warnings,
format!(
"Color control for `{}` must attach to `uniform vec3` or `uniform vec4`",
directive.uniform_name
),
);
return None;
}
let default_alpha = directive.uniform_type == "vec4";
let alpha = match directive.key_values.get("alpha").map(String::as_str) {
Some("true") => true,
Some("false") => false,
Some(_) => {
directive.warn(
warnings,
format!(
"Color `{}` alpha must be `true` or `false`; using default",
directive.uniform_name
),
);
default_alpha
}
None => default_alpha,
};
if directive.uniform_type == "vec3" && alpha {
directive.warn(
warnings,
format!(
"Color control `{}` cannot use alpha=true with `uniform vec3`",
directive.uniform_name
),
);
return None;
}
let label = directive.label(warnings, "Color");
Some(ShaderControlKind::Color { alpha, label })
}