From 8f3e99bc79a93a138fc9e1907d576d6ceba9d7d3 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Wed, 13 Feb 2013 10:51:07 +0100 Subject: [PATCH] Gutter height now accounts for horizontal scrollbar Previously the gutter and the text view were set to have the same height (via constraints). Though when the horizontal scrollbar is visible then the gutter should technically be made a little taller to account for the extra bottom margin. Not adding this space was causing problems. Fixes #773. --- Frameworks/OakTextView/src/GutterView.mm | 25 +++++++++++++------ Frameworks/OakTextView/src/OakDocumentView.mm | 1 - 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Frameworks/OakTextView/src/GutterView.mm b/Frameworks/OakTextView/src/GutterView.mm index 111d991b..acaac1a0 100644 --- a/Frameworks/OakTextView/src/GutterView.mm +++ b/Frameworks/OakTextView/src/GutterView.mm @@ -28,6 +28,7 @@ struct data_source_t }; @interface GutterView () +@property (nonatomic) NSSize size; - (CGFloat)widthForColumnWithIdentifier:(std::string const&)identifier; - (data_source_t*)columnWithIdentifier:(std::string const&)identifier; @@ -248,9 +249,16 @@ struct data_source_t - (void)boundsDidChange:(NSNotification*)aNotification { + [self updateSize]; [self.enclosingScrollView.contentView scrollToPoint:NSMakePoint(0, NSMinY(_partnerView.enclosingScrollView.contentView.bounds))]; - if([self updateWidth] != NSWidth(self.frame)) - [self invalidateIntrinsicContentSize]; +} + +- (void)setSize:(NSSize)newSize +{ + if(NSEqualSizes(_size, newSize)) + return; + _size = newSize; + [self invalidateIntrinsicContentSize]; } static CTLineRef CreateCTLineFromText (std::string const& text, NSFont* font, NSColor* color = nil) @@ -384,7 +392,7 @@ static void DrawText (std::string const& text, CGRect const& rect, CGFloat basel } } -- (CGFloat)updateWidth +- (void)updateSize { static const CGFloat columnPadding = 1; @@ -404,20 +412,21 @@ static void DrawText (std::string const& text, CGRect const& rect, CGFloat basel } } - return totalWidth; + NSPoint origin = NSMakePoint(0, NSMinY(_partnerView.enclosingScrollView.contentView.bounds)); + CGFloat height = std::max(NSHeight(_partnerView.frame), origin.y + NSHeight([self visibleRect])); + [self setSize:NSMakeSize(totalWidth, height)]; } - (NSSize)intrinsicContentSize { - return NSMakeSize([self updateWidth], NSViewNoInstrinsicMetric); + return self.size; } - (void)reloadData:(id)sender { D(DBF_GutterView, bug("\n");); + [self updateSize]; [self setNeedsDisplay:YES]; - if([self updateWidth] != NSWidth(self.frame)) - [self invalidateIntrinsicContentSize]; } - (NSRect)columnRectForPoint:(NSPoint)aPoint @@ -496,7 +505,7 @@ static void DrawText (std::string const& text, CGRect const& rect, CGFloat basel if(visible) [hiddenColumns removeObject:columnIdentifier]; else [hiddenColumns addObject:columnIdentifier]; - [self invalidateIntrinsicContentSize]; + [self updateSize]; } // ================== diff --git a/Frameworks/OakTextView/src/OakDocumentView.mm b/Frameworks/OakTextView/src/OakDocumentView.mm index 1bb055f6..b0833cd7 100644 --- a/Frameworks/OakTextView/src/OakDocumentView.mm +++ b/Frameworks/OakTextView/src/OakDocumentView.mm @@ -148,7 +148,6 @@ private: [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[gutterScrollView(==gutterView)][gutterDividerView(==1)][textScrollView(>=100)]|" options:NSLayoutFormatAlignAllTop|NSLayoutFormatAlignAllBottom metrics:nil views:views]]; [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[statusBar]|" options:0 metrics:nil views:views]]; [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[statusDividerView][statusBar]|" options:NSLayoutFormatAlignAllLeft|NSLayoutFormatAlignAllRight metrics:nil views:views]]; - [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[gutterView(==textView)]" options:NSLayoutFormatAlignAllTop metrics:nil views:NSDictionaryOfVariableBindings(gutterView, textView)]]; NSMutableArray* stackedViews = [NSMutableArray array]; [stackedViews addObjectsFromArray:topAuxiliaryViews];