mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 00:36:07 +03:00
Merge pull request #834 from gpanders/split-binding
macos: pass split as a binding to SplitView
This commit is contained in:
@ -123,6 +123,7 @@ extension Ghostty {
|
|||||||
|
|
||||||
@Published var topLeft: SplitNode
|
@Published var topLeft: SplitNode
|
||||||
@Published var bottomRight: SplitNode
|
@Published var bottomRight: SplitNode
|
||||||
|
@Published var split: CGFloat = 0.5
|
||||||
|
|
||||||
var resizeEvent: PassthroughSubject<Double, Never> = .init()
|
var resizeEvent: PassthroughSubject<Double, Never> = .init()
|
||||||
|
|
||||||
|
@ -270,6 +270,7 @@ extension Ghostty {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
SplitView(
|
SplitView(
|
||||||
container.direction,
|
container.direction,
|
||||||
|
$container.split,
|
||||||
resizeIncrements: .init(width: 1, height: 1),
|
resizeIncrements: .init(width: 1, height: 1),
|
||||||
resizePublisher: container.resizeEvent,
|
resizePublisher: container.resizeEvent,
|
||||||
left: {
|
left: {
|
||||||
|
@ -12,7 +12,10 @@ extension Ghostty {
|
|||||||
|
|
||||||
// Maintain whether our view has focus or not
|
// Maintain whether our view has focus or not
|
||||||
@FocusState private var inspectorFocus: Bool
|
@FocusState private var inspectorFocus: Bool
|
||||||
|
|
||||||
|
// The fractional area of the surface view vs. the inspector (0.5 means a 50/50 split)
|
||||||
|
@State private var split: CGFloat = 0.5
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
let center = NotificationCenter.default
|
let center = NotificationCenter.default
|
||||||
let pubInspector = center.publisher(for: Notification.didControlInspector, object: surfaceView)
|
let pubInspector = center.publisher(for: Notification.didControlInspector, object: surfaceView)
|
||||||
@ -21,7 +24,7 @@ extension Ghostty {
|
|||||||
if (!surfaceView.inspectorVisible) {
|
if (!surfaceView.inspectorVisible) {
|
||||||
SurfaceWrapper(surfaceView: surfaceView, isSplit: isSplit)
|
SurfaceWrapper(surfaceView: surfaceView, isSplit: isSplit)
|
||||||
} else {
|
} else {
|
||||||
SplitView(.vertical, left: {
|
SplitView(.vertical, $split, left: {
|
||||||
SurfaceWrapper(surfaceView: surfaceView, isSplit: isSplit)
|
SurfaceWrapper(surfaceView: surfaceView, isSplit: isSplit)
|
||||||
}, right: {
|
}, right: {
|
||||||
InspectorViewRepresentable(surfaceView: surfaceView)
|
InspectorViewRepresentable(surfaceView: surfaceView)
|
||||||
|
@ -22,7 +22,7 @@ struct SplitView<L: View, R: View>: View {
|
|||||||
let right: R
|
let right: R
|
||||||
|
|
||||||
/// The current fractional width of the split view. 0.5 means L/R are equally sized, for example.
|
/// The current fractional width of the split view. 0.5 means L/R are equally sized, for example.
|
||||||
@State var split: CGFloat = 0.5
|
@Binding var split: CGFloat
|
||||||
|
|
||||||
/// The visible size of the splitter, in points. The invisible size is a transparent hitbox that can still
|
/// The visible size of the splitter, in points. The invisible size is a transparent hitbox that can still
|
||||||
/// be used for getting a resize handle. The total width/height of the splitter is the sum of both.
|
/// be used for getting a resize handle. The total width/height of the splitter is the sum of both.
|
||||||
@ -54,9 +54,10 @@ 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, @ViewBuilder left: (() -> L), @ViewBuilder right: (() -> R)) {
|
init(_ direction: SplitViewDirection, _ split: Binding<CGFloat>, @ViewBuilder left: (() -> L), @ViewBuilder right: (() -> R)) {
|
||||||
self.init(
|
self.init(
|
||||||
direction,
|
direction,
|
||||||
|
split,
|
||||||
resizeIncrements: .init(width: 1, height: 1),
|
resizeIncrements: .init(width: 1, height: 1),
|
||||||
resizePublisher: .init(),
|
resizePublisher: .init(),
|
||||||
left: left,
|
left: left,
|
||||||
@ -67,12 +68,14 @@ struct SplitView<L: View, R: View>: View {
|
|||||||
/// Initialize a split view that supports programmatic resizing.
|
/// Initialize a split view that supports programmatic resizing.
|
||||||
init(
|
init(
|
||||||
_ direction: SplitViewDirection,
|
_ direction: SplitViewDirection,
|
||||||
|
_ split: Binding<CGFloat>,
|
||||||
resizeIncrements: NSSize,
|
resizeIncrements: NSSize,
|
||||||
resizePublisher: PassthroughSubject<Double, Never>,
|
resizePublisher: PassthroughSubject<Double, Never>,
|
||||||
@ViewBuilder left: (() -> L),
|
@ViewBuilder left: (() -> L),
|
||||||
@ViewBuilder right: (() -> R)
|
@ViewBuilder right: (() -> R)
|
||||||
) {
|
) {
|
||||||
self.direction = direction
|
self.direction = direction
|
||||||
|
self._split = split
|
||||||
self.resizeIncrements = resizeIncrements
|
self.resizeIncrements = resizeIncrements
|
||||||
self.resizePublisher = resizePublisher
|
self.resizePublisher = resizePublisher
|
||||||
self.left = left()
|
self.left = left()
|
||||||
|
Reference in New Issue
Block a user