Skip to content

Commit

Permalink
Disable sidebar top edge inset for fullscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
ngquerol committed Aug 24, 2016
1 parent 3d8af9d commit 3edfc48
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 5 deletions.
50 changes: 50 additions & 0 deletions Diurna/CategoriesViewController.swift
Expand Up @@ -11,20 +11,64 @@ import Cocoa
class CategoriesViewController: NSViewController {

// MARK: Outlets
@IBOutlet var categoriesScrollView: NSScrollView! {
didSet {
categoriesScrollView.automaticallyAdjustsContentInsets = false
categoriesScrollView.contentInsets.top = topEdgeInset
}
}
@IBOutlet weak var categoriesTableView: NSTableView!

// MARK: Properties
private let topEdgeInset: CGFloat = 29.0

// MARK: View lifecycle
override func viewWillAppear() {
super.viewWillAppear()

NotificationCenter.default.addObserver(
self,
selector: .didEnterFullScreen,
name: .enterFullScreenNotification,
object: nil
)

NotificationCenter.default.addObserver(
self,
selector: .didExitFullScreen,
name: .exitFullScreenNotification,
object: nil
)
}

override func viewDidAppear() {
super.viewDidAppear()

notifyCategoryChange()
}

// MARK: (De)initializers
deinit {
NotificationCenter.default.removeObserver(self)
}

// MARK: Methods
@IBAction func categoriesTableViewSelectionChanged(_ sender: NSTableView) {
notifyCategoryChange()
}

func didEnterFullScreen(_ notification: Notification) {
guard notification.name == .enterFullScreenNotification else { return }

categoriesScrollView.contentInsets.top = 0.0
}

func didExitFullScreen(_ notification: Notification) {
guard notification.name == .exitFullScreenNotification else { return }

categoriesScrollView.contentInsets.top = topEdgeInset
}

private func notifyCategoryChange() {
guard let selectedCategory = StoryType(rawValue: StoryType.allValues[categoriesTableView.selectedRow]) else { return }

Expand All @@ -41,6 +85,12 @@ extension Notification.Name {
static let newCategorySelectedNotification = Notification.Name("NewCategorySelectedNotification")
}

// MARK: - Selectors
private extension Selector {
static let didEnterFullScreen = #selector(CategoriesViewController.didEnterFullScreen(_:))
static let didExitFullScreen = #selector(CategoriesViewController.didExitFullScreen(_:))
}

// MARK: - NSTableView Data Source
extension CategoriesViewController: NSTableViewDataSource {
func numberOfRows(in tableView: NSTableView) -> Int {
Expand Down
14 changes: 9 additions & 5 deletions Diurna/Main.storyboard
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11198.2" systemVersion="16A294a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="mHI-bR-tcx">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11198.2" systemVersion="16A304a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="mHI-bR-tcx">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11198.2"/>
Expand Down Expand Up @@ -158,6 +158,9 @@
<rect key="contentRect" x="163" y="199" width="818" height="500"/>
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="777"/>
<value key="minSize" type="size" width="409" height="300"/>
<connections>
<outlet property="delegate" destination="mHI-bR-tcx" id="A6u-Pa-s3Q"/>
</connections>
</window>
<connections>
<segue destination="1Wn-mi-uyW" kind="relationship" relationship="window.shadowedContentViewController" id="UiF-ko-TW9"/>
Expand All @@ -179,7 +182,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" selectionHighlightStyle="sourceList" columnReordering="NO" columnResizing="NO" multipleSelection="NO" emptySelection="NO" autosaveColumns="NO" typeSelect="NO" rowHeight="24" rowSizeStyle="medium" viewBased="YES" floatsGroupRows="NO" id="U9R-Xi-FUO">
<rect key="frame" x="0.0" y="0.0" width="68" height="471"/>
<rect key="frame" x="0.0" y="0.0" width="68" height="500"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="0.0" height="15"/>
<color key="backgroundColor" name="_sourceListBackgroundColor" catalog="System" colorSpace="catalog"/>
Expand Down Expand Up @@ -230,7 +233,7 @@
</subviews>
<nil key="backgroundColor"/>
</clipView>
<edgeInsets key="contentInsets" left="0.0" right="0.0" top="29" bottom="0.0"/>
<edgeInsets key="contentInsets" left="0.0" right="0.0" top="0.0" bottom="0.0"/>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="EKg-kH-u7n">
<rect key="frame" x="-100" y="-100" width="150" height="16"/>
<autoresizingMask key="autoresizingMask"/>
Expand All @@ -241,6 +244,7 @@
</scroller>
</scrollView>
<connections>
<outlet property="categoriesScrollView" destination="OFS-3P-Mk1" id="oc8-tP-41J"/>
<outlet property="categoriesTableView" destination="U9R-Xi-FUO" id="BNd-ff-piF"/>
</connections>
</viewController>
Expand Down Expand Up @@ -548,15 +552,15 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="QRH-qd-Gfs">
<rect key="frame" x="166" y="201.5" width="119" height="17"/>
<rect key="frame" x="166" y="202" width="119" height="17"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" allowsUndo="NO" sendsActionOnEndEditing="YES" alignment="center" title="No comments yet." usesSingleLineMode="YES" id="Wcj-cQ-gao">
<font key="font" metaFont="system"/>
<color key="textColor" name="tertiaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<stackView distribution="fill" orientation="vertical" alignment="centerX" spacing="0.0" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="UzQ-o9-8gO">
<rect key="frame" x="113" y="193.5" width="225" height="35"/>
<rect key="frame" x="113" y="193" width="225" height="35"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ydK-nz-uz5">
<rect key="frame" x="45" y="18" width="135" height="17"/>
Expand Down
19 changes: 19 additions & 0 deletions Diurna/MainWindowController.swift
Expand Up @@ -25,3 +25,22 @@ class MainWindowController: NSWindowController {
window.standardWindowButton(NSWindowButton.miniaturizeButton)?.frame.origin.y -= 4
}
}

extension MainWindowController: NSWindowDelegate {
func windowWillEnterFullScreen(_ notification: Notification) {
guard notification.name == .NSWindowWillEnterFullScreen else { return }

NotificationCenter.default.post(name: .enterFullScreenNotification, object: self)
}

func windowWillExitFullScreen(_ notification: Notification) {
guard notification.name == .NSWindowWillExitFullScreen else { return }

NotificationCenter.default.post(name: .exitFullScreenNotification, object: self)
}
}

extension Notification.Name {
static let enterFullScreenNotification = Notification.Name("EnterFullScreenNotification")
static let exitFullScreenNotification = Notification.Name("ExitFullScreenNotification")
}

0 comments on commit 3edfc48

Please sign in to comment.