OSDN Git Service

リストの画像がcollection viewからはみ出さないようにした
authormasakih <masakih@users.sourceforge.jp>
Fri, 14 Oct 2016 15:09:39 +0000 (00:09 +0900)
committermasakih <masakih@users.sourceforge.jp>
Fri, 14 Oct 2016 15:09:39 +0000 (00:09 +0900)
KCD/HMScreenshotListViewController.m
KCD/HMScreenshotListViewController.xib

index 1c16297..039d939 100644 (file)
@@ -61,6 +61,7 @@
 @property (weak, nonatomic) IBOutlet NSView *editorView;
 
 @property (nonatomic) CGFloat zoom;
+@property CGFloat maxZoom;
 
 
 - (void)reloadData;
                           forKeyPath:@"selectionIndexPaths"
                              options:0
                              context:nil];
+    self.collectionView.postsFrameChangedNotifications = YES;
+    [[NSNotificationCenter defaultCenter] addObserver:self
+                                             selector:@selector(viewFrameDidChange:)
+                                                 name:NSViewFrameDidChangeNotification
+                                               object:self.collectionView];
+    [self viewFrameDidChange:nil];
        
        [self performSelector:@selector(reloadData:)
                           withObject:nil
                           afterDelay:0.0];
 }
 
+const CGFloat def = 800;
+const CGFloat leftMergin = 8 + 1;
+const CGFloat rightMergin = 8 + 1;
+
+CGFloat maxZoom(CGFloat width) {
+    width -= leftMergin;
+    width -= rightMergin;
+    
+    if(width < 240) {
+        return width / def / 0.6;
+    }
+    if(width > 800) {
+        return 1;
+    }
+    return pow((width / def - 0.2) / 0.8, 1.0 / 3.0);
+}
+CGFloat realFromZoom(CGFloat zoom) {
+    CGFloat f = 0.0;
+    
+    if(zoom < 0.5) {
+        f = def * zoom * 0.6;
+    } else {
+        f = def * (0.8 * zoom * zoom * zoom + 0.2);
+    }
+    
+    return f;
+}
 - (void)setZoom:(CGFloat)zoom
 {
     _zoom = zoom;
 }
 - (NSSize)collectionView:(NSCollectionView *)collectionView layout:(NSCollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
 {
-    const NSInteger def = 800;
-    return NSMakeSize(def * self.zoom, def * self.zoom);
+    CGFloat f = realFromZoom(self.zoom);
+    return NSMakeSize(f, f);
+}
+- (void)viewFrameDidChange:(id)no
+{
+    self.maxZoom = maxZoom(self.collectionView.frame.size.width);;
+    
+    CGFloat f = self.maxZoom;
+    if(_zoom > f) self.zoom = f;
 }
 
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
index eecc096..0e08c45 100644 (file)
                     <constraints>
                         <constraint firstAttribute="height" constant="17" id="hwt-Fn-wJs"/>
                     </constraints>
-                    <sliderCell key="cell" continuous="YES" refusesFirstResponder="YES" state="on" alignment="left" minValue="0.20000000000000001" maxValue="1" doubleValue="1" tickMarkPosition="above" sliderType="linear" id="hO7-4z-A2O"/>
+                    <sliderCell key="cell" continuous="YES" refusesFirstResponder="YES" state="on" alignment="left" minValue="0.20000000000000001" maxValue="0.90000000000000002" doubleValue="0.90000000000000002" tickMarkPosition="above" sliderType="linear" id="hO7-4z-A2O"/>
                     <connections>
-                        <binding destination="-2" name="value" keyPath="zoom" id="kWI-Wj-qk7"/>
+                        <binding destination="-2" name="maxValue" keyPath="maxZoom" id="vam-gz-oQq"/>
+                        <binding destination="-2" name="value" keyPath="zoom" previousBinding="vam-gz-oQq" id="2mY-1p-K3E"/>
                     </connections>
                 </slider>
                 <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="vkb-uY-8tN">