-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: fence <[email protected]>
- Loading branch information
1 parent
a8668af
commit f1a1048
Showing
6 changed files
with
121 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Amethyst.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
Amethyst.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// TwoPaneRightLayout.swift | ||
// Amethyst | ||
// | ||
// Created by Anja on 16.06.23. | ||
// Copyright © 2023 Ian Ynda-Hummel. All rights reserved. | ||
// | ||
|
||
import Silica | ||
|
||
class TwoPaneRightLayout<Window: WindowType>: Layout<Window>, PanedLayout { | ||
override static var layoutName: String { return "Two Pane Right" } | ||
override static var layoutKey: String { return "two-pane-right" } | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case mainPaneCount | ||
case mainPaneRatio | ||
} | ||
|
||
override var layoutDescription: String { return "" } | ||
|
||
private(set) var mainPaneCount: Int = 1 | ||
private(set) var mainPaneRatio: CGFloat = 0.5 | ||
|
||
required init() { | ||
super.init() | ||
} | ||
|
||
required init(from decoder: Decoder) throws { | ||
let values = try decoder.container(keyedBy: CodingKeys.self) | ||
self.mainPaneCount = try values.decode(Int.self, forKey: .mainPaneCount) | ||
self.mainPaneRatio = try values.decode(CGFloat.self, forKey: .mainPaneRatio) | ||
super.init() | ||
} | ||
|
||
override func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encode(mainPaneCount, forKey: .mainPaneCount) | ||
try container.encode(mainPaneRatio, forKey: .mainPaneRatio) | ||
} | ||
|
||
func recommendMainPaneRawRatio(rawRatio: CGFloat) { | ||
mainPaneRatio = rawRatio | ||
} | ||
|
||
func increaseMainPaneCount() {} | ||
|
||
func decreaseMainPaneCount() {} | ||
|
||
override func frameAssignments(_ windowSet: WindowSet<Window>, on screen: Screen) -> [FrameAssignmentOperation<Window>]? { | ||
let windows = windowSet.windows | ||
|
||
guard !windows.isEmpty else { | ||
return [] | ||
} | ||
|
||
let mainPaneCount = min(windows.count, self.mainPaneCount) | ||
let secondaryPaneCount = windows.count > 1 ? 1 : 0 | ||
let hasSecondaryPane = secondaryPaneCount > 0 | ||
|
||
let screenFrame = screen.adjustedFrame() | ||
let isHorizontal = (screenFrame.size.width / screenFrame.size.height) >= 1 | ||
|
||
let mainPaneWindowHeight = screenFrame.size.height * (!isHorizontal && hasSecondaryPane ? mainPaneRatio : 1) | ||
let secondaryPaneWindowHeight = isHorizontal ? mainPaneWindowHeight : screenFrame.size.height - mainPaneWindowHeight | ||
|
||
let mainPaneWindowWidth = screenFrame.size.width * (isHorizontal && hasSecondaryPane ? mainPaneRatio : 1) | ||
let secondaryPaneWindowWidth = !isHorizontal ? mainPaneWindowWidth : screenFrame.size.width - mainPaneWindowWidth | ||
|
||
return windows.reduce([]) { acc, window -> [FrameAssignmentOperation<Window>] in | ||
var assignments = acc | ||
var windowFrame = CGRect.zero | ||
let isMain = acc.count < mainPaneCount | ||
var scaleFactor: CGFloat | ||
|
||
if isMain { | ||
scaleFactor = screenFrame.size.width / mainPaneWindowWidth | ||
windowFrame.origin.x = screenFrame.origin.x + (isHorizontal ? secondaryPaneWindowWidth : 0) | ||
windowFrame.origin.y = screenFrame.origin.y | ||
windowFrame.size.width = mainPaneWindowWidth | ||
windowFrame.size.height = mainPaneWindowHeight | ||
} else { | ||
scaleFactor = screenFrame.size.width / secondaryPaneWindowWidth | ||
windowFrame.origin.x = screenFrame.origin.x | ||
windowFrame.origin.y = screenFrame.origin.y + (isHorizontal ? 0 : mainPaneWindowHeight) | ||
windowFrame.size.width = secondaryPaneWindowWidth | ||
windowFrame.size.height = secondaryPaneWindowHeight | ||
} | ||
|
||
let resizeRules = ResizeRules(isMain: isMain, unconstrainedDimension: .horizontal, scaleFactor: scaleFactor) | ||
let frameAssignment = FrameAssignment<Window>( | ||
frame: windowFrame, | ||
window: window, | ||
screenFrame: screenFrame, | ||
resizeRules: resizeRules | ||
) | ||
|
||
assignments.append(FrameAssignmentOperation(frameAssignment: frameAssignment, windowSet: windowSet)) | ||
|
||
return assignments | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters