From 5c7dd533804812732d2e75606f19522578420990 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Mon, 24 Nov 2014 08:07:41 -0500 Subject: Add new "flat" button style Hides the button border and background; good for placing several shortcut buttons into a table view. --- MASShortcutView.h | 3 ++- MASShortcutView.m | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/MASShortcutView.h b/MASShortcutView.h index d6a4313..d798878 100644 --- a/MASShortcutView.h +++ b/MASShortcutView.h @@ -5,7 +5,8 @@ typedef enum { MASShortcutViewAppearanceDefault = 0, // Height = 19 px MASShortcutViewAppearanceTexturedRect, // Height = 25 px - MASShortcutViewAppearanceRounded // Height = 43 px + MASShortcutViewAppearanceRounded, // Height = 43 px + MASShortcutViewAppearanceFlat } MASShortcutViewAppearance; @interface MASShortcutView : NSView diff --git a/MASShortcutView.m b/MASShortcutView.m index b2d2531..bd18003 100644 --- a/MASShortcutView.m +++ b/MASShortcutView.m @@ -107,6 +107,12 @@ _shortcutCell.bezelStyle = NSRoundedBezelStyle; break; } + case MASShortcutViewAppearanceFlat: { + self.wantsLayer = YES; + _shortcutCell.backgroundColor = [NSColor clearColor]; + _shortcutCell.bordered = NO; + break; + } } } @@ -176,12 +182,16 @@ [_shortcutCell drawWithFrame:CGRectOffset(frame, 0.0, 1.0) inView:self]; break; } + case MASShortcutViewAppearanceFlat: { + [_shortcutCell drawWithFrame:frame inView:self]; + break; + } } } - (void)drawRect:(CGRect)dirtyRect { - if (self.shortcutValue) { + if (self.shortcutValue) { [self drawInRect:self.bounds withTitle:MASShortcutChar(self.recording ? kMASShortcutGlyphEscape : kMASShortcutGlyphDeleteLeft) alignment:NSRightTextAlignment state:NSOffState]; @@ -227,7 +237,8 @@ switch (self.appearance) { case MASShortcutViewAppearanceTexturedRect: hintButtonWidth += 2.0; break; case MASShortcutViewAppearanceRounded: hintButtonWidth += 3.0; break; - default: break; + case MASShortcutViewAppearanceFlat: hintButtonWidth -= 8.0 - (_shortcutCell.font.pointSize - BUTTON_FONT_SIZE); break; + default: break; } CGRectDivide(self.bounds, &hintRect, &shortcutRect, hintButtonWidth, CGRectMaxXEdge); if (shortcutRectRef) *shortcutRectRef = shortcutRect; -- cgit v1.2.3 From 443e2db73d3268b7dbac7bb1e80bf2f716c86fd3 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Mon, 24 Nov 2014 08:15:24 -0500 Subject: Fix indentation on previous commits: tabs to four spaces --- MASShortcutView.h | 2 +- MASShortcutView.m | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/MASShortcutView.h b/MASShortcutView.h index d798878..c8a46bb 100644 --- a/MASShortcutView.h +++ b/MASShortcutView.h @@ -6,7 +6,7 @@ typedef enum { MASShortcutViewAppearanceDefault = 0, // Height = 19 px MASShortcutViewAppearanceTexturedRect, // Height = 25 px MASShortcutViewAppearanceRounded, // Height = 43 px - MASShortcutViewAppearanceFlat + MASShortcutViewAppearanceFlat } MASShortcutViewAppearance; @interface MASShortcutView : NSView diff --git a/MASShortcutView.m b/MASShortcutView.m index bd18003..dd75729 100644 --- a/MASShortcutView.m +++ b/MASShortcutView.m @@ -107,12 +107,12 @@ _shortcutCell.bezelStyle = NSRoundedBezelStyle; break; } - case MASShortcutViewAppearanceFlat: { - self.wantsLayer = YES; - _shortcutCell.backgroundColor = [NSColor clearColor]; - _shortcutCell.bordered = NO; - break; - } + case MASShortcutViewAppearanceFlat: { + self.wantsLayer = YES; + _shortcutCell.backgroundColor = [NSColor clearColor]; + _shortcutCell.bordered = NO; + break; + } } } @@ -182,16 +182,16 @@ [_shortcutCell drawWithFrame:CGRectOffset(frame, 0.0, 1.0) inView:self]; break; } - case MASShortcutViewAppearanceFlat: { - [_shortcutCell drawWithFrame:frame inView:self]; - break; - } + case MASShortcutViewAppearanceFlat: { + [_shortcutCell drawWithFrame:frame inView:self]; + break; + } } } - (void)drawRect:(CGRect)dirtyRect { - if (self.shortcutValue) { + if (self.shortcutValue) { [self drawInRect:self.bounds withTitle:MASShortcutChar(self.recording ? kMASShortcutGlyphEscape : kMASShortcutGlyphDeleteLeft) alignment:NSRightTextAlignment state:NSOffState]; @@ -237,8 +237,8 @@ switch (self.appearance) { case MASShortcutViewAppearanceTexturedRect: hintButtonWidth += 2.0; break; case MASShortcutViewAppearanceRounded: hintButtonWidth += 3.0; break; - case MASShortcutViewAppearanceFlat: hintButtonWidth -= 8.0 - (_shortcutCell.font.pointSize - BUTTON_FONT_SIZE); break; - default: break; + case MASShortcutViewAppearanceFlat: hintButtonWidth -= 8.0 - (_shortcutCell.font.pointSize - BUTTON_FONT_SIZE); break; + default: break; } CGRectDivide(self.bounds, &hintRect, &shortcutRect, hintButtonWidth, CGRectMaxXEdge); if (shortcutRectRef) *shortcutRectRef = shortcutRect; -- cgit v1.2.3