forked from CodebuffAI/codebuff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayout-helpers.ts
More file actions
33 lines (26 loc) · 1.2 KB
/
Copy pathlayout-helpers.ts
File metadata and controls
33 lines (26 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/** Minimum width (in characters) for a grid column */
export const MIN_COLUMN_WIDTH = 10
/** Maximum nesting depth for agent blocks */
export const MAX_AGENT_DEPTH = 10
/** Horizontal padding (in characters) inside agent content boxes */
export const AGENT_CONTENT_HORIZONTAL_PADDING = 12
/**
* Compute the ideal number of columns for a grid layout.
* Tries to create a balanced grid (e.g. 2x2 instead of 3x1 + 1) while respecting max columns.
*/
export function computeSmartColumns(itemCount: number, maxColumns: number): number {
if (itemCount === 0) return 1
if (itemCount <= maxColumns) return itemCount
// If we can make a perfect grid with maxColumns, do it
if (itemCount % maxColumns === 0) return maxColumns
// Special case for 4 items on a 3-column screen: prefer 2x2 over 3+1
if (itemCount === 4 && maxColumns === 3) return 2
// Iterate down from maxColumns to find a divisor or better balance
// We prioritize using more columns (larger width) over perfect balance, unless it's very egregious
for (let c = maxColumns; c >= 2; c--) {
// If perfect match (divisor)
if (itemCount % c === 0) return c
}
// Default to max columns if no nice divisor found
return maxColumns
}