Improves helder
This commit is contained in:
@@ -39,24 +39,48 @@ public enum ColumnLayout {
|
||||
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
|
||||
/// Scales the fixed columns down so the flex column keeps `minEditorWidth`; unchanged when they fit.
|
||||
/// Hidden columns keep their width for when they come back.
|
||||
public static func fitted(_ widths: ColumnWidths, windowWidth: Double, visible: ColumnVisibility) -> ColumnWidths {
|
||||
let agentIsFixed = visible.agent && visible.editor
|
||||
let flexMinimum = visible.editor || visible.agent ? minEditorWidth : 0
|
||||
let budget = windowWidth - Double(visible.splitterCount) * splitterWidth - flexMinimum
|
||||
let total = (visible.sourceControl ? widths.sourceControl : 0) + (visible.explorer ? widths.explorer : 0)
|
||||
+ (agentIsFixed ? widths.agent : 0)
|
||||
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)
|
||||
sourceControl: visible.sourceControl ? (widths.sourceControl * k).rounded(.down) : widths.sourceControl,
|
||||
explorer: visible.explorer ? (widths.explorer * k).rounded(.down) : widths.explorer,
|
||||
agent: agentIsFixed ? (widths.agent * k).rounded(.down) : widths.agent
|
||||
)
|
||||
}
|
||||
|
||||
/// 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)
|
||||
public static func maxAgentWidth(windowWidth: Double, widths: ColumnWidths, visible: ColumnVisibility) -> Double {
|
||||
let others = (visible.sourceControl ? widths.sourceControl : 0) + (visible.explorer ? widths.explorer : 0)
|
||||
return max(minEditorWidth, windowWidth - Double(visible.splitterCount) * splitterWidth - others - minEditorWidth)
|
||||
}
|
||||
}
|
||||
|
||||
/// Which of the four columns are shown. A hidden column keeps its width and its contents.
|
||||
public struct ColumnVisibility: Sendable, Equatable {
|
||||
public var sourceControl: Bool
|
||||
public var explorer: Bool
|
||||
public var editor: Bool
|
||||
public var agent: Bool
|
||||
|
||||
public init(sourceControl: Bool = true, explorer: Bool = true, editor: Bool = true, agent: Bool = true) {
|
||||
self.sourceControl = sourceControl
|
||||
self.explorer = explorer
|
||||
self.editor = editor
|
||||
self.agent = agent
|
||||
}
|
||||
|
||||
public static let all = ColumnVisibility()
|
||||
|
||||
/// One splitter between each pair of neighbouring visible columns.
|
||||
public var splitterCount: Int {
|
||||
max(0, [sourceControl, explorer, editor, agent].filter { $0 }.count - 1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user