mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 16:26:08 +03:00
Merge pull request #1304 from gpanders/resize-bounds
macos: respect minimum split size when using resize keys
This commit is contained in:
@ -21,6 +21,9 @@ struct SplitView<L: View, R: View>: View {
|
|||||||
let left: L
|
let left: L
|
||||||
let right: R
|
let right: R
|
||||||
|
|
||||||
|
/// The minimum size (in points) of a split
|
||||||
|
let minSize: CGFloat = 10
|
||||||
|
|
||||||
/// 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.
|
||||||
@Binding var split: CGFloat
|
@Binding var split: CGFloat
|
||||||
|
|
||||||
@ -83,22 +86,22 @@ struct SplitView<L: View, R: View>: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func resize(for size: CGSize, amount: Double) {
|
private func resize(for size: CGSize, amount: Double) {
|
||||||
|
let dim: CGFloat
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case .horizontal:
|
case .horizontal:
|
||||||
split += amount / size.width
|
dim = size.width
|
||||||
case .vertical:
|
case .vertical:
|
||||||
split += amount / size.height
|
dim = size.height
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure split is clamped between 0 and 1
|
let pos = split * dim
|
||||||
split = max(0.0, min(split, 1.0))
|
let new = min(max(minSize, pos + amount), dim - minSize)
|
||||||
|
split = new / dim
|
||||||
}
|
}
|
||||||
|
|
||||||
private func dragGesture(_ size: CGSize, splitterPoint: CGPoint) -> some Gesture {
|
private func dragGesture(_ size: CGSize, splitterPoint: CGPoint) -> some Gesture {
|
||||||
return DragGesture()
|
return DragGesture()
|
||||||
.onChanged { gesture in
|
.onChanged { gesture in
|
||||||
let minSize: CGFloat = 10
|
|
||||||
|
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case .horizontal:
|
case .horizontal:
|
||||||
let new = min(max(minSize, gesture.location.x), size.width - minSize)
|
let new = min(max(minSize, gesture.location.x), size.width - minSize)
|
||||||
|
Reference in New Issue
Block a user