Skip to content

The Panel Dock function doesn't reliably size correctly #14

@luttje

Description

@luttje

The Garry's Mod sandbox spawnmenu seems to work fine, but some menus using Dock(TOP) in experiment-redux are not sized to the correct height.

The problem is likely somewhere here:

/*
** Based on GWEN's Docking system:
** https://github.com/garrynewman/GWEN/blob/ca010e87e3df13749d7a9420918c566f99a28021/gwen/src/Controls/Base.cpp#L704
*/
void Panel::RecurseLayout()
{
// if ( _flags.IsFlagSet( NEEDS_LAYOUT ) )
//{
// InternalPerformLayout();
// }
// Start calculating the dock layout sizes
// Assume 0, 0 as the starting point. True positioning will occur in PostLayout
int wide, tall;
GetSize( wide, tall );
Size renderBounds( 0, 0, wide, tall );
renderBounds.x += m_DockPadding.left;
renderBounds.y += m_DockPadding.top;
renderBounds.wide -= m_DockPadding.left + m_DockPadding.right;
renderBounds.tall -= m_DockPadding.top + m_DockPadding.bottom;
for ( int i = 0; i < GetChildCount(); i++ )
{
Panel *pChild = GetChild( i );
if ( !pChild->IsVisible() )
continue;
Dock::Type dock = pChild->GetDock();
// We'll handle fill after this loop
if ( dock == Dock::Fill )
continue;
if ( dock == Dock::Top )
{
const Thickness margin = pChild->GetDockMargin();
pChild->SetBounds( renderBounds.x + margin.left, renderBounds.y + margin.top, renderBounds.wide - margin.left - margin.right, pChild->GetTall() );
int iHeight = margin.top + pChild->GetTall() + margin.bottom;
renderBounds.y += iHeight;
renderBounds.tall -= iHeight;
}
else if ( dock == Dock::Left )
{
const Thickness margin = pChild->GetDockMargin();
pChild->SetBounds( renderBounds.x + margin.left, renderBounds.y + margin.top, pChild->GetWide(), renderBounds.tall - margin.top - margin.bottom );
int iWidth = margin.left + margin.right + pChild->GetWide();
renderBounds.x += iWidth;
renderBounds.wide -= iWidth;
}
else if ( dock == Dock::Right )
{
const Thickness margin = pChild->GetDockMargin();
pChild->SetBounds( ( renderBounds.x + renderBounds.wide ) - pChild->GetWide() - margin.right, renderBounds.y + margin.top, pChild->GetWide(), renderBounds.tall - margin.top - margin.bottom );
int iWidth = margin.left + margin.right + pChild->GetWide();
renderBounds.wide -= iWidth;
}
else if ( dock == Dock::Bottom )
{
const Thickness margin = pChild->GetDockMargin();
pChild->SetBounds( renderBounds.x + margin.left, ( renderBounds.y + renderBounds.tall ) - pChild->GetTall() - margin.bottom, renderBounds.wide - margin.left - margin.right, pChild->GetTall() );
int iHeight = pChild->GetTall() - margin.bottom - margin.top;
renderBounds.tall -= iHeight;
}
pChild->RecurseLayout();
}
m_InnerBounds = renderBounds;
// Fill the left over space
for ( int i = 0; i < ipanel()->GetChildCount( GetVPanel() ); i++ )
{
Panel *pChild = GetChild( i );
Dock::Type dock = pChild->GetDock();
if ( dock == Dock::Fill )
{
const Thickness margin = pChild->GetDockMargin();
pChild->SetBounds( renderBounds.x + margin.left, renderBounds.y + margin.top, renderBounds.wide - margin.left - margin.right, renderBounds.tall - margin.top - margin.bottom );
pChild->RecurseLayout();
}
}
PostLayout();
}

Or it is caused by the layout not being 'recalculated' at the correct times.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions