fix: make hard controls also limit range movement

This commit is contained in:
mtvare6
2025-07-12 05:02:00 +05:30
parent 6780626768
commit 6aee1e6fb9
7 changed files with 70 additions and 6 deletions

View File

@@ -255,6 +255,15 @@ pub struct NumberInput {
#[serde(rename = "rangeMax")]
pub range_max: Option<f64>,
// TODO: Make this (and range_max) apply to both Range and Increment modes when dragging with the mouse
#[serde(rename = "hardMin")]
#[widget_builder(skip)]
pub hard_min: Option<f64>,
#[serde(rename = "hardMax")]
#[widget_builder(skip)]
pub hard_max: Option<f64>,
// Styling
#[serde(rename = "minWidth")]
pub min_width: u32,
@@ -295,6 +304,14 @@ impl NumberInput {
self.range_max = Some(val);
self
}
pub fn hard_min(mut self, val: f64) -> Self {
self.hard_min = Some(val);
self
}
pub fn hard_max(mut self, val: f64) -> Self {
self.hard_max = Some(val);
self
}
pub fn mode_range(mut self) -> Self {
self.mode = NumberInputMode::Range;
self

View File

@@ -2653,6 +2653,8 @@ impl DocumentMessageHandler {
.disabled(disabled)
.min(0.)
.max(100.)
.hard_min(0.)
.hard_max(100.)
.range_min(Some(0.))
.range_max(Some(100.))
.mode_range()
@@ -2675,6 +2677,8 @@ impl DocumentMessageHandler {
.disabled(disabled)
.min(0.)
.max(100.)
.hard_min(0.)
.hard_max(100.)
.range_min(Some(0.))
.range_max(Some(100.))
.mode_range()

View File

@@ -118,19 +118,25 @@ pub(crate) fn property_from_type(
node_id: NodeId,
index: usize,
ty: &Type,
number_options: (Option<f64>, Option<f64>, Option<(f64, f64)>),
number_options: (Option<f64>, Option<f64>, Option<f64>, Option<f64>, Option<(f64, f64)>),
unit: Option<&str>,
display_decimal_places: Option<u32>,
step: Option<f64>,
context: &mut NodePropertiesContext,
) -> Result<Vec<LayoutGroup>, Vec<LayoutGroup>> {
let (mut number_min, mut number_max, range) = number_options;
let (mut number_min, mut number_max, number_hard_min, number_hard_max, range) = number_options;
let mut number_input = NumberInput::default();
if let Some((range_start, range_end)) = range {
number_min = Some(range_start);
number_max = Some(range_end);
number_input = number_input.mode_range().min(range_start).max(range_end);
}
if let Some(hard_min) = number_hard_min {
number_input = number_input.hard_min(hard_min)
}
if let Some(hard_max) = number_hard_max {
number_input = number_input.hard_max(hard_max)
}
if let Some(unit) = unit {
number_input = number_input.unit(unit);
}
@@ -1427,7 +1433,7 @@ pub(crate) fn generate_node_properties(node_id: NodeId, context: &mut NodeProper
return Vec::new();
};
let mut number_options = (None, None, None);
let mut number_options = (None, None, None, None, None);
let mut display_decimal_places = None;
let mut step = None;
let mut unit_suffix = None;
@@ -1439,7 +1445,7 @@ pub(crate) fn generate_node_properties(node_id: NodeId, context: &mut NodeProper
.get(&proto_node_identifier)
.and_then(|metadata| metadata.fields.get(input_index))
{
number_options = (field.number_min, field.number_max, field.number_mode_range);
number_options = (field.number_min, field.number_max, field.number_hard_min, field.number_hard_max, field.number_mode_range);
display_decimal_places = field.number_display_decimal_places;
unit_suffix = field.unit;
step = field.number_step;