From e2772d1e61bb9c518480bac68120df2efa3876eb Mon Sep 17 00:00:00 2001 From: Noah Blake Date: Sun, 13 Sep 2020 20:13:01 -0400 Subject: [PATCH] [Gardening] Rename semicircular to capsule, handle narrow capsule case --- BlueprintUICommonControls/Sources/Box.swift | 6 +++--- .../Tests/Sources/BoxTests.swift | 9 +++++++-- .../BoxTests/test_cornerStyle_longCapsule.png | Bin 0 -> 2283 bytes ...ular.png => test_cornerStyle_wideCapsule.png} | Bin CHANGELOG.md | 4 ++-- 5 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 BlueprintUICommonControls/Tests/Sources/ReferenceImages/BoxTests/test_cornerStyle_longCapsule.png rename BlueprintUICommonControls/Tests/Sources/ReferenceImages/BoxTests/{test_cornerStyle_semicircular.png => test_cornerStyle_wideCapsule.png} (100%) diff --git a/BlueprintUICommonControls/Sources/Box.swift b/BlueprintUICommonControls/Sources/Box.swift index 9f74dae73..c53ed30ab 100644 --- a/BlueprintUICommonControls/Sources/Box.swift +++ b/BlueprintUICommonControls/Sources/Box.swift @@ -102,7 +102,7 @@ extension Box { public enum CornerStyle { case square - case semicircular + case capsule case rounded(radius: CGFloat) } @@ -145,8 +145,8 @@ extension Box.CornerStyle { switch self { case .square: return 0 - case .semicircular: - return bounds.height / 2.0 + case .capsule: + return min(bounds.height, bounds.width) / 2.0 case let .rounded(radius: radius): return radius } diff --git a/BlueprintUICommonControls/Tests/Sources/BoxTests.swift b/BlueprintUICommonControls/Tests/Sources/BoxTests.swift index 17059af00..aa8d2a720 100644 --- a/BlueprintUICommonControls/Tests/Sources/BoxTests.swift +++ b/BlueprintUICommonControls/Tests/Sources/BoxTests.swift @@ -22,11 +22,16 @@ class BoxTests: XCTestCase { do { var box = Box() box.backgroundColor = .blue - box.cornerStyle = .semicircular + box.cornerStyle = .capsule compareSnapshot( of: box, size: CGSize(width: 200, height: 100), - identifier: "semicircular") + identifier: "wideCapsule") + + compareSnapshot( + of: box, + size: CGSize(width: 100, height: 200), + identifier: "longCapsule") } do { diff --git a/BlueprintUICommonControls/Tests/Sources/ReferenceImages/BoxTests/test_cornerStyle_longCapsule.png b/BlueprintUICommonControls/Tests/Sources/ReferenceImages/BoxTests/test_cornerStyle_longCapsule.png new file mode 100644 index 0000000000000000000000000000000000000000..5123ac4960a6c7876b893980b06778c7c3ab9e32 GIT binary patch literal 2283 zcmc&!`#;ldAKzwUEn`VeN$a57G0}{5OW&=HIn5l>5)Ti?i0QVQk<>^zPE<}gjpC70 z$gy(BDMO@*QaR*Ms^L}&9X#LNujh6D3(xg>eXjTCbiF^<=a+W^oo0zfsi7bc2-=ED zb_CG}v|gk%cx#xEAAtbnI9ie*RfFmaU_fRvtbFb4AUdFrgh1o`A#h0xXlkHAAW{M- zL<&TxBqxCVQ}q!@{p0sa8gB+xjDn!1XOe+c?;eJdiIGL2M#J4Y`FRRv_)2S!hq-rJ5?htZKBD}eu9-`eNNRemuJ8y)3!Q#>zdWaaUHt>tgd z7*%zKuJ5{#`D&`6;&HocjDbOWH=?>xrlJaVX;Sv%j~RTkxZj4?#?-fkG`Gpn?4$Yo zbKOHy*V=@WzH&-Mhp`0(?JrfUn_rs8;^+gH35JbTMWNWMSKFue95V5fAuC`w-YEn1 zVivkrw7t4beqi7QA`RZ@mVKBLtg9xovWigOZ5c@vO56AOEq2$S18qdZTB+r_o)Hlt z>S@o3E-sLUJ3ez*`p) zcF8}(7HgK!^BE6ww37=dxrs~hlq)l}6$bsu1Q`PoWxM;VOq-MpSgJG~3q5m7mM zZ86e(m7PRwlbSxN02}5@k4#v~-cHJ4jzEj# z0CAKlc4+9$7g^}KC{I>J4!N{&-SkZWAZ>`5fNNv__EHZlhV7X0;tAWK(=D$QhOS7b zbU)$qeMYn)k7Mi!sVaEfS-rLQTc9nBGM-nOd&ftW6U{@$_c`_=3Ylsn{ANo4PM)*X?9bW?Cj-tIq=QI(k$^pL z6t)+uHs+}j`a{p_eIRE@$u;Hx0%l|gTmZFTbMx+< z9U@Q+v?L-R&TTX5qASL6S*(FlI*T3-(*W+`&$;6ANrh8?OMt5WB~{H^P61UvYdPFn zT|$lz=k9~AT;H&3LaW7s$xIF#-)!|C(I2$78#qjA7mW&jx0tF+(IF}BNyJd7UJjDI z>U=2Cb0R@L;|ut0tvqd}rV;{N+}g%PkztPhkU){_^(@=b<^R@hL;!sK^j%lFZSSfk ztw$tiIQ>~(mE8Tdh{xF5{e`JFItt%k^4`T=HK|e`T0>4;=x2OdL{V*rEAJaASz5xp z5)?(5HKxauQ?rUrhcflpYK<{TwQ#mxOV_|WTO`T5av-tcF4I%u#J$3IeiG5rWtpE6v&8E>w zu-;7mC@a4aiZzv!gYP$R?OpBcG)tV=FaV`=@W}wunu@u>?_nJcY~xjT{%YmLO2_n2 zT#&O1LV}$uHIPZ-ctZe z$v9B0v5+F_U4}e{k@h5OtG$m@6LdG>@ffxC^e&u-g6P}*lTOSjS14)P?Tr15e&mMR zyNed8$hH<^Y%9RtX4~0fu)$ajiytfLs}03E_u18Lp3lr`J<;sIK(sHL6M1XaP2V;P zG(v_m9fl5{pUgRU30CM}wrk%IZRPN}aoX;R-=gfGvb&Yl9g>idm}}#Gn7v*{a@IbAx#5&MWy~p?^eG#b^>J O9uO-Eja)_YjQKA>{?~#4 literal 0 HcmV?d00001 diff --git a/BlueprintUICommonControls/Tests/Sources/ReferenceImages/BoxTests/test_cornerStyle_semicircular.png b/BlueprintUICommonControls/Tests/Sources/ReferenceImages/BoxTests/test_cornerStyle_wideCapsule.png similarity index 100% rename from BlueprintUICommonControls/Tests/Sources/ReferenceImages/BoxTests/test_cornerStyle_semicircular.png rename to BlueprintUICommonControls/Tests/Sources/ReferenceImages/BoxTests/test_cornerStyle_wideCapsule.png diff --git a/CHANGELOG.md b/CHANGELOG.md index 060e3f289..a02d7653b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `addFixed(child:)` and `addFlexible(child:)` methods to `StackElement` for adding children with a grow & shrink priority of 0.0 and 1.0 respectively. -- Add `semicircular` case to `Box.CornerStyle` ([#145]). This addition sugars the following pattern +- Add `capsule` case to `Box.CornerStyle` ([#145]). This addition sugars the following pattern ``` GeometryReader { geometry in @@ -24,7 +24,7 @@ GeometryReader { geometry in into ``` -Box(cornerStyle: .semicircular) +Box(cornerStyle: .capsule) ``` ### Removed