Fix Status bar message v-alignment and use monospaced font for Time.

CQTexperiment
Dzmitry Neviadomski 2021-01-25 23:17:57 +03:00
parent 5677780a82
commit bebe6cd3e8
5 changed files with 62 additions and 57 deletions

View File

@ -21,12 +21,13 @@
<rect key="contentRect" x="331" y="367" width="847" height="400"/> <rect key="contentRect" x="331" y="367" width="847" height="400"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1055"/> <rect key="screenRect" x="0.0" y="0.0" width="1920" height="1055"/>
<value key="minSize" type="size" width="400" height="200"/> <value key="minSize" type="size" width="400" height="200"/>
<stackView key="contentView" orientation="vertical" alignment="centerX" hasEqualSpacing="YES" detachesHiddenViews="YES" id="2"> <stackView key="contentView" orientation="vertical" alignment="centerX" spacing="4" hasEqualSpacing="YES" detachesHiddenViews="YES" id="2">
<rect key="frame" x="0.0" y="0.0" width="847" height="400"/> <rect key="frame" x="0.0" y="0.0" width="847" height="400"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<edgeInsets key="edgeInsets" left="0.0" right="0.0" top="0.0" bottom="4"/>
<middleViews> <middleViews>
<button toolTip="Click to select currently playing track" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="gev-jg-41I"> <button toolTip="Click to select currently playing track" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="gev-jg-41I">
<rect key="frame" x="337" y="384" width="173" height="16"/> <rect key="frame" x="337" y="384" width="174" height="16"/>
<buttonCell key="cell" type="bevel" title="Now Playing Track title here" bezelStyle="rounded" alignment="center" lineBreakMode="truncatingTail" imageScaling="proportionallyDown" inset="2" id="oXd-7z-UQS"> <buttonCell key="cell" type="bevel" title="Now Playing Track title here" bezelStyle="rounded" alignment="center" lineBreakMode="truncatingTail" imageScaling="proportionallyDown" inset="2" id="oXd-7z-UQS">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
@ -42,17 +43,17 @@
</connections> </connections>
</button> </button>
<splitView fixedFrame="YES" dividerStyle="thin" vertical="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2123"> <splitView fixedFrame="YES" dividerStyle="thin" vertical="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2123">
<rect key="frame" x="24" y="22" width="800" height="354"/> <rect key="frame" x="24" y="22" width="800" height="358"/>
<subviews> <subviews>
<scrollView fixedFrame="YES" borderType="none" autohidesScrollers="YES" horizontalLineScroll="24" horizontalPageScroll="0.0" verticalLineScroll="24" verticalPageScroll="0.0" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" id="206" userLabel="Scroll View - Playlist View"> <scrollView fixedFrame="YES" borderType="none" autohidesScrollers="YES" horizontalLineScroll="24" horizontalPageScroll="0.0" verticalLineScroll="24" verticalPageScroll="0.0" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" id="206" userLabel="Scroll View - Playlist View">
<rect key="frame" x="0.0" y="0.0" width="800" height="354"/> <rect key="frame" x="0.0" y="0.0" width="800" height="358"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="KWC-Ti-8KY"> <clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="KWC-Ti-8KY">
<rect key="frame" x="0.0" y="0.0" width="800" height="354"/> <rect key="frame" x="0.0" y="0.0" width="800" height="358"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<tableView focusRingType="none" verticalHuggingPriority="750" allowsExpansionToolTips="YES" alternatingRowBackgroundColors="YES" autosaveName="Playlist" rowHeight="18" headerView="1517" id="207" customClass="PlaylistView"> <tableView focusRingType="none" verticalHuggingPriority="750" allowsExpansionToolTips="YES" alternatingRowBackgroundColors="YES" autosaveName="Playlist" rowHeight="18" headerView="1517" id="207" customClass="PlaylistView">
<rect key="frame" x="0.0" y="0.0" width="800" height="337"/> <rect key="frame" x="0.0" y="0.0" width="800" height="341"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="3" height="6"/> <size key="intercellSpacing" width="3" height="6"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/> <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
@ -310,7 +311,7 @@
</middleViews> </middleViews>
<endViews> <endViews>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="778"> <textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="778">
<rect key="frame" x="293" y="0.0" width="261" height="14"/> <rect key="frame" x="293" y="4" width="261" height="14"/>
<textFieldCell key="cell" controlSize="small" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" alignment="center" title="Total Duration: 00 hours 00 minutes 00 seconds" bezelStyle="round" id="1473"> <textFieldCell key="cell" controlSize="small" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" alignment="center" title="Total Duration: 00 hours 00 minutes 00 seconds" bezelStyle="round" id="1473">
<font key="font" metaFont="controlContent" size="11"/> <font key="font" metaFont="controlContent" size="11"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@ -631,12 +632,12 @@
</connections> </connections>
</slider> </slider>
</toolbarItem> </toolbarItem>
<toolbarItem implicitItemIdentifier="C0FF70A3-EE67-43F6-9956-95B89425CF0E" label="Current Time" paletteLabel="Current Time" sizingBehavior="auto" id="2274"> <toolbarItem implicitItemIdentifier="C0FF70A3-EE67-43F6-9956-95B89425CF0E" label="Current Time" paletteLabel="Current Time" visibilityPriority="5" sizingBehavior="auto" id="2274">
<nil key="toolTip"/> <nil key="toolTip"/>
<textField key="view" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2291" customClass="TimeField"> <textField key="view" verticalHuggingPriority="750" id="2291" customClass="TimeField">
<rect key="frame" x="14" y="14" width="49" height="19"/> <rect key="frame" x="14" y="14" width="49" height="19"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" controlSize="small" lineBreakMode="clipping" sendsActionOnEndEditing="YES" borderStyle="bezel" alignment="center" title="0:00" bezelStyle="round" id="2292"> <textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" borderStyle="bezel" alignment="center" title="0:00" usesSingleLineMode="YES" bezelStyle="round" id="2292">
<font key="font" metaFont="message" size="11"/> <font key="font" metaFont="message" size="11"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>

View File

@ -11,8 +11,8 @@
@class TimeField; @class TimeField;
@interface PositionSlider : TrackingSlider { @interface PositionSlider : TrackingSlider
IBOutlet TimeField *positionTextField;
} @property (nonatomic) IBOutlet TimeField *positionTextField;
@end @end

View File

@ -13,21 +13,21 @@
- (void)setDoubleValue:(double)value - (void)setDoubleValue:(double)value
{ {
[positionTextField setDoubleValue:value]; self.positionTextField.currentTime = (long)value;
[super setDoubleValue:value]; [super setDoubleValue:value];
} }
- (void)setMaxValue:(double)value - (void)setMaxValue:(double)value
{ {
[positionTextField setMaxDoubleValue:value]; self.positionTextField.duration = (long)value;
[super setMaxValue:value]; [super setMaxValue:value];
} }
- (void)mouseDragged:(NSEvent *)theEvent - (void)mouseDragged:(NSEvent *)theEvent
{ {
[positionTextField setDoubleValue:[self doubleValue]]; self.positionTextField.currentTime = (long)[self doubleValue];
[super mouseDragged:theEvent]; [super mouseDragged:theEvent];
} }

View File

@ -9,14 +9,9 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
@interface TimeField : NSTextField { @interface TimeField : NSTextField
BOOL showTimeRemaining;
double value; @property (nonatomic) NSInteger currentTime;
double maxValue; @property (nonatomic) NSInteger duration;
}
- (void)setMaxDoubleValue:(double)v;
- (void)setDoubleValue:(double)v;
@end @end

View File

@ -8,12 +8,26 @@
#import "TimeField.h" #import "TimeField.h"
static NSString *kTimerModeKey = @"timerShowTimeRemaining";
@implementation TimeField NSString * formatTimer(long minutes, long seconds, unichar prefix) {
return [NSString localizedStringWithFormat:@"%C%lu:%02lu", prefix, minutes, seconds];;
}
@implementation TimeField {
BOOL showTimeRemaining;
NSDictionary *fontAttributes;
}
- (void)awakeFromNib - (void)awakeFromNib
{ {
showTimeRemaining = [[NSUserDefaults standardUserDefaults] boolForKey:@"timerShowTimeRemaining"]; showTimeRemaining = [[NSUserDefaults standardUserDefaults] boolForKey:kTimerModeKey];
if (@available(macOS 10.15, *)) {
fontAttributes =
@{NSFontAttributeName : [NSFont monospacedSystemFontOfSize:13
weight:NSFontWeightMedium]};
[self update];
}
} }
- (void)update - (void)update
@ -21,34 +35,29 @@
NSString *text; NSString *text;
if (showTimeRemaining == NO) if (showTimeRemaining == NO)
{ {
int sec = value; long sec = self.currentTime;
text = [NSString stringWithFormat:NSLocalizedString(@"TimeElapsed", @""), sec/60, sec%60]; text = formatTimer(sec / 60, sec % 60, 0x2007); // Digit-width space
} }
else else
{ {
int sec = maxValue - value; long sec = MAX(0, self.duration - self.currentTime);
if (sec < 0) text = formatTimer(sec / 60, sec % 60, 0x2012); // Hyphen
sec = 0;
text = [NSString stringWithFormat:NSLocalizedString(@"TimeRemaining", @""), sec/60, sec%60];
} }
[self setStringValue:text]; NSAttributedString *string = [[NSAttributedString alloc] initWithString:text
attributes:fontAttributes];
[self setAttributedStringValue: string];
} }
- (void)mouseDown:(NSEvent *)theEvent - (void)mouseDown:(NSEvent *)theEvent
{ {
showTimeRemaining = !showTimeRemaining; showTimeRemaining = !showTimeRemaining;
[[NSUserDefaults standardUserDefaults] setBool:showTimeRemaining forKey:@"timerShowTimeRemaining"]; [[NSUserDefaults standardUserDefaults] setBool:showTimeRemaining forKey:kTimerModeKey];
[self update]; [self update];
} }
- (void)setMaxDoubleValue:(double)v - (void)setCurrentTime:(NSInteger)currentTime
{ {
maxValue = v; _currentTime = currentTime;
}
- (void)setDoubleValue:(double)v
{
value = v;
[self update]; [self update];
} }