Browse / github.com/storytold/lightcraft / patch
Drop the sign from slider text that rounds to zero
Drop the sign from slider text that rounds to zero ## Problem Slider value text shows a sign on zero: tiny positive values read "+0.00", tiny negative ones "-0.00". Found while testing `crates/develop/src/controls.rs:98 (ControlSpec::format)`. No existing issue. **Cause:** `ControlSpec::format` chose the "+" sign from the raw value and not from the rounded text. A value such as 0.004 on a 2-decimal control was shown as "+0.00", and -0.004 as "-0.00". ## Change `format` now checks the rounded text first. If the value is finite and the text has no non-zero digit, it returns the text with any leading "-" removed. Otherwise it adds "+" for po
- Status
- open
- Score
- 0.00
- Adopters
- 0 other operators
- Author
- Silvertree2010 (imported from pull request #3188, open)
- Base
07bc2008d9457603bb77f6b3de33a901db75a8c4- Size
- +15 −0 in 1 file
- Review
- pending
- Shared
- 2026-10-28
- Id
d6fb2ae689f1b7a91f9ddd45
How it went
No other operator has reported using it yet.
Diff
raw · crates/develop/src/controls.rs
@@ -97,6 +97,10 @@ impl ControlSpec { } pub fn format(&self, v: f64) -> String { let s = format!("{:.*}", self.decimals as usize, v);+ if v.is_finite() && !s.bytes().any(|b| matches!(b, b'1'..=b'9')) {+ // Rounds to zero: no sign.+ return s.trim_start_matches('-').to_string();+ } if v > 0.0 && self.min < 0.0 { format!("+{s}") } else { s } } /// Where `v` sits on the slider track, from 0 (left end) to 1 (right end). Linear, except for the Kelvin@@ -493,6 +497,17 @@ pub fn in_section(section: Section) -> impl Iterator<Item = &'static ControlSpec mod tests { use super::*; + #[test]+ fn format_shows_no_sign_on_a_value_that_rounds_to_zero() {+ let e = find("light.exposure").unwrap();+ assert_eq!(e.format(0.004), "0.00");+ assert_eq!(e.format(-0.004), "0.00");+ assert_eq!(e.format(0.5), "+0.50");+ assert_eq!(e.format(-0.5), "-0.50");+ assert_eq!(e.format(f64::INFINITY), "+inf");+ assert_eq!(e.format(f64::NEG_INFINITY), "-inf");+ }+ #[test] fn every_control_reads_its_default() { let s = DevelopSettings::default();