Skip to content

Commit 5767189

Browse files
committed
Add Height property to ScrollablePanelControl
1 parent 582e3f3 commit 5767189

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

SharpConsoleUI/Builders/ScrollablePanelBuilder.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public sealed class ScrollablePanelBuilder
3737
private Margin _margin = new(0, 0, 0, 0);
3838
private bool _visible = true;
3939
private int? _width;
40+
private int? _height;
4041
private string? _name;
4142
private object? _tag;
4243
private StickyPosition _stickyPosition = StickyPosition.None;
@@ -255,6 +256,17 @@ public ScrollablePanelBuilder WithWidth(int width)
255256
return this;
256257
}
257258

259+
/// <summary>
260+
/// Sets the height
261+
/// </summary>
262+
/// <param name="height">The height</param>
263+
/// <returns>The builder for chaining</returns>
264+
public ScrollablePanelBuilder WithHeight(int height)
265+
{
266+
_height = height;
267+
return this;
268+
}
269+
258270
/// <summary>
259271
/// Sets the control name for FindControl queries
260272
/// </summary>
@@ -362,6 +374,7 @@ public ScrollablePanelControl Build()
362374
Margin = _margin,
363375
Visible = _visible,
364376
Width = _width,
377+
Height = _height,
365378
Name = _name,
366379
Tag = _tag,
367380
StickyPosition = _stickyPosition,

SharpConsoleUI/Controls/ScrollablePanelControl.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public class ScrollablePanelControl : IWindowControl, IInteractiveControl, IFocu
6161
private StickyPosition _stickyPosition = StickyPosition.None;
6262
private bool _visible = true;
6363
private int? _width;
64+
private int? _height;
6465

6566
// IContainer properties
6667
private Color _backgroundColor = Color.Black;
@@ -207,7 +208,7 @@ public bool AutoScroll
207208
#region IWindowControl Implementation
208209

209210
/// <inheritdoc/>
210-
public int? ContentHeight => null; // Fill available space
211+
public int? ContentHeight => _height;
211212

212213
/// <inheritdoc/>
213214
public int? ContentWidth => _width;
@@ -289,6 +290,13 @@ public int? Width
289290
set { _width = value; Container?.Invalidate(true); }
290291
}
291292

293+
/// <inheritdoc/>
294+
public int? Height
295+
{
296+
get => _height;
297+
set => PropertySetterHelper.SetDimensionProperty(ref _height, value, Container);
298+
}
299+
292300
/// <inheritdoc/>
293301
public System.Drawing.Size GetLogicalContentSize()
294302
{
@@ -1137,12 +1145,23 @@ public LayoutSize MeasureDOM(LayoutConstraints constraints)
11371145
int width = _width ?? constraints.MaxWidth;
11381146
int availableWidth = Math.Max(1, width - _margin.Left - _margin.Right);
11391147

1140-
// Pass the actual available width to CalculateContentHeight
1141-
int height = CalculateContentHeight(availableWidth);
1148+
// Determine height
1149+
int height;
1150+
if (_height.HasValue)
1151+
{
1152+
// Explicit height set - use it directly
1153+
height = _height.Value;
1154+
}
1155+
else
1156+
{
1157+
// No explicit height - calculate from content
1158+
int contentHeight = CalculateContentHeight(availableWidth);
1159+
height = contentHeight + _margin.Top + _margin.Bottom;
1160+
}
11421161

11431162
return new LayoutSize(
11441163
Math.Clamp(width + _margin.Left + _margin.Right, constraints.MinWidth, constraints.MaxWidth),
1145-
Math.Clamp(height + _margin.Top + _margin.Bottom, constraints.MinHeight, constraints.MaxHeight)
1164+
Math.Clamp(height, constraints.MinHeight, constraints.MaxHeight)
11461165
);
11471166
}
11481167

0 commit comments

Comments
 (0)