Bottom-to-Top Stacking
Introduction
Creating the Layout


Last updated
Was this helpful?


Last updated
Was this helpful?
Was this helpful?
ScrollViewer scrollViewer;
protected override void Initialize()
{
GumUI.Initialize(this, Gum.Forms.DefaultVisualsVersion.Newest);
var panel = new StackPanel();
panel.AddToRoot();
panel.Anchor(Anchor.Center);
// wrapped ScrollViewer
scrollViewer = new ScrollViewer();
panel.AddChild(scrollViewer);
scrollViewer.Width = 400;
var innerPanel = scrollViewer.GetVisual("InnerPanelInstance");
var bottomAlignedContainer = new ContainerRuntime();
innerPanel.AddChild(bottomAlignedContainer);
bottomAlignedContainer.Dock(Dock.Bottom);
bottomAlignedContainer.Height = 0;
bottomAlignedContainer.HeightUnits = DimensionUnitType.RelativeToChildren;
bottomAlignedContainer.ChildrenLayout = ChildrenLayout.TopToBottomStack;
var button = new Button();
panel.AddChild(button);
button.Text = "Add Label";
button.Click += (sender, args) =>
{
var label = new Label();
bottomAlignedContainer.AddChild(label);
label.Text = $"Added at " + DateTime.Now.ToString("hh:mm:ss.ff");
FillAndExpandVertically(innerPanel);
scrollViewer.ScrollToBottom();
};
}
void FillAndExpandVertically(GraphicalUiElement visual)
{
// let it expand...
visual.HeightUnits = DimensionUnitType.RelativeToChildren;
// then measure:
if(visual.GetAbsoluteHeight() > visual.Parent.GetAbsoluteHeight())
{
visual.HeightUnits = DimensionUnitType.RelativeToChildren;
}
else
{
visual.HeightUnits = DimensionUnitType.RelativeToParent;
}
}