Skip to content

Commit fffebb0

Browse files
committed
fix: compute ToolbarControl.ContentWidth from items instead of returning null
1 parent faff3d1 commit fffebb0

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

SharpConsoleUI/Controls/ToolbarControl.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,26 @@ public ToolbarControl()
5151
}
5252

5353
/// <inheritdoc/>
54-
public override int? ContentWidth => Width;
54+
public override int? ContentWidth => Width ?? ComputeContentWidth();
55+
56+
private int? ComputeContentWidth()
57+
{
58+
if (_items.Count == 0) return null;
59+
int total = 0;
60+
foreach (var item in _items)
61+
{
62+
if (item is ButtonControl btn)
63+
total += btn.ContentWidth ?? 0;
64+
else if (item is SeparatorControl)
65+
total += 1;
66+
else
67+
total += item.ContentWidth ?? item.Width ?? 0;
68+
}
69+
total += Math.Max(0, _items.Count - 1) * ItemSpacing;
70+
total += _contentPadding.Left + _contentPadding.Right;
71+
total += Margin.Left + Margin.Right;
72+
return total;
73+
}
5574

5675
/// <summary>
5776
/// Gets or sets the background color of the toolbar.

0 commit comments

Comments
 (0)