Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxies PanedLayout function calls to extended layouts #1551

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion Amethyst/Layout/Layouts/CustomLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private enum LayoutExtension<Window: WindowType> {
case layout(Layout<Window>)
}

class CustomLayout<Window: WindowType>: StatefulLayout<Window> {
class CustomLayout<Window: WindowType>: StatefulLayout<Window>, PanedLayout {
typealias WindowID = Window.WindowID

private enum CodingKeys: String, CodingKey {
Expand All @@ -49,6 +49,9 @@ class CustomLayout<Window: WindowType>: StatefulLayout<Window> {
private let key: String
private let fileURL: URL

private(set) var mainPaneCount: Int = 1
private(set) var mainPaneRatio: CGFloat = 1.0

private lazy var context: JSContext? = {
guard let context = JSContext() else {
return nil
Expand Down Expand Up @@ -315,4 +318,62 @@ class CustomLayout<Window: WindowType>: StatefulLayout<Window> {

return jsChange
}

func recommendMainPaneRawRatio(rawRatio: CGFloat) {
switch layoutExtension {
case .layout(let layout):
if let panedLayout = layout as? PanedLayout {
panedLayout.recommendMainPaneRawRatio(rawRatio: rawRatio)
mainPaneRatio = panedLayout.mainPaneRatio
}
default:
mainPaneRatio = rawRatio
}
}

func increaseMainPaneCount() {
switch layoutExtension {
case .layout(let layout):
if let panedLayout = layout as? PanedLayout {
panedLayout.increaseMainPaneCount()
mainPaneCount = panedLayout.mainPaneCount
}
default:
mainPaneCount += 1
}
}

func decreaseMainPaneCount() {
switch layoutExtension {
case .layout(let layout):
if let panedLayout = layout as? PanedLayout {
panedLayout.decreaseMainPaneCount()
mainPaneCount = panedLayout.mainPaneCount
}
default:
mainPaneCount -= 1
}
}

func shrinkMainPane() {
switch layoutExtension {
case .layout(let layout):
if let panedLayout = layout as? PanedLayout {
panedLayout.shrinkMainPane()
}
default:
()
}
}

func expandMainPane() {
switch layoutExtension {
case .layout(let layout):
if let panedLayout = layout as? PanedLayout {
panedLayout.expandMainPane()
}
default:
()
}
}
}
Loading