Skip to content

Commit 2b1619a

Browse files
s202283440s202283440
authored andcommitted
bars are bigger
tree nodes are autosized with minimum size
1 parent 47a23dc commit 2b1619a

2 files changed

Lines changed: 22 additions & 15 deletions

File tree

FileSystem/barchart_strategy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ private void CollectItems(Folder folder)
5454

5555
private void DrawBar(string name, long size, bool isFolder, Panel panel)
5656
{
57-
int maxBarWidth = panel.Width - 250;
57+
int maxBarWidth = panel.Width -50;
5858
if (maxBarWidth < 200) maxBarWidth = 400;
5959

6060
int barWidth = maxSize > 0 ? (int)((size * maxBarWidth) / maxSize) : 0;
61-
if (barWidth < 50) barWidth = 50;
61+
//if (barWidth < 50) barWidth = 50;
6262

6363
string sizeText = FormatSize(size);
6464
string labelText = $"({sizeText}) {name}";

FileSystem/tree_strategy.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ private void DrawFolderTree(Folder folder, Panel panel, int x, int level)
2626
{
2727
Text = folder.Name,
2828
Location = new Point(x + (level * INDENT), currentY),
29-
Size = new Size(120, 20),
29+
MinimumSize = new Size(120, 20),
30+
AutoSize = true,
3031
BorderStyle = BorderStyle.FixedSingle,
3132
BackColor = Color.White,
3233
TextAlign = ContentAlignment.MiddleCenter
@@ -54,11 +55,11 @@ private void DrawFolderTree(Folder folder, Panel panel, int x, int level)
5455
// Draw connecting line from parent to file
5556
DrawLine(panel, x + (level * INDENT) + 60, folderY + 10,
5657
x + ((level + 1) * INDENT) + 60, currentY + 10);
57-
58-
DrawFile(file, panel, x + ((level + 1) * INDENT), currentY);
58+
DrawFile(file, panel, x + ((level + 1) * INDENT) + 20 , currentY );
5959
currentY += LINE_HEIGHT;
6060
}
6161
}
62+
folderLabel.BringToFront();
6263
}
6364

6465
private void DrawFile(File file, Panel panel, int x, int y)
@@ -67,12 +68,14 @@ private void DrawFile(File file, Panel panel, int x, int y)
6768
{
6869
Text = file.Name,
6970
Location = new Point(x, y),
70-
Size = new Size(80, 20),
71+
MinimumSize = new Size(80, 20),
72+
AutoSize = true,
7173
BorderStyle = BorderStyle.FixedSingle,
7274
BackColor = Color.LightBlue,
7375
TextAlign = ContentAlignment.MiddleCenter
7476
};
7577
panel.Controls.Add(fileLabel);
78+
fileLabel.BringToFront();
7679
}
7780

7881
private void DrawLine(Panel panel, int x1, int y1, int x2, int y2)
@@ -95,26 +98,30 @@ private void DrawLine(Panel panel, int x1, int y1, int x2, int y2)
9598
}
9699
else
97100
{
98-
// Diagonal line approximation with horizontal + vertical
99-
Panel hLine = new Panel
101+
// L-shape: vertical first, then horizontal (down then right)
102+
// Vertical from (x1, y1) to (x1, y2)
103+
Panel vLine = new Panel
100104
{
101105
BackColor = Color.Black,
102-
Location = new Point(x1, y1),
103-
Size = new Size(Math.Abs(x2 - x1), 2)
106+
Location = new Point(x1, Math.Min(y1, y2)),
107+
Size = new Size(2, Math.Abs(y2 - y1))
104108
};
105-
panel.Controls.Add(hLine);
109+
panel.Controls.Add(vLine);
106110

107-
Panel vLine = new Panel
111+
// Horizontal from (x1, y2) to (x2, y2)
112+
Panel hLine = new Panel
108113
{
109114
BackColor = Color.Black,
110-
Location = new Point(x2, Math.Min(y1, y2)),
111-
Size = new Size(2, Math.Abs(y2 - y1))
115+
Location = new Point(Math.Min(x1, x2), y2),
116+
Size = new Size(Math.Abs(x2 - x1), 2)
112117
};
113-
panel.Controls.Add(vLine);
118+
panel.Controls.Add(hLine);
119+
114120
return;
115121
}
116122

117123
panel.Controls.Add(line);
118124
}
125+
119126
}
120127
}

0 commit comments

Comments
 (0)