Font size adjustment
This commit is contained in:
@@ -173,6 +173,33 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
|
||||
autocompleteViewController.delegate = self
|
||||
autocompleteViewController.view.isHidden = true
|
||||
|
||||
// Font size adjust
|
||||
toolbarController.urlBar.documentButton.addAction(UIAction(handler: { [unowned self] _ in
|
||||
let documentControls = DocumentControlViewController()
|
||||
documentControls.modalPresentationStyle = .popover
|
||||
documentControls.popoverPresentationController?.permittedArrowDirections = [ .down, .up ]
|
||||
documentControls.popoverPresentationController?.sourceView = toolbarController.urlBar.documentButton
|
||||
documentControls.popoverPresentationController?.delegate = self
|
||||
|
||||
let numberFormatter = NumberFormatter()
|
||||
numberFormatter.numberStyle = .percent
|
||||
|
||||
let label = documentControls.fontSizeAdjustView.labelView
|
||||
label.text = numberFormatter.string(for: tab.webView._viewScale)
|
||||
|
||||
documentControls.fontSizeAdjustView.decreaseSizeButton.addAction(UIAction(handler: { [unowned self] _ in
|
||||
tab.webView._viewScale -= 0.10
|
||||
label.text = numberFormatter.string(for: tab.webView._viewScale)
|
||||
}), for: .touchUpInside)
|
||||
|
||||
documentControls.fontSizeAdjustView.increaseSizeButton.addAction(UIAction(handler: { [unowned self] _ in
|
||||
tab.webView._viewScale += 0.10
|
||||
label.text = numberFormatter.string(for: tab.webView._viewScale)
|
||||
}), for: .touchUpInside)
|
||||
|
||||
present(documentControls, animated: true, completion: nil)
|
||||
}), for: .touchUpInside)
|
||||
|
||||
self.view = browserView
|
||||
}
|
||||
|
||||
|
||||
32
App/Document Controls UI/DocumentControlViewController.swift
Normal file
32
App/Document Controls UI/DocumentControlViewController.swift
Normal file
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// DocumentControlViewController.swift
|
||||
// App
|
||||
//
|
||||
// Created by James Magahern on 9/22/20.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class DocumentControlViewController: UIViewController
|
||||
{
|
||||
let documentControlView = StackView(dimension: .vertical)
|
||||
let fontSizeAdjustView = FontSizeAdjustView()
|
||||
|
||||
static public let preferredWidth = CGFloat(200.0)
|
||||
static public let controlHeight = CGFloat(48.0)
|
||||
|
||||
convenience init() {
|
||||
self.init(nibName: nil, bundle: nil)
|
||||
|
||||
documentControlView.addArrangedSubview(fontSizeAdjustView)
|
||||
}
|
||||
|
||||
override func loadView() {
|
||||
self.view = documentControlView
|
||||
}
|
||||
|
||||
override var preferredContentSize: CGSize {
|
||||
get { documentControlView.sizeThatFits(CGSize(width: Self.preferredWidth, height: -1)) }
|
||||
set {}
|
||||
}
|
||||
}
|
||||
58
App/Document Controls UI/FontSizeAdjustView.swift
Normal file
58
App/Document Controls UI/FontSizeAdjustView.swift
Normal file
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// FontSizeAdjustView.swift
|
||||
// App
|
||||
//
|
||||
// Created by James Magahern on 9/22/20.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class FontSizeAdjustView: UIView
|
||||
{
|
||||
let decreaseSizeButton = UIButton(frame: .zero)
|
||||
let increaseSizeButton = UIButton(frame: .zero)
|
||||
let labelView = UILabel(frame: .zero)
|
||||
|
||||
convenience init() {
|
||||
self.init(frame: .zero)
|
||||
|
||||
labelView.textColor = .secondaryLabel
|
||||
labelView.textAlignment = .center
|
||||
labelView.text = "100%"
|
||||
|
||||
tintColor = .black
|
||||
|
||||
decreaseSizeButton.setImage(UIImage(systemName: "minus"), for: .normal)
|
||||
increaseSizeButton.setImage(UIImage(systemName: "plus"), for: .normal)
|
||||
|
||||
addSubview(increaseSizeButton)
|
||||
addSubview(decreaseSizeButton)
|
||||
addSubview(labelView)
|
||||
}
|
||||
|
||||
override func sizeThatFits(_ size: CGSize) -> CGSize {
|
||||
CGSize(width: size.width, height: DocumentControlViewController.controlHeight)
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
decreaseSizeButton.frame = CGRect(
|
||||
x: 0.0, y: 0.0,
|
||||
width: bounds.height,
|
||||
height: bounds.height
|
||||
)
|
||||
|
||||
increaseSizeButton.frame = CGRect(
|
||||
x: bounds.width - bounds.height, y: 0.0,
|
||||
width: bounds.height,
|
||||
height: bounds.height
|
||||
)
|
||||
|
||||
labelView.frame = CGRect(
|
||||
x: decreaseSizeButton.frame.maxX, y: 0.0,
|
||||
width: bounds.width - decreaseSizeButton.frame.width - increaseSizeButton.frame.width,
|
||||
height: bounds.height
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -6,3 +6,4 @@
|
||||
|
||||
// SPI
|
||||
#import <UIKit/UITextField_Private.h>
|
||||
#import <WebKit/WKWebViewPrivate.h>
|
||||
|
||||
@@ -12,6 +12,7 @@ class URLBar: ReliefButton
|
||||
let textField = UITextField(frame: .zero)
|
||||
let refreshButton = UIButton(frame: .zero)
|
||||
let errorButton = UIButton(frame: .zero)
|
||||
let documentButton = UIButton(frame: .zero)
|
||||
|
||||
public enum LoadProgress {
|
||||
case complete
|
||||
@@ -28,11 +29,14 @@ class URLBar: ReliefButton
|
||||
private let progressIndicatorView = ProgressIndicatorView()
|
||||
private var progressIndicatorAnimating = false
|
||||
|
||||
private let documentImage = UIImage(systemName: "doc.plaintext")
|
||||
private let refreshImage = UIImage(systemName: "arrow.clockwise")
|
||||
private let stopImage = UIImage(systemName: "xmark")
|
||||
|
||||
private let backgroundCornerRadius: CGFloat = 0
|
||||
|
||||
private let documentSeparatorView = UIView(frame: .zero)
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
@@ -70,6 +74,13 @@ class URLBar: ReliefButton
|
||||
errorButton.setTitle("ERR", for: .normal)
|
||||
addSubview(errorButton)
|
||||
|
||||
documentButton.tintColor = .secondaryLabel
|
||||
documentButton.setImage(documentImage, for: .normal)
|
||||
addSubview(documentButton)
|
||||
|
||||
documentSeparatorView.backgroundColor = .secondarySystemFill
|
||||
addSubview(documentSeparatorView)
|
||||
|
||||
setErrorButtonAnimating(false)
|
||||
}
|
||||
|
||||
@@ -172,7 +183,27 @@ class URLBar: ReliefButton
|
||||
backgroundView.frame = bounds
|
||||
shadowView.frame = bounds
|
||||
progressIndicatorView.frame = backgroundView.bounds
|
||||
textField.frame = bounds.insetBy(dx: 6.0, dy: 0)
|
||||
|
||||
// Document button
|
||||
documentButton.frame = CGRect(x: 0.0, y: 0.0, width: bounds.height, height: bounds.height)
|
||||
|
||||
// Document separator
|
||||
documentSeparatorView.frame = CGRect(
|
||||
x: documentButton.frame.maxX, y: 0.0,
|
||||
width: 1.0, height: bounds.height
|
||||
)
|
||||
documentSeparatorView.frame = documentSeparatorView.frame.insetBy(dx: 0.0, dy: 3.0)
|
||||
|
||||
// Text field
|
||||
let textFieldPadding: CGFloat = 5.0
|
||||
let textFieldOrigin = CGPoint(x: documentButton.frame.maxX + textFieldPadding, y: 0.0)
|
||||
textField.frame = CGRect(
|
||||
origin: textFieldOrigin,
|
||||
size: CGSize(
|
||||
width: bounds.width - textFieldOrigin.x - textFieldPadding,
|
||||
height: bounds.height
|
||||
)
|
||||
)
|
||||
|
||||
var fadeCutoffLocation: CGFloat = 0.8
|
||||
|
||||
|
||||
92
App/Utilities/StackView.swift
Normal file
92
App/Utilities/StackView.swift
Normal file
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// StackView.swift
|
||||
// App
|
||||
//
|
||||
// Created by James Magahern on 9/22/20.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class StackView: UIView
|
||||
{
|
||||
var arrangedSubviews: [UIView] = []
|
||||
{ didSet { setNeedsLayout() } }
|
||||
|
||||
var layoutDimension: UIAxis = .vertical
|
||||
|
||||
convenience init(dimension: UIAxis) {
|
||||
self.init(frame: .zero)
|
||||
self.layoutDimension = dimension
|
||||
}
|
||||
|
||||
// Convenience
|
||||
public func addArrangedSubview(_ view: UIView) {
|
||||
addSubview(view)
|
||||
arrangedSubviews.append(view)
|
||||
setNeedsLayout()
|
||||
}
|
||||
|
||||
public func removeArrangedSubview(_ view: UIView) {
|
||||
if view.superview == self {
|
||||
view.removeFromSuperview()
|
||||
}
|
||||
|
||||
arrangedSubviews.removeAll { $0 == view }
|
||||
setNeedsLayout()
|
||||
}
|
||||
|
||||
public func removeAllArrangedSubviews() {
|
||||
arrangedSubviews.forEach { $0.removeFromSuperview() }
|
||||
arrangedSubviews.removeAll()
|
||||
setNeedsLayout()
|
||||
}
|
||||
|
||||
override func sizeThatFits(_ containerSize: CGSize) -> CGSize {
|
||||
var size: CGSize = .zero
|
||||
|
||||
if layoutDimension == .horizontal {
|
||||
size.height = containerSize.height
|
||||
} else {
|
||||
size.width = containerSize.width
|
||||
}
|
||||
|
||||
var spaceRemaining = containerSize
|
||||
for view in arrangedSubviews {
|
||||
let viewSize = view.sizeThatFits(spaceRemaining)
|
||||
if layoutDimension == .horizontal {
|
||||
size.width += viewSize.width
|
||||
spaceRemaining.width -= viewSize.width
|
||||
} else {
|
||||
size.height += viewSize.height
|
||||
spaceRemaining.height -= viewSize.height
|
||||
}
|
||||
}
|
||||
|
||||
return size
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
var origin: CGPoint = CGPoint(x: safeAreaInsets.left, y: safeAreaInsets.top)
|
||||
var spaceRemaining = bounds.size
|
||||
for view in arrangedSubviews {
|
||||
var viewSize = view.sizeThatFits(spaceRemaining)
|
||||
|
||||
var offset: CGPoint = .zero
|
||||
if layoutDimension == .horizontal {
|
||||
offset.x = viewSize.width
|
||||
viewSize.height = bounds.height
|
||||
spaceRemaining.width -= viewSize.width
|
||||
} else {
|
||||
offset.y = viewSize.height
|
||||
viewSize.width = bounds.width
|
||||
spaceRemaining.height -= viewSize.height
|
||||
}
|
||||
|
||||
view.frame = CGRect(origin: origin, size: viewSize)
|
||||
origin.x += offset.x
|
||||
origin.y += offset.y
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user