restores Helder in all its glory
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import Foundation
|
||||
|
||||
/// Which side of the window has focus; drives the fluid widths below 1600pt.
|
||||
public enum FocusZone: String, Sendable, Equatable {
|
||||
case neutral
|
||||
case editor
|
||||
case terminal
|
||||
}
|
||||
|
||||
/// Pixel widths of the three fixed columns; the editor takes the remainder.
|
||||
public struct ColumnWidths: Sendable, Equatable {
|
||||
public var sourceControl: Double
|
||||
public var explorer: Double
|
||||
public var agent: Double
|
||||
|
||||
public init(sourceControl: Double, explorer: Double, agent: Double) {
|
||||
self.sourceControl = sourceControl
|
||||
self.explorer = explorer
|
||||
self.agent = agent
|
||||
}
|
||||
}
|
||||
|
||||
public enum ColumnLayout {
|
||||
/// At and above this width every column fits and focus changes nothing.
|
||||
public static let roomyWidth = 1600.0
|
||||
public static let minEditorWidth = 280.0
|
||||
public static let splitterWidth = 1.0
|
||||
public static let sourceControlRange = 160.0...460.0
|
||||
public static let explorerRange = 160.0...520.0
|
||||
|
||||
/// Fluid widths for a window. Roomy: 13.4% · 16.4% · flex · 27.3% (the design's
|
||||
/// 236 · 288 · flex · 480 on a 1760 frame). Tight: 15% · 15%, and the agent column
|
||||
/// takes 30%, or 20% with the editor focused, or 50% with a terminal focused.
|
||||
public static func fluid(windowWidth w: Double, focus: FocusZone) -> ColumnWidths {
|
||||
if w >= roomyWidth {
|
||||
return ColumnWidths(sourceControl: (w * 0.134).rounded(), explorer: (w * 0.164).rounded(), agent: (w * 0.273).rounded())
|
||||
}
|
||||
let agentShare = focus == .terminal ? 0.5 : focus == .editor ? 0.2 : 0.3
|
||||
return ColumnWidths(sourceControl: (w * 0.15).rounded(), explorer: (w * 0.15).rounded(), agent: (w * agentShare).rounded())
|
||||
}
|
||||
|
||||
/// Scales the fixed columns down so the editor keeps `minEditorWidth`; unchanged when they fit.
|
||||
public static func fitted(_ widths: ColumnWidths, windowWidth: Double, sourceControlVisible: Bool) -> ColumnWidths {
|
||||
let splitters = (sourceControlVisible ? 3.0 : 2.0) * splitterWidth
|
||||
let budget = windowWidth - splitters - minEditorWidth
|
||||
let total = (sourceControlVisible ? widths.sourceControl : 0) + widths.explorer + widths.agent
|
||||
guard total > budget, total > 0 else { return widths }
|
||||
let k = max(0, budget) / total
|
||||
return ColumnWidths(
|
||||
sourceControl: sourceControlVisible ? (widths.sourceControl * k).rounded(.down) : widths.sourceControl,
|
||||
explorer: (widths.explorer * k).rounded(.down),
|
||||
agent: (widths.agent * k).rounded(.down)
|
||||
)
|
||||
}
|
||||
|
||||
/// The widest the agent column may be dragged: until the editor would drop below its minimum.
|
||||
public static func maxAgentWidth(windowWidth: Double, widths: ColumnWidths, sourceControlVisible: Bool) -> Double {
|
||||
let splitters = (sourceControlVisible ? 3.0 : 2.0) * splitterWidth
|
||||
let others = (sourceControlVisible ? widths.sourceControl : 0) + widths.explorer
|
||||
return max(minEditorWidth, windowWidth - splitters - others - minEditorWidth)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user