diff --git a/T-Minus/CountdownView.h b/T-Minus/CountdownView.h index 87a980a..e0b8016 100644 --- a/T-Minus/CountdownView.h +++ b/T-Minus/CountdownView.h @@ -10,7 +10,7 @@ @interface CountdownView : NSView -@property (weak) IBOutlet NSTextFieldCell *countdownLabel; +@property (nonatomic, strong) NSString *description; @property (nonatomic, strong) NSString *backgroundPath; @property (weak) IBOutlet NSImageView *backgroundView; diff --git a/T-Minus/CountdownView.m b/T-Minus/CountdownView.m index 9836ad8..e307f64 100644 --- a/T-Minus/CountdownView.m +++ b/T-Minus/CountdownView.m @@ -11,17 +11,41 @@ @interface CountdownView() +@property (weak) IBOutlet NSTextFieldCell *countdownLabel; @property (weak) IBOutlet NSTextFieldCell *countdownTitleLabel; +@property (weak) IBOutlet NSVisualEffectView *visualEffectView; +@property (weak) IBOutlet NSLayoutConstraint *widthConstraint; @end @implementation CountdownView +-(void)awakeFromNib +{ + [super awakeFromNib]; + + self.visualEffectView.layer.cornerRadius = 5.0f; +} + +- (void)setDescription:(NSString *)description +{ + self.countdownLabel.stringValue = description; + CGFloat currentWidth = self.widthConstraint.constant; + CGFloat defaultPadding = 20; + CGFloat desiredWidth = [self.countdownLabel cellSize].width + defaultPadding; + CGFloat diff = currentWidth - desiredWidth; + if (diff < 0 || diff > 40) { + self.widthConstraint.constant = desiredWidth + defaultPadding; + [self setNeedsUpdateConstraints:YES]; + } +} + - (void)setBackgroundPath:(NSString *)backgroundPath { NSURL *bgURL = [NSURL fileURLWithPath:backgroundPath]; self.backgroundView.image = [[NSImage alloc] initWithContentsOfURL:bgURL]; - [self adjustTextColor]; + self.countdownLabel.textColor = [NSColor whiteColor]; + self.countdownTitleLabel.textColor = [NSColor whiteColor]; } - (void)adjustTextColor diff --git a/T-Minus/CountdownView.xib b/T-Minus/CountdownView.xib index 3e5152e..2f3933a 100644 --- a/T-Minus/CountdownView.xib +++ b/T-Minus/CountdownView.xib @@ -1,7 +1,6 @@ - @@ -9,7 +8,7 @@ - + @@ -17,38 +16,50 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - - - - + + diff --git a/T-Minus/CountdownViewController.m b/T-Minus/CountdownViewController.m index 16d83ff..d792aca 100644 --- a/T-Minus/CountdownViewController.m +++ b/T-Minus/CountdownViewController.m @@ -62,7 +62,7 @@ - (void)viewDidAppear - (void)windowDidResize:(NSNotification *)notification { - [self.countdownView adjustTextColor]; + } @@ -78,7 +78,7 @@ - (void)updateTimer { Tminus tm = Countdown_tminus(self.ctdn); - self.countdownView.countdownLabel.stringValue = [NSString stringWithUTF8String:tm.description]; + self.countdownView.description = [NSString stringWithUTF8String:tm.description]; if (tm.difference == 10) { // With 10 seconds to go, pop to the foreground @@ -149,7 +149,7 @@ - (void)cancel:(id)sender - (void)createCountdown { - self.countdownView.countdownLabel.stringValue = @""; + self.countdownView.description = @""; NSStoryboard *storyboard = [NSStoryboard storyboardWithName:@"Main" bundle:nil]; NSWindowController *vc = [storyboard instantiateControllerWithIdentifier:@"createCountdown"];