Skip to content

Commit

Permalink
Fixes to width and some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
stonehouse committed Mar 22, 2017
1 parent d4c1a1e commit d7ec1d9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
4 changes: 1 addition & 3 deletions T-Minus/CountdownView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

@interface CountdownView : NSView

@property (nonatomic, strong) NSString *description;
@property (nonatomic, strong) NSString *countdownDescription;
@property (nonatomic, strong) NSString *backgroundPath;
@property (weak) IBOutlet NSImageView *backgroundView;

- (void)adjustTextColor;

@end
18 changes: 8 additions & 10 deletions T-Minus/CountdownView.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ @interface CountdownView()
@property (weak) IBOutlet NSTextFieldCell *countdownTitleLabel;
@property (weak) IBOutlet NSVisualEffectView *visualEffectView;
@property (weak) IBOutlet NSLayoutConstraint *widthConstraint;
@property (weak) IBOutlet NSLayoutConstraint *heightConstraint;

@end

Expand All @@ -27,15 +28,19 @@ -(void)awakeFromNib
self.visualEffectView.layer.cornerRadius = 5.0f;
}

- (void)setDescription:(NSString *)description
- (void)setCountdownDescription:(NSString *)countdownDescription
{
self.countdownLabel.stringValue = description;
self.countdownLabel.stringValue = countdownDescription;
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;
if (desiredWidth > self.frame.size.width + defaultPadding) {
self.widthConstraint.constant = self.frame.size.width - defaultPadding;
} else {
self.widthConstraint.constant = desiredWidth;
}
[self setNeedsUpdateConstraints:YES];
}
}
Expand All @@ -48,11 +53,4 @@ - (void)setBackgroundPath:(NSString *)backgroundPath
self.countdownTitleLabel.textColor = [NSColor whiteColor];
}

- (void)adjustTextColor
{
CGRect sectionCountdown = [self convertRect:self.countdownLabel.controlView.frame toView:self.backgroundView];
self.countdownLabel.textColor = [self.backgroundView idealTextColorForSection:sectionCountdown];
self.countdownTitleLabel.textColor = [self.countdownLabel.textColor copy];
}

@end
6 changes: 4 additions & 2 deletions T-Minus/CountdownView.xib
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<imageCell key="cell" scrollable="YES" lineBreakMode="clipping" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" id="ctI-ay-bQB"/>
</imageView>
<visualEffectView appearanceType="vibrantDark" blendingMode="withinWindow" material="appearanceBased" state="followsWindowActiveState" translatesAutoresizingMaskIntoConstraints="NO" id="i9L-1Z-VOl">
<visualEffectView appearanceType="vibrantDark" blendingMode="withinWindow" material="appearanceBased" state="active" translatesAutoresizingMaskIntoConstraints="NO" id="i9L-1Z-VOl">
<rect key="frame" x="20" y="85" width="400" height="100"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="Qgn-xA-33d">
Expand All @@ -37,7 +37,7 @@
</textField>
</subviews>
<constraints>
<constraint firstAttribute="width" constant="400" id="EIU-VK-VpZ"/>
<constraint firstAttribute="width" priority="750" constant="400" id="EIU-VK-VpZ"/>
<constraint firstItem="Qgn-xA-33d" firstAttribute="leading" secondItem="i9L-1Z-VOl" secondAttribute="leading" constant="10" id="MNe-SI-H1A"/>
<constraint firstItem="eDC-9b-xG6" firstAttribute="leading" secondItem="Qgn-xA-33d" secondAttribute="leading" id="XwH-hJ-0Wy"/>
<constraint firstAttribute="height" constant="100" id="ZlA-87-daY"/>
Expand All @@ -52,12 +52,14 @@
<constraint firstAttribute="trailing" secondItem="AuJ-Iz-O21" secondAttribute="trailing" id="NXh-DA-dCf"/>
<constraint firstAttribute="bottom" secondItem="AuJ-Iz-O21" secondAttribute="bottom" id="OHH-aj-Fpf"/>
<constraint firstItem="AuJ-Iz-O21" firstAttribute="top" secondItem="c22-O7-iKe" secondAttribute="top" id="UyQ-WV-qUW"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="i9L-1Z-VOl" secondAttribute="trailing" constant="20" id="mJK-Ep-xZk"/>
<constraint firstItem="AuJ-Iz-O21" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" id="zl7-Zs-Gyz"/>
</constraints>
<connections>
<outlet property="backgroundView" destination="AuJ-Iz-O21" id="lOS-yD-zH0"/>
<outlet property="countdownLabel" destination="hPX-lE-mos" id="MIJ-nK-sTQ"/>
<outlet property="countdownTitleLabel" destination="jp5-zh-A1C" id="0LD-xZ-G9h"/>
<outlet property="heightConstraint" destination="ZlA-87-daY" id="BGW-8B-JLT"/>
<outlet property="visualEffectView" destination="i9L-1Z-VOl" id="FhV-sY-YEJ"/>
<outlet property="widthConstraint" destination="EIU-VK-VpZ" id="LJm-Eo-fHd"/>
</connections>
Expand Down
10 changes: 2 additions & 8 deletions T-Minus/CountdownViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ - (void)viewDidAppear
}
}

- (void)windowDidResize:(NSNotification *)notification
{

}


- (void)dealloc
{
Countdown_destroy(self.ctdn);
Expand All @@ -78,7 +72,7 @@ - (void)updateTimer {

Tminus tm = Countdown_tminus(self.ctdn);

self.countdownView.description = [NSString stringWithUTF8String:tm.description];
self.countdownView.countdownDescription = [NSString stringWithUTF8String:tm.description];

if (tm.difference == 10) {
// With 10 seconds to go, pop to the foreground
Expand Down Expand Up @@ -149,7 +143,7 @@ - (void)cancel:(id)sender

- (void)createCountdown
{
self.countdownView.description = @"";
self.countdownView.countdownDescription = @"";
NSStoryboard *storyboard = [NSStoryboard storyboardWithName:@"Main" bundle:nil];
NSWindowController *vc = [storyboard instantiateControllerWithIdentifier:@"createCountdown"];

Expand Down
4 changes: 2 additions & 2 deletions T-Minus/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2</string>
<string>1.3</string>
<key>CFBundleVersion</key>
<string>3</string>
<string>4</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
Expand Down

0 comments on commit d7ec1d9

Please sign in to comment.