1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-15 16:17:41 +02:00

Fix: Can now drag double height toolbars onto start of last row, even when last row is single height.

I also simplified the code by (a) exiting from a loop as soon as we know the answer and by (b) not treating the initial case of a loop as 'special'.
This commit is contained in:
james.k.crook@gmail.com 2014-10-21 16:36:32 +00:00
parent a0f43759a0
commit e31644eda8
2 changed files with 52 additions and 60 deletions

@ -293,7 +293,7 @@ int ToolDock::PositionBar( ToolBar *t, wxPoint & pos, wxRect & rect )
// process one more bar than is currently docked (<= in for) // process one more bar than is currently docked (<= in for)
for (ndx = 0, ct = 0; ndx <= cnt; ndx++, ct++) for (ndx = 0, ct = 0; ndx <= cnt; ndx++, ct++)
{ {
// We're on the last entry... // If last entry, then it is the
if (ndx == cnt) if (ndx == cnt)
{ {
// ...so check to see if the new bar has been placed yet // ...so check to see if the new bar has been placed yet
@ -314,7 +314,8 @@ int ToolDock::PositionBar( ToolBar *t, wxPoint & pos, wxRect & rect )
tinfo[ct].rect = b->GetRect(); tinfo[ct].rect = b->GetRect();
tinfo[ct].min = b->GetSize(); tinfo[ct].min = b->GetSize();
// Insert the new bar if it hasn't already been done // Maybe insert the new bar if it hasn't already been done
// and is in the right place.
if (tindx == -1) if (tindx == -1)
{ {
wxRect r; wxRect r;
@ -342,31 +343,22 @@ int ToolDock::PositionBar( ToolBar *t, wxPoint & pos, wxRect & rect )
int tw = sz.GetWidth() + toolbarGap; int tw = sz.GetWidth() + toolbarGap;
int th = sz.GetHeight() + toolbarGap; int th = sz.GetHeight() + toolbarGap;
// This loop reduces stkcnt until it gives a box
// Will this one fit in remaining space? // that we fit in.
while (stkcnt > 0)
{
// Get out if it will fit
bool bTooWide = tw > stack[stkcnt].GetWidth(); bool bTooWide = tw > stack[stkcnt].GetWidth();
// We'd like to be able to add a tall toolbar in at the start of a row, // We'd like to be able to add a tall toolbar in at the start of a row,
// even if there isn't enough height for it. // even if there isn't enough height for it.
// If so, we'd have to at least change how we calculate 'bTooHigh'. // If so, we'd have to at least change how we calculate 'bTooHigh'.
bool bTooHigh = th > stack[stkcnt].GetHeight(); bool bTooHigh = th > stack[stkcnt].GetHeight();
if( bTooWide || bTooHigh ) //bTooHigh &= stack[stkcnt].GetWidth() < (width - toolbarGap);
{ //bTooHigh = false;
// Destack entries until one is found in which this bar
// will fit or until we run out of stacked entries
while( stkcnt > 0 )
{
stkcnt--;
// Get out if it will fit
bTooWide = tw > stack[stkcnt].GetWidth();
bTooHigh = th > stack[stkcnt].GetHeight();
if (!bTooWide && !bTooHigh) if (!bTooWide && !bTooHigh)
{
break; break;
} stkcnt--;
}
} }
// The current stack entry position is where the bar // The current stack entry position is where the bar
@ -376,8 +368,7 @@ int ToolDock::PositionBar( ToolBar *t, wxPoint & pos, wxRect & rect )
// We'll be using at least a portion of this stack entry, so // We'll be using at least a portion of this stack entry, so
// adjust the location and size. It is possible that these // adjust the location and size. It is possible that these
// will become zero if this entry and the toolbar have the // will become zero if this entry and the toolbar have the
// same height, or negative if we've added a taller toolbar at the // same height. This is (?) what we want as it will be destacked
// start of a row. This is (?) what we want as it will be destacked
// in the next iteration. // in the next iteration.
stack[stkcnt].SetY(stack[stkcnt].GetY() + th); stack[stkcnt].SetY(stack[stkcnt].GetY() + th);
stack[stkcnt].SetHeight(stack[stkcnt].GetHeight() - th); stack[stkcnt].SetHeight(stack[stkcnt].GetHeight() - th);
@ -400,16 +391,17 @@ int ToolDock::PositionBar( ToolBar *t, wxPoint & pos, wxRect & rect )
tinfo[lt].rect.y = lpos.y; tinfo[lt].rect.y = lpos.y;
} }
// Place and stretch the final toolbar
if( ndx == cnt )
{
tinfo[ ct ].rect.x = cpos.x;
tinfo[ ct ].rect.y = cpos.y;
}
// Remember for next iteration // Remember for next iteration
lt = ct; lt = ct;
lpos = cpos; lpos = cpos;
// If we've placed it, we're done.
if (tindx != -1)
{
tinfo[tindx].rect.x = cpos.x;
tinfo[tindx].rect.y = cpos.y;
break;
}
} }
// Fill in the final position // Fill in the final position

@ -1003,7 +1003,7 @@ void ToolManager::OnMouse( wxMouseEvent & event )
mIndicator->Hide(); mIndicator->Hide();
// Decide which direction the arrow should point // Decide which direction the arrow should point
if( r.GetBottom() >= dr.GetHeight() ) if( r.GetTop() >= dr.GetHeight() )
{ {
p.x = dr.GetLeft() + ( dr.GetWidth() / 2 ); p.x = dr.GetLeft() + ( dr.GetWidth() / 2 );
p.y = dr.GetBottom() - mDown->GetBox().GetHeight(); p.y = dr.GetBottom() - mDown->GetBox().GetHeight();