From 53f02bb48e085ab2ec6e81c30df42ea3098df05f Mon Sep 17 00:00:00 2001 From: Kyle Van Essen Date: Mon, 3 Apr 2023 22:52:46 -0700 Subject: [PATCH 1/2] Constrain label measurements to the provided constraint size --- .../Sources/AttributedLabel.swift | 10 +++++++++- CHANGELOG.md | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/BlueprintUICommonControls/Sources/AttributedLabel.swift b/BlueprintUICommonControls/Sources/AttributedLabel.swift index f9e1c3fa2..ace6cee19 100644 --- a/BlueprintUICommonControls/Sources/AttributedLabel.swift +++ b/BlueprintUICommonControls/Sources/AttributedLabel.swift @@ -128,8 +128,16 @@ public struct AttributedLabel: Element, Hashable { return ElementContent { constraint, environment -> CGSize in let label = Self.prototypeLabel + let constraint = constraint.maximum + label.update(model: self, text: text, environment: environment, isMeasuring: true) - return label.sizeThatFits(constraint.maximum) + + let size = label.sizeThatFits(constraint) + + return CGSize( + width: min(constraint.width, size.width), + height: min(constraint.height, size.height) + ) } } diff --git a/CHANGELOG.md b/CHANGELOG.md index b674c3ec2..a9d448ccd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- `AttributedLabel` and `Label` will now restrict their measured size to the provided measurement constraint. + ### Deprecated ### Security From b9905f4d68fcbe40e811b021866f154629d749c7 Mon Sep 17 00:00:00 2001 From: Kyle Van Essen Date: Mon, 3 Apr 2023 22:54:51 -0700 Subject: [PATCH 2/2] Fix: Tests --- .../Tests/Sources/AttributedLabelTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlueprintUICommonControls/Tests/Sources/AttributedLabelTests.swift b/BlueprintUICommonControls/Tests/Sources/AttributedLabelTests.swift index b612db48b..a979fe76a 100644 --- a/BlueprintUICommonControls/Tests/Sources/AttributedLabelTests.swift +++ b/BlueprintUICommonControls/Tests/Sources/AttributedLabelTests.swift @@ -191,7 +191,7 @@ class AttributedLabelTests: XCTestCase { test( in: CGSize(width: 30, height: 20), - expectedSize: CGSize(width: 30, height: 235.5) + expectedSize: CGSize(width: 30, height: 20.0) ) test( in: CGSize(width: 100, height: 300),