Keep the prefs window width constant between panes. Keep the top edge of the window constant.

This commit is contained in:
Brent Simmons 2019-01-26 22:01:38 -08:00
parent 7f731164a3
commit 8a0f65dd24
1 changed files with 5 additions and 5 deletions

View File

@ -29,6 +29,7 @@ private struct ToolbarItemIdentifier {
class PreferencesWindowController : NSWindowController, NSToolbarDelegate { class PreferencesWindowController : NSWindowController, NSToolbarDelegate {
private let windowFrameName = "Preferences" private let windowFrameName = "Preferences"
private let windowWidth = CGFloat(512.0) // Width is constant for all views; only the height changes
private var viewControllers = [String: NSViewController]() private var viewControllers = [String: NSViewController]()
private let toolbarItemSpecs: [PreferencesToolbarItemSpec] = { private let toolbarItemSpecs: [PreferencesToolbarItemSpec] = {
var specs = [PreferencesToolbarItemSpec]() var specs = [PreferencesToolbarItemSpec]()
@ -37,7 +38,6 @@ class PreferencesWindowController : NSWindowController, NSToolbarDelegate {
return specs return specs
}() }()
override func windowDidLoad() { override func windowDidLoad() {
let toolbar = NSToolbar(identifier: NSToolbar.Identifier("PreferencesToolbar")) let toolbar = NSToolbar(identifier: NSToolbar.Identifier("PreferencesToolbar"))
@ -163,24 +163,24 @@ private extension PreferencesWindowController {
viewControllers[identifier] = viewController viewControllers[identifier] = viewController
return viewController return viewController
} }
func resizeWindow(toFitView view: NSView) { func resizeWindow(toFitView view: NSView) {
let viewFrame = view.frame let viewFrame = view.frame
let windowFrame = window!.frame let windowFrame = window!.frame
let contentViewFrame = window!.contentView!.frame let contentViewFrame = window!.contentView!.frame
let deltaHeight = NSHeight(contentViewFrame) - NSHeight(viewFrame) let deltaHeight = NSHeight(contentViewFrame) - NSHeight(viewFrame)
let heightForWindow = NSHeight(windowFrame) - deltaHeight let heightForWindow = NSHeight(windowFrame) - deltaHeight
let windowOriginY = NSMinY(windowFrame)// + deltaHeight let windowOriginY = NSMinY(windowFrame) + deltaHeight
var updatedWindowFrame = windowFrame var updatedWindowFrame = windowFrame
updatedWindowFrame.size.height = heightForWindow updatedWindowFrame.size.height = heightForWindow
updatedWindowFrame.origin.y = windowOriginY updatedWindowFrame.origin.y = windowOriginY
updatedWindowFrame.size.width = NSWidth(viewFrame) updatedWindowFrame.size.width = windowWidth //NSWidth(viewFrame)
var updatedViewFrame = viewFrame var updatedViewFrame = viewFrame
updatedViewFrame.origin = NSZeroPoint updatedViewFrame.origin = NSZeroPoint
updatedViewFrame.size.width = windowWidth
if viewFrame != updatedViewFrame { if viewFrame != updatedViewFrame {
view.frame = updatedViewFrame view.frame = updatedViewFrame
} }