Skip to content

Commit 179daa8

Browse files
committed
View: stylistic changes (NFC)
- `#if` conditions should be 0-column aligned and do not impact the actual code being conditioned. - Reflow some comments to better bin pack. - Remove some bleeding whitespace. - Re-indent some code for better 80-column fitting.
1 parent d25cd2e commit 179daa8

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

Sources/SwiftWin32/Views and Controls/View.swift

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ private func ScaleClient(rect: inout Rect, for dpi: UINT, _ style: WindowStyle)
7373
}
7474

7575
private func WindowBasedTransform(for view: View?) -> AffineTransform {
76-
guard var view = view else { return AffineTransform.identity }
76+
guard var view = view else { return .identity }
77+
7778
var transform = AffineTransform.identity
7879
while let superview = view.superview {
7980
// Create a single transform that places this view in the coordinate
@@ -371,9 +372,9 @@ public class View: Responder {
371372
/// own coordinate system.
372373
public var bounds: Rect {
373374
didSet {
374-
#if !ENABLE_TESTING
375-
fatalError("\(#function) not yet implemented")
376-
#endif
375+
#if !ENABLE_TESTING
376+
fatalError("\(#function) not yet implemented")
377+
#endif
377378
}
378379
}
379380

@@ -389,9 +390,9 @@ public class View: Responder {
389390
/// bounds.
390391
public var transform: AffineTransform = .identity {
391392
didSet {
392-
#if !ENABLE_TESTING
393-
fatalError("\(#function) not yet implemented")
394-
#endif
393+
#if !ENABLE_TESTING
394+
fatalError("\(#function) not yet implemented")
395+
#endif
395396
}
396397
}
397398

@@ -800,8 +801,8 @@ public class View: Responder {
800801
// center offset and transform.
801802
if let superview = self.superview, superview == view {
802803
// `p - self.bounds.center` undos any translation done by the bounds of
803-
// `self`. Apply the current transform to the shifted point, and
804-
// then return the point relative to `self.center`.
804+
// `self`. Apply the current transform to the shifted point, and then
805+
// return the point relative to `self.center`.
805806

806807
// +--- view ---+
807808
// | +- self -+ |
@@ -811,15 +812,15 @@ public class View: Responder {
811812

812813
// `bounds` is in the coordinate space of self and `center` is in the
813814
// coordinate space of the superview. In this case, the superview is
814-
// `view`, which is the destination coordinate space. We simply map
815-
// the transformed point p from the coordinate space of `self` into
816-
// the destination coordinate space of `view` using `self.center`.
815+
// `view`, which is the destination coordinate space. We simply map the
816+
// transformed point p from the coordinate space of `self` into the
817+
// destination coordinate space of `view` using `self.center`.
817818
return (point - self.bounds.center).applying(self.transform)
818819
+ self.center
819820
} else if let superview = view.superview, superview == self {
820-
// `p - view.center` shifts the point relative to the center of `view`
821-
// as seen by `self`. Invert any transformations performed by `view`
822-
// on the point, and then return the point relative to the center of
821+
// `p - view.center` shifts the point relative to the center of `view`
822+
// as seen by `self`. Invert any transformations performed by `view` on
823+
// the point, and then return the point relative to the center of
823824
// `view.bounds.`
824825

825826
// +--- self ---+
@@ -830,9 +831,9 @@ public class View: Responder {
830831

831832
// `center` is in the coordinate space of the superview. Because `self`
832833
// is the superview of `view`, `view.center` is in the coordinate space
833-
// of `self`. We locate `point` in the coordinate space of `self`,
834-
// undo any local transformation, and then relocate it in the
835-
// coordinate space of the destination view.
834+
// of `self`. We locate `point` in the coordinate space of `self`, undo
835+
// any local transformation, and then relocate it in the coordinate
836+
// space of the destination view.
836837
return (point - view.center).applying(view.transform.inverted())
837838
+ view.bounds.center
838839
}
@@ -845,7 +846,9 @@ public class View: Responder {
845846
/// Converts a point from the coordinate system of a given view to that of the
846847
/// receiver.
847848
public func convert(_ point: Point, from view: View?) -> Point {
848-
return view?.convert(point, to: self) ?? self.window?.convert(point, to: self) ?? point
849+
return view?.convert(point, to: self)
850+
?? self.window?.convert(point, to: self)
851+
?? point
849852
}
850853

851854
/// Converts a rectangle from the receiver’s coordinate system to that of
@@ -863,8 +866,8 @@ public class View: Responder {
863866
if let superview = self.superview, superview == view {
864867
// `r.offsetBy(dx: self.bounds.center.x, dy: self.bounds.center.y)`
865868
// undos any translation done by the bounds property of `self`. Apply
866-
// the current transform to the rect, and then return the rect
867-
// relative to the center of `self`.
869+
// the current transform to the rect, and then return the rect relative
870+
// to the center of `self`.
868871

869872
// +--- view ---+
870873
// | +- self -+ |
@@ -874,18 +877,18 @@ public class View: Responder {
874877

875878
// `bounds` is in the coordinate space of self and `center` is in the
876879
// coordinate space of the superview. In this case, the superview is
877-
// `view`, which is the destination coordinate space. We simply map
878-
// the transformed rect r from the coordinate space of `self` into
879-
// the destination coordinate space of `view` using `self.center`.
880+
// `view`, which is the destination coordinate space. We simply map the
881+
// transformed rect r from the coordinate space of `self` into the
882+
// destination coordinate space of `view` using `self.center`.
880883
return rect.offsetBy(dx: -self.bounds.center.x,
881884
dy: -self.bounds.center.y)
882885
.applying(self.transform)
883886
.offsetBy(dx: self.center.x, dy: self.center.y)
884887
} else if let superview = view.superview, superview == self {
885888
// `r.offsetBy(dx: -view.center, dy: -view.center.y)` shifts the point
886889
// relative to the center of `view` as seen by `self`. Invert any
887-
// transformations performed by `view` on the rect, and then return
888-
// the rect relative to the bounds of `view`.
890+
// transformations performed by `view` on the rect, and then return the
891+
// rect relative to the bounds of `view`.
889892

890893
// +--- self ---+
891894
// | +- view -+ |
@@ -895,9 +898,9 @@ public class View: Responder {
895898

896899
// `center` is in the coordinate space of the superview. Because `self`
897900
// is the superview of `view`, `view.center` is in the coordinate space
898-
// of `self`. We locate `rect` in the coordinate space of `self`,
899-
// undo any local transformation, and then relocate it in the
900-
// coordinate space of the destination view.
901+
// of `self`. We locate `rect` in the coordinate space of `self`, undo
902+
// any local transformation, and then relocate it in the coordinate
903+
// space of the destination view.
901904
return rect.offsetBy(dx: -view.center.x, dy: -view.center.y)
902905
.applying(view.transform.inverted())
903906
.offsetBy(dx: view.bounds.center.x, dy: view.bounds.center.y)
@@ -911,7 +914,9 @@ public class View: Responder {
911914
/// Converts a rectangle from the coordinate system of another view to that of
912915
/// the receiver.
913916
public func convert(_ rect: Rect, from view: View?) -> Rect {
914-
return view?.convert(rect, to: self) ?? self.window?.convert(rect, to: self) ?? rect
917+
return view?.convert(rect, to: self)
918+
?? self.window?.convert(rect, to: self)
919+
?? rect
915920
}
916921

917922
// MARK - Responder Chain

0 commit comments

Comments
 (0)