GitHub PullRequestReviewCommentEvent at 2014-03-22 17:09:18
Repository: Switch
Actor: robrix
Payload: {"comment":{"url":"https://api.github.com/repos/numist/Switch/pulls/comments/10863092","id":10863092,"diff_hunk":"@@ -98,6 +104,147 @@ - (void)mouseDown:(NSEvent *)theEvent;\n     return;\n }\n \n+#pragma mark NSView\n+\n++ (BOOL)requiresConstraintBasedLayout;\n+{\n+    return YES;\n+}\n+\n+- (void)viewWillMoveToSuperview:(NSView *)newSuperview;\n+{\n+    if (!self.hud) {\n+        _hud = [[SWHUDView alloc] initWithFrame:NSZeroRect];\n+        [self addSubview:self.hud];\n+        \n+        self.hud.translatesAutoresizingMaskIntoConstraints = NO;\n+    }\n+}\n+\n+- (void)updateConstraints;\n+{\n+    if (!Check(!self.constraints.count)) {\n+        [self removeConstraints:self.constraints];\n+    }\n+\n+    [super updateConstraints];\n+    if (self.currentConstraints) {\n+        return;\n+    }\n+\n+    NSDictionary *views = @{\n+        @\"hud\" : self.hud,\n+        @\"collection\" : self,\n+    };\n+\n+    NSDictionary *metrics = @{\n+        @\"hudPadding\" : @(kNNScreenToWindowInset),\n+        @\"cellPadding\" : @(kNNWindowToThumbInset),\n+        @\"maxThumbSize\" : @(self.maxCellSize),\n+        @\"emptyHUDSize\" : @(self.maxCellSize + (kNNWindowToThumbInset * 2.0)),\n+        @\"windowWidth\" : @(self.frame.size.width),\n+        @\"windowHeight\" : @(self.frame.size.height),\n+    };\n+\n+    // Maintain the size of the frame.\n+    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@\"H:[collection(windowWidth)]\" options:NSLayoutFormatAlignAllCenterY metrics:metrics views:views]];\n+    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@\"V:[collection(windowHeight)]\" options:NSLayoutFormatAlignAllCenterY metrics:metrics views:views]];\n+\n+    // Center the HUD inside its container view.\n+    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.hud attribute:NSLayoutAttributeCenterX\n+                                                     relatedBy:NSLayoutRelationEqual\n+                                                        toItem:self attribute:NSLayoutAttributeCenterX\n+                                                    multiplier:1.f constant:0.f]];\n+    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.hud attribute:NSLayoutAttributeCenterY\n+                                                     relatedBy:NSLayoutRelationEqual\n+                                                        toItem:self attribute:NSLayoutAttributeCenterY\n+                                                    multiplier:1.f constant:0.f]];\n+\n+    // Ensure that the hud always has a minimum padding within its container view.\n+    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@\"H:|-(>=hudPadding)-[hud]-(>=hudPadding)-|\" options:NSLayoutFormatAlignAllCenterY metrics:metrics views:views]];\n+    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@\"V:|-(>=hudPadding)-[hud]-(>=hudPadding)-|\" options:NSLayoutFormatAlignAllCenterY metrics:metrics views:views]];\n+\n+    if (self.numberOfCells == 0) {\n+        // Empty HUD is square.\n+        [self addConstraint:[NSLayoutConstraint constraintWithItem:self.hud attribute:NSLayoutAttributeHeight\n+                                                         relatedBy:NSLayoutRelationEqual\n+                                                            toItem:self.hud attribute:NSLayoutAttributeWidth\n+                                                        multiplier:1.f constant:0.f]];\n+\n+        // Empty HUD has the size of the HUD as if it contained one item.\n+        [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@\"[hud(emptyHUDSize)]\" options:NSLayoutFormatAlignAllCenterY metrics:metrics views:views]];\n+    }\n+\n+    for (NSUInteger i = 0; i < self.numberOfCells; i++) {\n+        NSView *prevCell = i != 0 ? self.cells[i - 1] : nil;\n+        NSView *cell = self.cells[i];\n+        NSView *nextCell = i < (self.numberOfCells - 1) ? self.cells[i + 1] : nil;\n+\n+        NSDictionary *cellViews = @{\n+            @\"prevCell\" : prevCell ?: [NSNull null],\n+            @\"cell\": cell,\n+            @\"nextCell\" : nextCell ?: [NSNull null],\n+            @\"hud\" : self.hud,\n+        };\n+\n+        if (!prevCell) {\n+            // First cell in the collection establishes the size that all of the others follow. Max size, with lower priority so it will be compromised if layout pressure exists due to too many cells.\n+            [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@\"[cell(maxThumbSize@777)]\" options:NSLayoutFormatAlignAllCenterY metrics:metrics views:cellViews]];","path":"Switch/SWHUDCollectionView.m","position":148,"original_position":148,"commit_id":"a03de67320b760fd66e518089a25ccbfd8eba14c","original_commit_id":"a03de67320b760fd66e518089a25ccbfd8eba14c","user":{"login":"robrix","id":59671,"avatar_url":"https://avatars.githubusercontent.com/u/59671?","gravatar_id":"bd4d228aa642d45962eaaef7a383f012","url":"https://api.github.com/users/robrix","html_url":"https://github.com/robrix","followers_url":"https://api.github.com/users/robrix/followers","following_url":"https://api.github.com/users/robrix/following{/other_user}","gists_url":"https://api.github.com/users/robrix/gists{/gist_id}","starred_url":"https://api.github.com/users/robrix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robrix/subscriptions","organizations_url":"https://api.github.com/users/robrix/orgs","repos_url":"https://api.github.com/users/robrix/repos","events_url":"https://api.github.com/users/robrix/events{/privacy}","received_events_url":"https://api.github.com/users/robrix/received_events","type":"User","site_admin":true},"body":"`maxThumbSize` doesn’t mean “maximum thumb size”?\r\n\r\nIn general, try to stick to the documented constants. cf `NSLayoutPriority`.","created_at":"2014-03-22T17:09:18Z","updated_at":"2014-03-22T17:09:18Z","html_url":"https://github.com/numist/Switch/pull/78#discussion_r10863092","pull_request_url":"https://api.github.com/repos/numist/Switch/pulls/78","_links":{"self":{"href":"https://api.github.com/repos/numist/Switch/pulls/comments/10863092"},"html":{"href":"https://github.com/numist/Switch/pull/78#discussion_r10863092"},"pull_request":{"href":"https://api.github.com/repos/numist/Switch/pulls/78"}}}}