GetHeightRequiredForSubViews dose not return what I expect #5672
|
I have a View with several labels. Every Label has the Bottom of the previous element as top. I use this local Helper Function for it: this.ViewportSettings |= ViewportSettingsFlags.HasScrollBars;
View? lastElement = null;
void Add(View view, int? spacing = null)
{
if (lastElement == null)
{
view.Y = Pos.Absolute(spacing ?? 0);
}
else
{
view.Y = Pos.Bottom(lastElement) + (spacing ?? 0);
}
view.X = Pos.Absolute(0);
view.Width = Dim.Fill();
this.Add(view);
lastElement = view;
}My assumption was that if I call I appreciate any help :) |
Replies: 1 comment 1 reply
|
By default
After you int y = 0;
foreach (var sub in this.SubViews)
{
// after Layout(), sub.Frame.Height is real
y = Math.Max(y, sub.Frame.Y + sub.Frame.Height);
}
this.SetContentSize(new Size(this.GetContentSize().Width, y));
this.ViewportSettings |= ViewportSettingsFlags.HasVerticalScrollBar;Or give the container |

GetHeightRequiredForSubViews()is returning the viewport on purpose in your setup, not the stacked labels.By default
ContentSizeTracksViewportis true, so content size == visible size.HasScrollBarsonly shows bars when content is larger than the viewport. If you never callSetContentSize, there is nothing to scroll, and the helper that feeds on auto-height / content size collapses to the viewport.Pos.Bottom(lastElement)also does not give those labels a height until layout has run. Calling the helper before the first layout pass will not sumDim.Fill()children (Fill does not contribute to auto height unless you give aminimumContentDim).After you
Addthe labels, compute a content siz…