From 144ee3762d5de31fa2e32494500c36ae56d431a8 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Wed, 12 Sep 2012 23:00:21 +0200 Subject: [PATCH] Use NSBox to draw gutter divider MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There’s a few subtle advantages of going with a view, mostly theoretical (about minimizing refresh rectangles) but switching to constrained based layout should provide minor code simplifications, since our ancestor view won’t have to deal with the gutter divider rectangle. --- Frameworks/OakTextView/src/OakDocumentView.h | 2 ++ Frameworks/OakTextView/src/OakDocumentView.mm | 28 ++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Frameworks/OakTextView/src/OakDocumentView.h b/Frameworks/OakTextView/src/OakDocumentView.h index 4239f6f0..72cf87cc 100644 --- a/Frameworks/OakTextView/src/OakDocumentView.h +++ b/Frameworks/OakTextView/src/OakDocumentView.h @@ -16,6 +16,8 @@ PUBLIC @interface OakDocumentView : NSView gutter_styles(); - self.gutterDividerColor = [NSColor tmColorWithCGColor:styles.divider]; gutterView.foregroundColor = [NSColor tmColorWithCGColor:styles.foreground]; gutterView.backgroundColor = [NSColor tmColorWithCGColor:styles.background]; @@ -359,17 +365,16 @@ private: gutterView.selectionIconHoverColor = [NSColor tmColorWithCGColor:styles.selectionIconsHover]; gutterView.selectionIconPressedColor = [NSColor tmColorWithCGColor:styles.selectionIconsPressed]; gutterView.selectionBorderColor = [NSColor tmColorWithCGColor:styles.selectionBorder]; + gutterScrollView.backgroundColor = gutterView.backgroundColor; + gutterDividerView.borderColor = [NSColor tmColorWithCGColor:styles.divider]; - gutterScrollView.backgroundColor = gutterView.backgroundColor; - - [self setNeedsDisplayInRect:[self gutterDividerRect]]; [gutterView setNeedsDisplay:YES]; } } - (BOOL)isOpaque { - return YES; // this is not entirely true as this view only draws the separator between gutter and text view, but we know all the other areas are completely drawn by subviews, so we return ‘YES’ to avoid our parent view (window) having to fill the entire area each time the separator needs to be redrawn + return YES; } - (IBAction)toggleLineNumbers:(id)sender @@ -420,6 +425,7 @@ private: } [gutterScrollView setFrame:NSMakeRect(0, y, gutterWidth - 1, docHeight)]; + [gutterDividerView setFrame:NSMakeRect(gutterWidth - 1, y, 1, docHeight)]; [textScrollView setFrame:NSMakeRect(gutterWidth, y, NSWidth(textScrollView.frame), docHeight)]; y += docHeight; @@ -478,10 +484,6 @@ private: [[NSColor grayColor] set]; NSRectFill(NSIntersectionRect(NSMakeRect(NSMinX(aRect), NSHeight(self.frame) - height, NSWidth(aRect), 1), aRect)); } - - // Draw the border between gutter and text views - [gutterDividerColor set]; - NSRectFill(NSIntersectionRect([self gutterDividerRect], aRect)); } // ======================