macos: plumb through the split divider color

This commit is contained in:
Mitchell Hashimoto
2024-01-29 21:32:10 -08:00
parent 375df57155
commit 18dfb642f5
5 changed files with 31 additions and 13 deletions

View File

@ -258,5 +258,14 @@ extension Ghostty {
blue: blue / 255 blue: blue / 255
) )
} }
// This isn't actually a configurable value currently but it could be done day.
// We put it here because it is a color that changes depending on the configuration.
var splitDividerColor: Color {
let backgroundColor = NSColor(backgroundColor)
let isLightBackground = backgroundColor.isLightColor
let newColor = isLightBackground ? backgroundColor.shadow(withLevel: 0.1) : backgroundColor.shadow(withLevel: 0.4)
return Color(nsColor: newColor ?? .gray.withAlphaComponent(0.5))
}
} }
} }

View File

@ -280,6 +280,8 @@ extension Ghostty {
/// This represents a split view that is in the horizontal or vertical split state. /// This represents a split view that is in the horizontal or vertical split state.
private struct TerminalSplitContainer: View { private struct TerminalSplitContainer: View {
@EnvironmentObject var ghostty: Ghostty.App
let neighbors: SplitNode.Neighbors let neighbors: SplitNode.Neighbors
@Binding var node: SplitNode? @Binding var node: SplitNode?
@StateObject var container: SplitNode.Container @StateObject var container: SplitNode.Container
@ -288,6 +290,7 @@ extension Ghostty {
SplitView( SplitView(
container.direction, container.direction,
$container.split, $container.split,
dividerColor: ghostty.config.splitDividerColor,
resizeIncrements: .init(width: 1, height: 1), resizeIncrements: .init(width: 1, height: 1),
resizePublisher: container.resizeEvent, resizePublisher: container.resizeEvent,
left: { left: {

View File

@ -6,6 +6,8 @@ import GhosttyKit
extension Ghostty { extension Ghostty {
/// InspectableSurface is a type of Surface view that allows an inspector to be attached. /// InspectableSurface is a type of Surface view that allows an inspector to be attached.
struct InspectableSurface: View { struct InspectableSurface: View {
@EnvironmentObject var ghostty: Ghostty.App
/// Same as SurfaceWrapper, see the doc comments there. /// Same as SurfaceWrapper, see the doc comments there.
@ObservedObject var surfaceView: SurfaceView @ObservedObject var surfaceView: SurfaceView
var isSplit: Bool = false var isSplit: Bool = false
@ -24,7 +26,7 @@ extension Ghostty {
if (!surfaceView.inspectorVisible) { if (!surfaceView.inspectorVisible) {
SurfaceWrapper(surfaceView: surfaceView, isSplit: isSplit) SurfaceWrapper(surfaceView: surfaceView, isSplit: isSplit)
} else { } else {
SplitView(.vertical, $split, left: { SplitView(.vertical, $split, dividerColor: ghostty.config.splitDividerColor, left: {
SurfaceWrapper(surfaceView: surfaceView, isSplit: isSplit) SurfaceWrapper(surfaceView: surfaceView, isSplit: isSplit)
}, right: { }, right: {
InspectorViewRepresentable(surfaceView: surfaceView) InspectorViewRepresentable(surfaceView: surfaceView)

View File

@ -3,11 +3,10 @@ import SwiftUI
extension SplitView { extension SplitView {
/// The split divider that is rendered and can be used to resize a split view. /// The split divider that is rendered and can be used to resize a split view.
struct Divider: View { struct Divider: View {
@EnvironmentObject var ghostty: Ghostty.App
let direction: SplitViewDirection let direction: SplitViewDirection
let visibleSize: CGFloat let visibleSize: CGFloat
let invisibleSize: CGFloat let invisibleSize: CGFloat
let color: Color
private var visibleWidth: CGFloat? { private var visibleWidth: CGFloat? {
switch (direction) { switch (direction) {
@ -45,14 +44,6 @@ extension SplitView {
} }
} }
private var color: Color {
let backgroundColor = NSColor(ghostty.config.backgroundColor)
let isLightBackground = backgroundColor.isLightColor
let newColor = isLightBackground ? backgroundColor.shadow(withLevel: 0.1) : backgroundColor.shadow(withLevel: 0.4)
return Color(nsColor: newColor ?? .gray.withAlphaComponent(0.5))
}
var body: some View { var body: some View {
ZStack { ZStack {
Color.clear Color.clear

View File

@ -10,6 +10,9 @@ struct SplitView<L: View, R: View>: View {
/// Direction of the split /// Direction of the split
let direction: SplitViewDirection let direction: SplitViewDirection
/// Divider color
let dividerColor: Color
/// If set, the split view supports programmatic resizing via events sent via the publisher. /// If set, the split view supports programmatic resizing via events sent via the publisher.
/// Minimum increment (in points) that this split can be resized by, in /// Minimum increment (in points) that this split can be resized by, in
/// each direction. Both `height` and `width` should be whole numbers /// each direction. Both `height` and `width` should be whole numbers
@ -45,7 +48,10 @@ struct SplitView<L: View, R: View>: View {
right right
.frame(width: rightRect.size.width, height: rightRect.size.height) .frame(width: rightRect.size.width, height: rightRect.size.height)
.offset(x: rightRect.origin.x, y: rightRect.origin.y) .offset(x: rightRect.origin.x, y: rightRect.origin.y)
Divider(direction: direction, visibleSize: splitterVisibleSize, invisibleSize: splitterInvisibleSize) Divider(direction: direction,
visibleSize: splitterVisibleSize,
invisibleSize: splitterInvisibleSize,
color: dividerColor)
.position(splitterPoint) .position(splitterPoint)
.gesture(dragGesture(geo.size, splitterPoint: splitterPoint)) .gesture(dragGesture(geo.size, splitterPoint: splitterPoint))
} }
@ -57,10 +63,15 @@ struct SplitView<L: View, R: View>: View {
/// Initialize a split view. This view isn't programmatically resizable; it can only be resized /// Initialize a split view. This view isn't programmatically resizable; it can only be resized
/// by manually dragging the divider. /// by manually dragging the divider.
init(_ direction: SplitViewDirection, _ split: Binding<CGFloat>, @ViewBuilder left: (() -> L), @ViewBuilder right: (() -> R)) { init(_ direction: SplitViewDirection,
_ split: Binding<CGFloat>,
dividerColor: Color,
@ViewBuilder left: (() -> L),
@ViewBuilder right: (() -> R)) {
self.init( self.init(
direction, direction,
split, split,
dividerColor: dividerColor,
resizeIncrements: .init(width: 1, height: 1), resizeIncrements: .init(width: 1, height: 1),
resizePublisher: .init(), resizePublisher: .init(),
left: left, left: left,
@ -72,6 +83,7 @@ struct SplitView<L: View, R: View>: View {
init( init(
_ direction: SplitViewDirection, _ direction: SplitViewDirection,
_ split: Binding<CGFloat>, _ split: Binding<CGFloat>,
dividerColor: Color,
resizeIncrements: NSSize, resizeIncrements: NSSize,
resizePublisher: PassthroughSubject<Double, Never>, resizePublisher: PassthroughSubject<Double, Never>,
@ViewBuilder left: (() -> L), @ViewBuilder left: (() -> L),
@ -79,6 +91,7 @@ struct SplitView<L: View, R: View>: View {
) { ) {
self.direction = direction self.direction = direction
self._split = split self._split = split
self.dividerColor = dividerColor
self.resizeIncrements = resizeIncrements self.resizeIncrements = resizeIncrements
self.resizePublisher = resizePublisher self.resizePublisher = resizePublisher
self.left = left() self.left = left()