Abhishek
3 years ago
9 changed files with 277 additions and 99 deletions
@ -0,0 +1,22 @@
|
||||
// Copyright © 2015 Abhishek Banthia |
||||
|
||||
import Foundation |
||||
|
||||
var avenirLightFont: NSFont { |
||||
if let avenirFont = NSFont(name: "Avenir-Light", size: 12) { |
||||
return avenirFont |
||||
} |
||||
return NSFont.systemFont(ofSize: 12) |
||||
} |
||||
|
||||
extension ParentPanelController { |
||||
func setupUpcomingEventViewCollectionViewIfNeccesary() { |
||||
if upcomingEventCollectionView != nil { |
||||
upcomingEventCollectionView.enclosingScrollView?.scrollerInsets = NSEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) |
||||
upcomingEventCollectionView.enclosingScrollView?.backgroundColor = NSColor.clear |
||||
upcomingEventCollectionView.setAccessibility("UpcomingEventCollectionView") |
||||
upcomingEventCollectionView.dataSource = upcomingEventsDataSource |
||||
upcomingEventCollectionView.delegate = upcomingEventsDataSource |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,22 @@
|
||||
// Copyright © 2015 Abhishek Banthia |
||||
|
||||
import Foundation |
||||
|
||||
class UpcomingEventViewItem: NSCollectionViewItem { |
||||
static let reuseIdentifier = NSUserInterfaceItemIdentifier("UpcomingEventViewItem") |
||||
@IBOutlet weak var calendarColorView: NSView! |
||||
|
||||
@IBOutlet weak var eventTitleLabel: NSTextField! |
||||
@IBOutlet weak var eventSubtitleLabel: NSButton! |
||||
|
||||
func setup(_ title: String, _ subtitle: String, _ color: NSColor) { |
||||
calendarColorView.layer?.backgroundColor = color.cgColor |
||||
eventTitleLabel.stringValue = title |
||||
eventSubtitleLabel.stringValue = subtitle |
||||
} |
||||
|
||||
override var acceptsFirstResponder: Bool { |
||||
return false |
||||
} |
||||
|
||||
} |
@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="18122" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> |
||||
<dependencies> |
||||
<deployment identifier="macosx"/> |
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="18122"/> |
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> |
||||
</dependencies> |
||||
<objects> |
||||
<customObject id="-2" userLabel="File's Owner"/> |
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> |
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/> |
||||
<customView id="Hz6-mo-xeY"> |
||||
<rect key="frame" x="0.0" y="0.0" width="250" height="75"/> |
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> |
||||
<subviews> |
||||
<customView translatesAutoresizingMaskIntoConstraints="NO" id="aM6-TI-1os" customClass="ClockerTextBackgroundView" customModule="Clocker" customModuleProvider="target"> |
||||
<rect key="frame" x="0.0" y="0.0" width="250" height="75"/> |
||||
<subviews> |
||||
<button focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Khp-8n-4FA"> |
||||
<rect key="frame" x="16" y="21" width="232" height="18"/> |
||||
<constraints> |
||||
<constraint firstAttribute="height" constant="18" id="asu-Dd-XhW"/> |
||||
</constraints> |
||||
<buttonCell key="cell" type="bevel" title="All Day Event" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingHead" truncatesLastVisibleLine="YES" state="on" focusRingType="none" imageScaling="proportionallyDown" inset="2" id="JOt-0Q-EAr"> |
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> |
||||
<font key="font" size="10" name="Avenir-Heavy"/> |
||||
</buttonCell> |
||||
</button> |
||||
<customView wantsLayer="YES" focusRingType="none" translatesAutoresizingMaskIntoConstraints="NO" id="Bbu-oG-vAb"> |
||||
<rect key="frame" x="5" y="21" width="2" height="34"/> |
||||
<constraints> |
||||
<constraint firstAttribute="width" constant="2" id="Qhx-45-1Hc"/> |
||||
<constraint firstAttribute="height" constant="34" id="xeh-m2-Fhh"/> |
||||
</constraints> |
||||
</customView> |
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fTt-gC-72b"> |
||||
<rect key="frame" x="15" y="31" width="235" height="24"/> |
||||
<constraints> |
||||
<constraint firstAttribute="height" constant="24" id="BA4-1v-xiZ"/> |
||||
</constraints> |
||||
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" alignment="left" title="Nandita Jaiswal's 35th birthday" placeholderString="" id="Dtv-o3-gqd"> |
||||
<font key="font" size="12" name="Avenir-Light"/> |
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/> |
||||
<color key="backgroundColor" red="1" green="0.5" blue="0.0" alpha="1" colorSpace="calibratedRGB"/> |
||||
</textFieldCell> |
||||
</textField> |
||||
</subviews> |
||||
<constraints> |
||||
<constraint firstItem="fTt-gC-72b" firstAttribute="top" secondItem="Bbu-oG-vAb" secondAttribute="top" id="FeN-R0-t1A"/> |
||||
<constraint firstItem="Khp-8n-4FA" firstAttribute="bottom" secondItem="Bbu-oG-vAb" secondAttribute="bottom" id="LQD-54-bUh"/> |
||||
<constraint firstItem="Bbu-oG-vAb" firstAttribute="leading" secondItem="aM6-TI-1os" secondAttribute="leading" constant="5" id="Myg-8W-znN"/> |
||||
<constraint firstItem="Khp-8n-4FA" firstAttribute="trailing" secondItem="fTt-gC-72b" secondAttribute="trailing" id="URW-gt-WbF"/> |
||||
<constraint firstAttribute="trailing" secondItem="fTt-gC-72b" secondAttribute="trailing" constant="2" id="UmL-0o-BVG"/> |
||||
<constraint firstItem="Khp-8n-4FA" firstAttribute="leading" secondItem="fTt-gC-72b" secondAttribute="leading" constant="-1" id="VyL-Kt-2aT"/> |
||||
<constraint firstItem="fTt-gC-72b" firstAttribute="leading" secondItem="Bbu-oG-vAb" secondAttribute="trailing" constant="10" id="arv-Oe-yih"/> |
||||
<constraint firstItem="Bbu-oG-vAb" firstAttribute="centerY" secondItem="aM6-TI-1os" secondAttribute="centerY" id="wkl-Vo-0kU"/> |
||||
</constraints> |
||||
</customView> |
||||
</subviews> |
||||
<constraints> |
||||
<constraint firstItem="aM6-TI-1os" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="2AJ-xz-nf9"/> |
||||
<constraint firstItem="aM6-TI-1os" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="D6T-PQ-RdE"/> |
||||
<constraint firstAttribute="bottom" secondItem="aM6-TI-1os" secondAttribute="bottom" id="DmC-7T-lrT"/> |
||||
<constraint firstAttribute="trailing" secondItem="aM6-TI-1os" secondAttribute="trailing" id="aCZ-sV-Mnd"/> |
||||
</constraints> |
||||
<point key="canvasLocation" x="147" y="239"/> |
||||
</customView> |
||||
<customObject id="p0M-E4-898" customClass="UpcomingEventViewItem" customModule="Clocker" customModuleProvider="target"> |
||||
<connections> |
||||
<outlet property="calendarColorView" destination="Bbu-oG-vAb" id="tBe-V1-qmC"/> |
||||
<outlet property="eventSubtitleLabel" destination="Khp-8n-4FA" id="mXV-EZ-2AW"/> |
||||
<outlet property="eventTitleLabel" destination="fTt-gC-72b" id="bOh-LO-tiH"/> |
||||
<outlet property="view" destination="Hz6-mo-xeY" id="9S0-wg-csq"/> |
||||
</connections> |
||||
</customObject> |
||||
</objects> |
||||
</document> |
@ -0,0 +1,30 @@
|
||||
// Copyright © 2015 Abhishek Banthia |
||||
|
||||
import Foundation |
||||
|
||||
class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollectionViewDelegateFlowLayout { |
||||
private var upcomingEvents: [EventInfo] = [] |
||||
|
||||
func updateEventsDataSource(_ events: [EventInfo]) { |
||||
upcomingEvents = events |
||||
} |
||||
|
||||
func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int { |
||||
return upcomingEvents.count |
||||
} |
||||
|
||||
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem { |
||||
let item = collectionView.makeItem(withIdentifier: UpcomingEventViewItem.reuseIdentifier, for: indexPath) as! UpcomingEventViewItem |
||||
let currentEventInfo = upcomingEvents[indexPath.item] |
||||
|
||||
let upcomingEventSubtitle = currentEventInfo.isAllDay ? "All-Day" : currentEventInfo.metadataForMeeting() |
||||
item.setup(currentEventInfo.event.title, upcomingEventSubtitle, currentEventInfo.event.calendar.color) |
||||
return item |
||||
} |
||||
|
||||
func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize { |
||||
let currentEventInfo = upcomingEvents[indexPath.item] |
||||
let prefferedSize = avenirLightFont.size(currentEventInfo.event.title, 250, attributes: [NSAttributedString.Key.font: avenirLightFont,]) |
||||
return NSSize(width: prefferedSize.width, height: 50) |
||||
} |
||||
} |
Loading…
Reference in new issue