Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions sdk/cli/tests/cli_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,11 +768,22 @@ fn ios_render_button_draws_button_ios_and_foundation_is_unchanged() {
let ios = render_scene(&root, &["button", "--platform", "ios"]);
assert_eq!(ios["component"], "button-ios", "{ios}");
let container = &ios["nodes"][0];
// The radius token (20) is larger than half the 34.2 high container, so the corner is
// clamped to a pill.
// The radius comes from the size token (20 for m) and is clamped to half the 34.2 high
// container, so the corner is a pill: radius == min(token value, height / 2).
let radius_token = container["tokens"]
.as_array()
.and_then(|t| t.iter().find(|t| t["prop"] == "cornerRadius"))
.unwrap_or_else(|| panic!("no cornerRadius token in {ios}"));
assert_eq!(radius_token["token"], "button-md-radius-capsule", "{ios}");
let token_value: f64 = radius_token["value"]
.as_str()
.and_then(|v| v.strip_suffix("px"))
.and_then(|v| v.parse().ok())
.unwrap_or_else(|| panic!("unexpected radius value in {ios}"));
assert_eq!(token_value, 20.0, "{ios}");
assert_eq!(
container["radius"].as_f64().unwrap(),
container["h"].as_f64().unwrap() / 2.0,
token_value.min(container["h"].as_f64().unwrap() / 2.0),
"{ios}"
);
assert_eq!(container["w"], 60.2, "{ios}");
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/src/visual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1757,13 +1757,13 @@ pub fn solve(variant: &CompiledVariant, req: &RenderRequest) -> Result<Scene, St
})
}

/// Closed outline of a rect with independent corner radii `[tl, tr, br, bl]`.
/// A corner radius cannot exceed half the box's width or height, like CSS `border-radius`:
/// an oversized radius draws a pill, not an ellipse.
fn clamp_radius(r: f64, w: f64, h: f64) -> f64 {
r.min(w / 2.0).min(h / 2.0)
}

/// Closed outline of a rect with independent corner radii `[tl, tr, br, bl]`.
fn rounded_path(x: f64, y: f64, w: f64, h: f64, r: [f64; 4]) -> String {
let [tl, tr, br, bl] = r;
format!(
Expand Down
Loading