Skip to content

Commit a2726ea

Browse files
committed
feat: allow fractional units in widget width, length, and offset
1 parent 05bd14f commit a2726ea

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

packages/client-api/src/config/config-schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { z } from 'zod';
33
const length = z
44
.string()
55
.regex(
6-
/^([+-]?\d+)(%|px)?$/,
6+
/^([+-]?\d+(?:\.\d+)?)(%|px)?$/,
77
"Not a valid length value. Must be of format '10px' or '10%'.",
88
);
99

packages/desktop/src/common/length_value.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ impl FromStr for LengthValue {
3939
type Err = anyhow::Error;
4040

4141
/// Parses a string containing a number followed by a unit (`px`, `%`).
42-
/// Allows for negative numbers.
42+
/// Allows for negative and fractional numbers.
4343
///
4444
/// Example:
4545
/// ```
4646
/// LengthValue::from_str("100px") // { amount: 100.0, unit: LengthUnit::Pixel }
47+
/// LengthValue::from_str("50.5%") // { amount: 50.5, unit: LengthUnit::Percentage }
4748
/// ```
4849
fn from_str(unparsed: &str) -> anyhow::Result<Self> {
49-
let units_regex = Regex::new(r"([+-]?\d+)(%|px)?")?;
50+
let units_regex = Regex::new(r"([+-]?\d+(?:\.\d+)?)(%|px)?")?;
5051

5152
let err_msg = format!(
5253
"Not a valid length value '{}'. Must be of format '10px' or '10%'.",

0 commit comments

Comments
 (0)