temperature converter
zsx / 7guis
program
load core::zsx::*; load core::math::round; fun one_decimal(x: float) -> float { round(x * 10.0) / 10.0 } fun main() { mut celsius: str = ""; mut fahrenheit: str = ""; imu converter: </> ::= <> <input value={celsius} @input={fn(e) => { celsius = e.value; match e.value.parse_float() { Option::Some(c) => { imu f: float = one_decimal(c * 9.0 / 5.0 + 32.0); fahrenheit = f.to_str(); } Option::None => {} }; }} /> <label>Celsius =</label> <input value={fahrenheit} @input={fn(e) => { fahrenheit = e.value; match e.value.parse_float() { Option::Some(f) => { imu c: float = one_decimal((f - 32.0) * 5.0 / 9.0); celsius = c.to_str(); } Option::None => {} }; }} /> <label>Fahrenheit</label> </>; #render converter; }
This programs declares two textfields (TC and TF) representing the temperature in Celcius and Fahrenheit. Two labels are associated to a specific textfields. At start, both TC and TF are empty.
source — 7GUIs (Temperature Converter)