Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import SwiftUI
internal extension MainSplitViewController {
func refreshAgentPanes(of workspace: ConnectionWorkspace) {
guard workspace.resolvedContentMode == .agent else { return }
workspace.panes.agentRail.rootView = AnyView(buildAgentRailView(for: workspace))
workspace.panes.agentRail.rootView = AnyView(buildAgentRailView(for: workspace).onSplitItem())
workspace.panes.agentConversation.rootView = AnyView(buildAgentConversationView(for: workspace))
workspace.panes.agentResult.rootView = AnyView(buildAgentResultView(for: workspace))
workspace.panes.agentResult.rootView = AnyView(buildAgentResultView(for: workspace).onSplitItem())
}

/// Re-arms only when the session naming the window changes, so the title can be asked for on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ internal final class MainSplitViewController: NSSplitViewController {
addSplitViewItem(detailSplitItem)

inspectorPaneHost = WorkspacePaneHost()
inspectorPaneHost.installBackdrop(SplitItemBackdrop.makeView())
inspectorSplitItem = NSSplitViewItem(inspectorWithViewController: inspectorPaneHost)
inspectorSplitItem.canCollapse = true
inspectorSplitItem.minimumThickness = Self.inspectorMinThickness
Expand Down Expand Up @@ -825,10 +826,10 @@ internal final class MainSplitViewController: NSSplitViewController {
/// `teardown()` needs only because its panes are never parented again: here it would mount every
/// intermediate value instead of letting one run-loop turn settle on the final one.
private func refreshPanes(of workspace: ConnectionWorkspace) {
workspace.panes.sidebar.rootView = AnyView(buildSidebarView(for: workspace))
workspace.panes.sidebar.rootView = AnyView(buildSidebarView(for: workspace).onSplitItem())
workspace.panes.detail.rootView = AnyView(buildDetailView(for: workspace))
workspace.panes.inspector.rootView = AnyView(buildInspectorView(for: workspace))
workspace.panes.assistant.rootView = AnyView(buildAssistantView(for: workspace))
workspace.panes.inspector.rootView = AnyView(buildInspectorView(for: workspace).onSplitItem())
workspace.panes.assistant.rootView = AnyView(buildAssistantView(for: workspace).onSplitItem())
refreshAgentPanes(of: workspace)
refreshTabStripPane(of: workspace)
workspace.panes.markRendered(workspace.paneRenderKey)
Expand Down Expand Up @@ -1065,8 +1066,8 @@ internal final class MainSplitViewController: NSSplitViewController {
/// publishes those actions.
func rebuildTrailingPanes() {
guard let selected = workspaces.selected else { return }
selected.panes.inspector.rootView = AnyView(buildInspectorView(for: selected))
selected.panes.assistant.rootView = AnyView(buildAssistantView(for: selected))
selected.panes.inspector.rootView = AnyView(buildInspectorView(for: selected).onSplitItem())
selected.panes.assistant.rootView = AnyView(buildAssistantView(for: selected).onSplitItem())
}

// MARK: - Session Bindings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ internal final class NavigationSidebarViewController: NSViewController {

override func loadView() {
view = NSView()
// On the pane root and not the split below it, so it reaches the titlebar band too.
let backdrop = SplitItemBackdrop.makeView()
backdrop.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(backdrop)
NSLayoutConstraint.activate([
backdrop.leadingAnchor.constraint(equalTo: view.leadingAnchor),
backdrop.trailingAnchor.constraint(equalTo: view.trailingAnchor),
backdrop.topAnchor.constraint(equalTo: view.topAnchor),
backdrop.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])

_ = railController.view
railController.isStripShown = false
Expand Down
18 changes: 16 additions & 2 deletions apple/TablePro/Theme/MaterialAccessibility.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftUI
import TableProTheme

internal enum MaterialRole {
case toolbar
Expand Down Expand Up @@ -56,15 +57,28 @@ private struct AccessibleMaterialBackgroundShape<S: Shape>: ViewModifier {
}
}

// The scrim covers a detail pane, so its solid stand-in is the window color that pane sits on.
internal struct AccessibleMaterialScrim: View {
let material: Material

@Environment(\.accessibilityReduceTransparency) private var reduceTransparency
// The environment value is get-only, so a test hands its own.
var reduceTransparency: Bool?

@ObservedObject private var themeEngine = ThemeEngine.shared
@Environment(\.accessibilityReduceTransparency) private var systemReduceTransparency
@Environment(\.colorSchemeContrast) private var contrast

var body: some View {
let reduceTransparency = reduceTransparency ?? systemReduceTransparency
if SolidSurfacePreference.prefersSolid(reduceTransparency: reduceTransparency, contrast: contrast) {
Rectangle().fill(MaterialRole.scrim.solidFallback)
Rectangle().fill(
ThemeShapeStyle.style(
.windowBackdrop,
native: MaterialRole.scrim.solidFallback,
engine: themeEngine,
contrast: contrast
)
)
} else {
Rectangle().fill(material)
}
Expand Down
10 changes: 5 additions & 5 deletions apple/TablePro/Theme/PaneBarBackground.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import SwiftUI

/// A bar's material is drawn for the system window color, so over a themed backdrop it reads as a
/// system band. The bar then draws nothing and shows the pane's theme through it.
// A bar's material is drawn for the system window color, so over a themed backdrop it reads as a
// system band. The bar then draws nothing and shows the pane's theme through it.
private struct PaneBarBackground<Native: ShapeStyle>: ViewModifier {
@ObservedObject private var themeEngine = ThemeEngine.shared
@Environment(\.colorSchemeContrast) private var contrast
@Environment(\.isOnSplitItem) private var isOnSplitItem

let native: Native
let edges: Edge.Set

func body(content: Content) -> some View {
let isThemed = ThemeBackdropState.isThemed(highContrast: contrast == .increased)
let isThemed = ThemeBackdropState.isThemed(highContrast: contrast == .increased, onSplitItem: isOnSplitItem)
return content.background(
isThemed ? AnyShapeStyle(Color.clear) : AnyShapeStyle(native),
ignoresSafeAreaEdges: edges
Expand All @@ -19,8 +20,7 @@ private struct PaneBarBackground<Native: ShapeStyle>: ViewModifier {
}

internal extension View {
/// No edges by default: a bar at the top of a pane would otherwise reach under the toolbar and
/// pull its glass toward the bar's material.
// No edges by default: a top bar would otherwise reach under the toolbar and pull its glass toward the bar's material.
func paneBarBackground(_ native: some ShapeStyle = .bar, ignoresSafeAreaEdges edges: Edge.Set = []) -> some View {
modifier(PaneBarBackground(native: native, edges: edges))
}
Expand Down
63 changes: 63 additions & 0 deletions apple/TablePro/Theme/SplitItemBackdrop.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import AppKit
import SwiftUI
import TableProTheme

// Under Reduce Transparency the sidebar and inspector glass draws an opaque system fill that drops the
// window color, so the pane draws `window.background` itself until the glass comes back.
@MainActor
internal enum SplitItemBackdrop {
internal static func fills(reachesChrome: Bool, reduceTransparency: Bool, isThemed: Bool) -> Bool {
reachesChrome && reduceTransparency && isThemed
}

internal static func makeView(reduceTransparency: Bool? = nil) -> NSView {
let view = SplitItemBackdropView(rootView: SplitItemBackdropSurface(reduceTransparency: reduceTransparency))
view.sizingOptions = []
return view
}
}

internal struct SplitItemBackdropFill: ViewModifier {
@ObservedObject private var themeEngine = ThemeEngine.shared
@Environment(\.accessibilityReduceTransparency) private var systemReduceTransparency
@Environment(\.colorSchemeContrast) private var contrast

// The environment value is get-only, so a test hands its own.
internal var reduceTransparency: Bool?
internal var reachesChrome = ThemeWindowBackdrop.canReachChrome

internal func body(content: Content) -> some View {
let fills = SplitItemBackdrop.fills(
reachesChrome: reachesChrome,
reduceTransparency: reduceTransparency ?? systemReduceTransparency,
isThemed: ThemeBackdropState.isThemed(highContrast: contrast == .increased)
)
return content.background(
fills ? AnyShapeStyle(Color(nsColor: themeEngine.palette[.windowBackdrop])) : AnyShapeStyle(Color.clear),
ignoresSafeAreaEdges: .all
)
}
}

internal extension View {
func splitItemBackdrop() -> some View {
modifier(SplitItemBackdropFill())
}
}

private struct SplitItemBackdropSurface: View {
let reduceTransparency: Bool?

var body: some View {
Color.clear
.modifier(SplitItemBackdropFill(reduceTransparency: reduceTransparency))
.accessibilityHidden(true)
}
}

// A point the pane above leaves unclaimed still reaches the glass and the window.
private final class SplitItemBackdropView: NSHostingView<SplitItemBackdropSurface> {
override func hitTest(_ point: NSPoint) -> NSView? {
nil
}
}
33 changes: 30 additions & 3 deletions apple/TablePro/Theme/ThemeBackdropState.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
import AppKit
import SwiftUI
import TableProTheme

/// Whether the window backdrop draws the theme's color. Chrome over the backdrop asks this rather
/// than reading a slot: a bar keeps its material until the theme colors what is behind it.
// Chrome asks this rather than reading a slot: a bar keeps its material until the theme colors what is behind it.
@MainActor
internal enum ThemeBackdropState {
internal static func isThemed(in appearance: NSAppearance, scope: ThemeScope = .live) -> Bool {
isThemed(highContrast: appearance.isHighContrast, scope: scope)
}

/// For SwiftUI, which knows the contrast from its environment rather than from an appearance.
internal static func isThemed(highContrast: Bool, scope: ThemeScope = .live) -> Bool {
scope.activeTheme.isOverridden(.windowBackdrop, highContrast: highContrast)
}

// A sidebar or inspector takes the theme only through the window color, which reaches it from macOS 26.
internal static func isThemed(
highContrast: Bool,
onSplitItem: Bool,
reachesChrome: Bool = ThemeWindowBackdrop.canReachChrome,
scope: ThemeScope = .live
) -> Bool {
guard !onSplitItem || reachesChrome else { return false }
return isThemed(highContrast: highContrast, scope: scope)
}
}

private struct OnSplitItemKey: EnvironmentKey {
static let defaultValue = false
}

internal extension EnvironmentValues {
var isOnSplitItem: Bool {
get { self[OnSplitItemKey.self] }
set { self[OnSplitItemKey.self] = newValue }
}
}

internal extension View {
func onSplitItem() -> some View {
environment(\.isOnSplitItem, true)
}
}
1 change: 1 addition & 0 deletions apple/TablePro/Views/Agent/AgentSessionRailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ internal struct AgentSessionRailView: View {
guard let session = highlightedSession else { return }
onDelete(session.id)
}
.splitItemGlassBackground()
}

/// A contextual menu leaves out what does not apply rather than dimming it, which is the reverse
Expand Down
2 changes: 2 additions & 0 deletions apple/TablePro/Views/DataFiles/DataFileRowDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ struct DataFileRowDetailsView: View {
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.splitItemBackdrop()
.onSplitItem()
.onAppear(perform: configure)
.onChange(of: controller.selectedRowIndices) { _ in configure() }
.onChange(of: controller.pageRevision) { _ in configure() }
Expand Down
5 changes: 3 additions & 2 deletions apple/TablePro/Views/Results/StatusBarChrome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ private struct StatusBarMaterial: NSViewRepresentable {
func updateNSView(_ nsView: NSVisualEffectView, context: Context) {}
}

/// The material does not follow a custom window color, so over a themed backdrop the bar draws none.
// The material does not follow a custom window color, so over a themed backdrop the bar draws none.
private struct StatusBarChromeModifier: ViewModifier {
@ObservedObject private var themeEngine = ThemeEngine.shared
@Environment(\.colorSchemeContrast) private var contrast
@Environment(\.isOnSplitItem) private var isOnSplitItem

func body(content: Content) -> some View {
let isThemed = ThemeBackdropState.isThemed(highContrast: contrast == .increased)
let isThemed = ThemeBackdropState.isThemed(highContrast: contrast == .increased, onSplitItem: isOnSplitItem)
return VStack(spacing: 0) {
Divider()
content
Expand Down
Loading
Loading