Skip to content

Update #[min/max] node macro attributes to #[soft/hard]_[min/max] and make them clamp their input data #2464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
May 1, 2025

Conversation

mTvare6
Copy link
Contributor

@mTvare6 mTvare6 commented Mar 18, 2025

No description provided.

@Keavon Keavon marked this pull request as draft March 20, 2025 08:11
@Keavon
Copy link
Member

Keavon commented Mar 20, 2025

Requires hard/soft range rework discussed in Discord.

@mTvare6
Copy link
Contributor Author

mTvare6 commented Mar 22, 2025

@Keavon I've changed them into hard_min and min(considering it to be the default). Do let me know if it should instead be called soft_min.

@mTvare6 mTvare6 marked this pull request as ready for review March 22, 2025 05:16
@Keavon Keavon force-pushed the master branch 3 times, most recently from aa7ff13 to e11b57a Compare April 6, 2025 11:41
@Keavon Keavon requested a review from TrueDoctor April 18, 2025 02:42
@TrueDoctor
Copy link
Member

Why do we have hard min and max but no hard/ soft ranges? And I'm not a fan of how the attributes are stored after parsing. Please choose a data representation which more closely aligns with what is a valid state. ( e.g. it shouldn't be possible to specify both hard and soft min and there should be a good error message in that case

@Keavon
Copy link
Member

Keavon commented Apr 18, 2025

Why do we have hard min and max but no hard/ soft ranges?

Range is always soft, it refers to how far left and right the draggable range slider goes. Specifying a range (to get the dragging slider kind of number input) and a hard min/max would be the expected way to set a range slider and prevent the user from typing values beyond the intended allowable bounds.

it shouldn't be possible to specify both hard and soft min and there should be a good error message in that case

If the soft min is larger than the hard min, that's allowed. But you're right that an error should be shown if they are equal (if so, soft should be removed) or reversed (this would indicate a mistake).

@Keavon Keavon force-pushed the fix-min-max-macro branch from 44f34bc to 2464b13 Compare May 1, 2025 05:27
@Keavon Keavon changed the title Fix min and max macro not enforcing limits when data flows Update #[min/max] node macro attributes to #[soft/hard]_[min/max] and make them clamp their input data May 1, 2025
Comment on lines +137 to +152
ParsedField::Regular { number_soft_min, number_hard_min, .. } => match (number_soft_min, number_hard_min) {
(Some(soft_min), _) => quote!(Some(#soft_min)),
(None, Some(hard_min)) => quote!(Some(#hard_min)),
(None, None) => quote!(None),
},
_ => quote!(None),
})
.collect();
let number_max_values: Vec<_> = fields
.iter()
.map(|field| match field {
ParsedField::Regular { number_max: Some(number_max), .. } => quote!(Some(#number_max)),
ParsedField::Regular { number_soft_max, number_hard_max, .. } => match (number_soft_max, number_hard_max) {
(Some(soft_max), _) => quote!(Some(#soft_max)),
(None, Some(hard_max)) => quote!(Some(#hard_max)),
(None, None) => quote!(None),
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the hard and soft cases of these match arms both producing the same result. Is that intentional and sensible here? Assuming so, they should also perhaps be combined, replacing None with _ and using | to put them on the same line.

@Keavon Keavon merged commit 9303953 into GraphiteEditor:master May 1, 2025
4 checks passed
@Keavon
Copy link
Member

Keavon commented May 1, 2025

Followup request: make the #[range(...)] min/max control the soft min/max of a range slider number input widget but still allow typing values above/below. This works successfully on some nodes like 'Copy to Points' because it's using the f64 typedef variant, Multiplier, where Some("Multiplier") => number_widget(default_info, number_input.unit("x")).into(), doesn't constrain a min/max, but others like the 'Generate Handles' node which uses a regular f64 with #[range((0., 1.))] does end up setting the .min(...) and .max(...) parts of the number input builder pattern construction. Specifically see this code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants