Skip to content

Commit

Permalink
Dynamically load font weights
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamik423 committed Feb 14, 2022
1 parent a84250c commit e2082f7
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 124 deletions.
4 changes: 2 additions & 2 deletions Padbury Clock Revived.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
"@loader_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.1.1;
MARKETING_VERSION = 1.1.2;
PRODUCT_BUNDLE_IDENTIFIER = "com.hans.Padbury-Clock-Revived";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -312,7 +312,7 @@
"@loader_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.1.1;
MARKETING_VERSION = 1.1.2;
PRODUCT_BUNDLE_IDENTIFIER = "com.hans.Padbury-Clock-Revived";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion Padbury Clock Revived/ClockView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ final class ClockView: ScreenSaverView {
// of a better system please make a pull request or write me an email!
// >>> [email protected] <<<
let fontSizeScaleFactor : CGFloat
switch preferences.font {
switch preferences.fontFamily {
case .sanFrancisco, .neueHelvetica:
fontSizeScaleFactor = 0.20
case .sanFranciscoMono:
Expand Down
31 changes: 22 additions & 9 deletions Padbury Clock Revived/ConfigureSheet.xib
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<outlet property="fontWeightSelector" destination="ZPr-3s-mEV" id="Lvz-Is-N9l"/>
<outlet property="mainScreenCheckbox" destination="1UD-4O-M08" id="QDq-cb-heL"/>
<outlet property="nightTimeModeCheckbox" destination="Amm-Fe-f9G" id="Vqv-0P-PuV"/>
<outlet property="plainFontsOnlyCheckbox" destination="zke-NP-hp0" id="R47-IB-AwG"/>
<outlet property="showSecondsCheckbox" destination="ZBS-KB-BcL" id="SKH-Ql-p3d"/>
<outlet property="showTimeSeparatorsCheckbox" destination="Ck4-Uf-5fZ" id="ajJ-vn-UIw"/>
<outlet property="twentyfourHoursCheckbox" destination="vcR-gm-DgE" id="3c6-40-Jtw"/>
Expand All @@ -33,7 +34,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<gridView xPlacement="leading" yPlacement="fill" rowAlignment="firstBaseline" rowSpacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="gJC-Fu-Ran">
<rect key="frame" x="16" y="61" width="430" height="283"/>
<rect key="frame" x="16" y="37" width="430" height="307"/>
<rows>
<gridRow yPlacement="top" rowAlignment="firstBaseline" id="qR4-PX-gJf"/>
<gridRow yPlacement="top" rowAlignment="firstBaseline" id="hNR-Sn-yK5"/>
Expand All @@ -48,7 +49,7 @@
<gridCells>
<gridCell row="qR4-PX-gJf" column="zi3-Ws-PdH" id="0fO-xp-vHq">
<textField key="contentView" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="nvf-RD-QbQ">
<rect key="frame" x="57" y="267" width="50" height="16"/>
<rect key="frame" x="57" y="291" width="50" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Theme:" id="LXO-Ih-MrQ">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -58,7 +59,7 @@
</gridCell>
<gridCell row="qR4-PX-gJf" column="Ci0-4x-MqC" id="Wxv-Fj-hWb">
<stackView key="contentView" distribution="fill" orientation="vertical" alignment="leading" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="sea-gl-kUy">
<rect key="frame" x="111" y="222" width="319" height="61"/>
<rect key="frame" x="111" y="246" width="319" height="61"/>
<subviews>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="S00-ph-A7z">
<rect key="frame" x="-2" y="44" width="100" height="18"/>
Expand Down Expand Up @@ -103,7 +104,7 @@
</gridCell>
<gridCell row="hNR-Sn-yK5" column="zi3-Ws-PdH" id="rFd-tF-pe7">
<textField key="contentView" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Eiq-ey-ljG">
<rect key="frame" x="56" y="190" width="51" height="16"/>
<rect key="frame" x="56" y="214" width="51" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Format:" id="x67-8N-GDg">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -113,7 +114,7 @@
</gridCell>
<gridCell row="hNR-Sn-yK5" column="Ci0-4x-MqC" id="9ob-ff-aVI">
<stackView key="contentView" distribution="fill" orientation="vertical" alignment="leading" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="gY9-7r-qzT">
<rect key="frame" x="111" y="142" width="319" height="64"/>
<rect key="frame" x="111" y="166" width="319" height="64"/>
<subviews>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="vcR-gm-DgE">
<rect key="frame" x="-2" y="47" width="83" height="18"/>
Expand Down Expand Up @@ -160,7 +161,7 @@
</gridCell>
<gridCell row="IXm-94-IO3" column="zi3-Ws-PdH" id="QwM-IL-kLx">
<textField key="contentView" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="GmH-OM-r8Z">
<rect key="frame" x="72" y="109" width="35" height="16"/>
<rect key="frame" x="72" y="133" width="35" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Font:" id="WxL-HA-itY">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -170,10 +171,10 @@
</gridCell>
<gridCell row="IXm-94-IO3" column="Ci0-4x-MqC" id="oBE-24-ISA">
<stackView key="contentView" distribution="fill" orientation="vertical" alignment="leading" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5vM-mO-oEe">
<rect key="frame" x="111" y="78" width="319" height="48"/>
<rect key="frame" x="111" y="78" width="319" height="72"/>
<subviews>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="zfh-nJ-hc4">
<rect key="frame" x="-3" y="24" width="326" height="25"/>
<rect key="frame" x="-3" y="48" width="326" height="25"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="vhr-wY-GWe">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
Expand All @@ -184,7 +185,7 @@
</connections>
</popUpButton>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ZPr-3s-mEV">
<rect key="frame" x="-3" y="-4" width="326" height="25"/>
<rect key="frame" x="-3" y="20" width="326" height="25"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="pCY-fT-R2N">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
Expand All @@ -194,6 +195,16 @@
<action selector="toggledCheckbox:" target="-2" id="1Fc-dD-LOb"/>
</connections>
</popUpButton>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="zke-NP-hp0">
<rect key="frame" x="-2" y="-1" width="262" height="18"/>
<buttonCell key="cell" type="check" title="Only Show Regular Width Roman Fonts" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="jzz-84-awZ">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="toggledCheckbox:" target="-2" id="8at-mN-oNc"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="ZPr-3s-mEV" firstAttribute="leading" secondItem="5vM-mO-oEe" secondAttribute="leading" id="9Gy-LV-4u0"/>
Expand All @@ -204,10 +215,12 @@
<visibilityPriorities>
<integer value="1000"/>
<integer value="1000"/>
<integer value="1000"/>
</visibilityPriorities>
<customSpacing>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
</gridCell>
Expand Down
25 changes: 18 additions & 7 deletions Padbury Clock Revived/ConfigureSheetController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ConfigureSheetController: NSObject {
@IBOutlet var showTimeSeparatorsCheckbox: NSButton!
@IBOutlet var fontSelector: NSPopUpButton!
@IBOutlet var fontWeightSelector: NSPopUpButton!
@IBOutlet var plainFontsOnlyCheckbox: NSButton!
@IBOutlet var mainScreenCheckbox: NSButton!

override init() {
Expand Down Expand Up @@ -51,23 +52,32 @@ class ConfigureSheetController: NSObject {
twentyfourHoursCheckbox.state = preferences.useAmPm ? .off : .on
showSecondsCheckbox.state = preferences.showSeconds ? .on : .off
showTimeSeparatorsCheckbox.state = preferences.showTimeSeparators ? .on : .off
fontSelector.selectItem(withTitle: preferences.font.name)
fontSelector.selectItem(withTitle: preferences.fontFamily.name)
mainScreenCheckbox.state = preferences.mainScreenOnly ? .on : .off
plainFontsOnlyCheckbox.state = preferences.plainFontsOnly ? .on : .off

// Remove all options from the font selector and add the ones corresponding to the fonts
fontSelector.removeAllItems()
fontSelector.addItems(withTitles: SupportedFont.allCases.map { $0.name })
fontSelector.selectItem(withTitle: preferences.font.name)
fontSelector.selectItem(withTitle: preferences.fontFamily.name)
// Apply font style
for (index, font) in SupportedFont.allCases.enumerated() {
fontSelector.item(at: index)?.attributedTitle = NSAttributedString(string: font.name, attributes: [.font: NSFont(name: font.fontFamilyName, size: NSFont.systemFontSize) ?? NSFont.menuFont(ofSize: NSFont.systemFontSize)])
}

// Remove all the options from the font weight selector
// and add the ones corresponding to the current font
fontWeightSelector.removeAllItems()
fontWeightSelector.addItems(withTitles: preferences.font.availableWeights.map({ $0.name }))
fontWeightSelector.addItems(withTitles: preferences.fontFamily.availableWeights)
// Select the correct item
// If the weight is not available for this font select the first option
fontWeightSelector.selectItem(at: preferences.font.availableWeights.firstIndex(where: { $0.name == preferences.fontWeight.name }) ?? 0 )
fontWeightSelector.selectItem(at: preferences.fontFamily.availableWeights.firstIndex(of: preferences.styleName) ?? 0)
// Preview font
for (index, typeName) in preferences.fontFamily.availableWeights.enumerated() {
fontWeightSelector.item(at: index)?.attributedTitle = NSAttributedString(string: typeName, attributes: [.font: NSFont(name: preferences.fontFamily.postscriptName(for: typeName) ?? "", size: NSFont.systemFontSize) ?? NSFont.menuFont(ofSize: NSFont.systemFontSize)])
}
// Store said option back to the settings in case it changed
preferences.fontWeight = NSFont.Weight.from(name: fontWeightSelector.selectedItem?.title ?? "")
preferences.styleName = fontWeightSelector.selectedItem?.title ?? ""

// Trigger update of the preview window
ClockView.shared?.setup(force: true)
Expand All @@ -84,9 +94,10 @@ class ConfigureSheetController: NSObject {
preferences.useAmPm = twentyfourHoursCheckbox.state == .off
preferences.showSeconds = showSecondsCheckbox.state == .on
preferences.showTimeSeparators = showTimeSeparatorsCheckbox.state == .on
preferences.font = SupportedFont.named(fontSelector.selectedItem?.title ?? "")
preferences.fontWeight = NSFont.Weight.from(name: fontWeightSelector.selectedItem?.title ?? "")
preferences.fontFamily = SupportedFont.named(fontSelector.selectedItem?.title ?? "")
preferences.styleName = fontWeightSelector.selectedItem?.title ?? ""
preferences.mainScreenOnly = mainScreenCheckbox.state == .on
preferences.plainFontsOnly = plainFontsOnlyCheckbox.state == .on

// Update the options. Font weight might have changed.
self.setup()
Expand Down
Loading

0 comments on commit e2082f7

Please sign in to comment.