Browse Source

Support increasing / decreasing text size

master
Matt Baer 4 years ago
parent
commit
fd6b44ec73
4 changed files with 50 additions and 3 deletions
  1. +4
    -0
      writeas.xcodeproj/project.pbxproj
  2. +12
    -0
      writeas/Base.lproj/Main.storyboard
  3. +15
    -0
      writeas/Preferences.swift
  4. +19
    -3
      writeas/ViewController.swift

+ 4
- 0
writeas.xcodeproj/project.pbxproj View File

@@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
33071D332D5799D36FBC1DDD /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3307150C0D2CA1C8A71C5E26 /* Preferences.swift */; };
C98EE9AC1F29532F002F646E /* writeas in Resources */ = {isa = PBXBuildFile; fileRef = C98EE9AB1F29532F002F646E /* writeas */; };
C9953E7D1F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf in Resources */ = {isa = PBXBuildFile; fileRef = C9953E791F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf */; };
C9953E7E1F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600italic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = C9953E7A1F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600italic.ttf */; };
@@ -23,6 +24,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
3307150C0D2CA1C8A71C5E26 /* Preferences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Preferences.swift; path = writeas/Preferences.swift; sourceTree = "<group>"; };
C98EE9AB1F29532F002F646E /* writeas */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = writeas; sourceTree = "<group>"; };
C9953E791F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf"; sourceTree = "<group>"; };
C9953E7A1F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600italic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600italic.ttf"; sourceTree = "<group>"; };
@@ -71,6 +73,7 @@
children = (
C99B910B1C33841E00A91990 /* writeas */,
C99B910A1C33841E00A91990 /* Products */,
3307150C0D2CA1C8A71C5E26 /* Preferences.swift */,
);
sourceTree = "<group>";
};
@@ -180,6 +183,7 @@
files = (
C99B910F1C33841E00A91990 /* ViewController.swift in Sources */,
C99B910D1C33841E00A91990 /* AppDelegate.swift in Sources */,
33071D332D5799D36FBC1DDD /* Preferences.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};


+ 12
- 0
writeas/Base.lproj/Main.storyboard View File

@@ -244,6 +244,18 @@ DQ
<action selector="toggleNightMode:" target="Voe-Tx-rLC" id="Nmq-eG-y3w"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="ue7-Hl-EOO"/>
<menuItem title="Increase Text Size" keyEquivalent="+" id="BWd-kX-bJP">
<connections>
<action selector="viewIncTextSize:" target="Voe-Tx-rLC" id="Z3T-tc-ixm"/>
</connections>
</menuItem>
<menuItem title="Decrease Text Size" keyEquivalent="-" id="fGL-5w-dMs">
<connections>
<action selector="viewDecTextSize:" target="Voe-Tx-rLC" id="6K9-kj-cui"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="wad-VP-ov7"/>
</items>
</menu>
</menuItem>


+ 15
- 0
writeas/Preferences.swift View File

@@ -0,0 +1,15 @@
//
// Created by Matt Baer on 7/29/17.
// Copyright (c) 2017 A Bunch Tell. All rights reserved.
//

import Foundation

class Preferences {

class func getFontSize() -> CGFloat {
let size = Int(UserDefaults.standard.string(forKey: "editor_text_size") ?? "16") ?? 16

return CGFloat(size)
}
}

+ 19
- 3
writeas/ViewController.swift View File

@@ -19,7 +19,7 @@ class ViewController: NSViewController, NSTextViewDelegate, NSUserNotificationCe

loadDocument()

writerText.font = NSFont(name: "Lora", size: 16)
writerText.font = NSFont(name: "Lora", size: Preferences.getFontSize())
writerText.isHorizontallyResizable = false
writerText.textContainerInset = NSSize(width: 16, height: 16)
writerText.isAutomaticQuoteSubstitutionEnabled = false
@@ -34,8 +34,7 @@ class ViewController: NSViewController, NSTextViewDelegate, NSUserNotificationCe
override func viewDidAppear() {
super.viewDidAppear()

// Fit textview to window size
writerText.setFrameSize(NSSize(width: self.view.window!.frame.width, height: self.view.window!.frame.height))
configureWindow()

// Style the window
self.view.window!.title = "Write.as"
@@ -45,6 +44,11 @@ class ViewController: NSViewController, NSTextViewDelegate, NSUserNotificationCe
self.view.window!.backgroundColor = NSColor.white
}

func configureWindow() {
// Fit textview to window size
writerText.setFrameSize(NSSize(width: self.view.window!.frame.width, height: self.view.window!.frame.height))
}

override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
@@ -132,5 +136,17 @@ class ViewController: NSViewController, NSTextViewDelegate, NSUserNotificationCe
self.writerText.textColor = NSColor.black
}
}

func adjustTextSize(increment: Bool) {
var size = Preferences.getFontSize()
if increment {
size += 2
} else {
size -= 1
}
self.writerText.font = NSFont(name: "Lora", size: size)
UserDefaults.standard.set(String(Int(size)), forKey: "editor_text_size")
configureWindow()
}
}


Loading…
Cancel
Save