-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathTallLayoutEngine.cs
More file actions
105 lines (86 loc) · 3.27 KB
/
TallLayoutEngine.cs
File metadata and controls
105 lines (86 loc) · 3.27 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Collections.Generic;
using System.Linq;
namespace workspacer
{
public class TallLayoutEngine : ILayoutEngine
{
private readonly int _numInPrimary;
private readonly double _primaryPercent;
private readonly double _primaryPercentIncrement;
private readonly bool _leftToRight;
private int _numInPrimaryOffset = 0;
private double _primaryPercentOffset = 0;
public TallLayoutEngine(bool reversed = false) : this(1, 0.5, 0.03, reversed) { }
public TallLayoutEngine(int numInPrimary, double primaryPercent, double primaryPercentIncrement, bool reversed)
{
_numInPrimary = numInPrimary;
_primaryPercent = primaryPercent;
_primaryPercentIncrement = primaryPercentIncrement;
_leftToRight = !reversed;
}
public string Name { get; set; } = "tall";
public IEnumerable<IWindowLocation> CalcLayout(IEnumerable<IWindow> windows, int spaceWidth, int spaceHeight)
{
var list = new List<IWindowLocation>();
var numWindows = windows.Count();
if (numWindows == 0)
return list;
int numInPrimary = Math.Min(GetNumInPrimary(), numWindows);
int primaryWidth = (int)(spaceWidth * (_primaryPercent + _primaryPercentOffset));
int primaryHeight = spaceHeight / numInPrimary;
int height = spaceHeight / Math.Max(numWindows - numInPrimary, 1);
// if there are more "primary" windows than actual windows,
// then we want the pane to actually spread the entire width
// of the working area
if (numInPrimary >= numWindows)
{
primaryWidth = spaceWidth;
}
int secondaryWidth = spaceWidth - primaryWidth;
for (var i = 0; i < numWindows; i++)
{
if (i < numInPrimary)
{
list.Add(new WindowLocation(CalcXPos(0, primaryWidth, spaceWidth), i * primaryHeight, primaryWidth, primaryHeight, WindowState.Normal));
}
else
{
list.Add(new WindowLocation(CalcXPos(primaryWidth, secondaryWidth, spaceWidth), (i - numInPrimary) * height, secondaryWidth, height, WindowState.Normal));
}
}
return list;
}
public void ShrinkPrimaryArea()
{
_primaryPercentOffset -= _primaryPercentIncrement;
}
public void ExpandPrimaryArea()
{
_primaryPercentOffset += _primaryPercentIncrement;
}
public void ResetPrimaryArea()
{
_primaryPercentOffset = 0;
}
public void IncrementNumInPrimary()
{
_numInPrimaryOffset++;
}
public void DecrementNumInPrimary()
{
if (GetNumInPrimary() > 1)
{
_numInPrimaryOffset--;
}
}
private int GetNumInPrimary()
{
return _numInPrimary + _numInPrimaryOffset;
}
private int CalcXPos(int x, int windowsWidth, int spaceWidth)
{
return _leftToRight ? x : spaceWidth - x - windowsWidth;
}
}
}