mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: plumb through the split divider color
This commit is contained in:
@ -258,5 +258,14 @@ extension Ghostty {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -280,6 +280,8 @@ extension Ghostty {
|
||||
|
||||
/// This represents a split view that is in the horizontal or vertical split state.
|
||||
private struct TerminalSplitContainer: View {
|
||||
@EnvironmentObject var ghostty: Ghostty.App
|
||||
|
||||
let neighbors: SplitNode.Neighbors
|
||||
@Binding var node: SplitNode?
|
||||
@StateObject var container: SplitNode.Container
|
||||
@ -288,6 +290,7 @@ extension Ghostty {
|
||||
SplitView(
|
||||
container.direction,
|
||||
$container.split,
|
||||
dividerColor: ghostty.config.splitDividerColor,
|
||||
resizeIncrements: .init(width: 1, height: 1),
|
||||
resizePublisher: container.resizeEvent,
|
||||
left: {
|
||||
|
@ -6,6 +6,8 @@ import GhosttyKit
|
||||
extension Ghostty {
|
||||
/// InspectableSurface is a type of Surface view that allows an inspector to be attached.
|
||||
struct InspectableSurface: View {
|
||||
@EnvironmentObject var ghostty: Ghostty.App
|
||||
|
||||
/// Same as SurfaceWrapper, see the doc comments there.
|
||||
@ObservedObject var surfaceView: SurfaceView
|
||||
var isSplit: Bool = false
|
||||
@ -24,7 +26,7 @@ extension Ghostty {
|
||||
if (!surfaceView.inspectorVisible) {
|
||||
SurfaceWrapper(surfaceView: surfaceView, isSplit: isSplit)
|
||||
} else {
|
||||
SplitView(.vertical, $split, left: {
|
||||
SplitView(.vertical, $split, dividerColor: ghostty.config.splitDividerColor, left: {
|
||||
SurfaceWrapper(surfaceView: surfaceView, isSplit: isSplit)
|
||||
}, right: {
|
||||
InspectorViewRepresentable(surfaceView: surfaceView)
|
||||
|
@ -3,11 +3,10 @@ import SwiftUI
|
||||
extension SplitView {
|
||||
/// The split divider that is rendered and can be used to resize a split view.
|
||||
struct Divider: View {
|
||||
@EnvironmentObject var ghostty: Ghostty.App
|
||||
|
||||
let direction: SplitViewDirection
|
||||
let visibleSize: CGFloat
|
||||
let invisibleSize: CGFloat
|
||||
let color: Color
|
||||
|
||||
private var visibleWidth: CGFloat? {
|
||||
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 {
|
||||
ZStack {
|
||||
Color.clear
|
||||
|
@ -10,6 +10,9 @@ struct SplitView<L: View, R: View>: View {
|
||||
/// Direction of the split
|
||||
let direction: SplitViewDirection
|
||||
|
||||
/// Divider color
|
||||
let dividerColor: Color
|
||||
|
||||
/// 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
|
||||
/// each direction. Both `height` and `width` should be whole numbers
|
||||
@ -45,7 +48,10 @@ struct SplitView<L: View, R: View>: View {
|
||||
right
|
||||
.frame(width: rightRect.size.width, height: rightRect.size.height)
|
||||
.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)
|
||||
.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
|
||||
/// 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(
|
||||
direction,
|
||||
split,
|
||||
dividerColor: dividerColor,
|
||||
resizeIncrements: .init(width: 1, height: 1),
|
||||
resizePublisher: .init(),
|
||||
left: left,
|
||||
@ -72,6 +83,7 @@ struct SplitView<L: View, R: View>: View {
|
||||
init(
|
||||
_ direction: SplitViewDirection,
|
||||
_ split: Binding<CGFloat>,
|
||||
dividerColor: Color,
|
||||
resizeIncrements: NSSize,
|
||||
resizePublisher: PassthroughSubject<Double, Never>,
|
||||
@ViewBuilder left: (() -> L),
|
||||
@ -79,6 +91,7 @@ struct SplitView<L: View, R: View>: View {
|
||||
) {
|
||||
self.direction = direction
|
||||
self._split = split
|
||||
self.dividerColor = dividerColor
|
||||
self.resizeIncrements = resizeIncrements
|
||||
self.resizePublisher = resizePublisher
|
||||
self.left = left()
|
||||
|
Reference in New Issue
Block a user