1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-23 15:50:05 +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

View File

@ -291,46 +291,47 @@ int ToolDock::PositionBar( ToolBar *t, wxPoint & pos, wxRect & rect )
// //
// Careful...slightly different from above in that we expect to // Careful...slightly different from above in that we expect to
// 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
if( tindx == -1 ) if (tindx == -1)
{ {
// Add the new bars' dimensions to the mix // Add the new bars' dimensions to the mix
tinfo[ ct ].rect = t->GetRect(); tinfo[ct].rect = t->GetRect();
tinfo[ ct ].min = t->GetMinSize(); tinfo[ct].min = t->GetMinSize();
tindx = ct; tindx = ct;
} }
} }
else else
{ {
// Cache toolbar pointer // Cache toolbar pointer
ToolBar *b = (ToolBar *) mDockedBars[ ndx ]; ToolBar *b = (ToolBar *)mDockedBars[ndx];
// Remember current bars' dimensions // Remember current bars' dimensions
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
if( tindx == -1 ) // and is in the right place.
if (tindx == -1)
{ {
wxRect r; wxRect r;
// Get bar rect and make gap part of it // Get bar rect and make gap part of it
r.SetPosition( b->GetParent()->ClientToScreen( b->GetPosition() ) ); r.SetPosition(b->GetParent()->ClientToScreen(b->GetPosition()));
r.SetSize( b->IsResizable() ? b->GetSize() : b->GetSize() ); r.SetSize(b->IsResizable() ? b->GetSize() : b->GetSize());
r.width += toolbarGap; r.width += toolbarGap;
r.height += toolbarGap; r.height += toolbarGap;
// Does the location fall within this bar? // Does the location fall within this bar?
if( r.Contains( pos ) || pos.y <= r.y ) if (r.Contains(pos) || pos.y <= r.y)
{ {
// Add the new bars' dimensions to the mix // Add the new bars' dimensions to the mix
tinfo[ ct ].rect = t->GetRect(); tinfo[ct].rect = t->GetRect();
tinfo[ ct ].min = t->GetSize(); tinfo[ct].min = t->GetSize();
tindx = ct; tindx = ct;
ndx--; ndx--;
} }
@ -338,78 +339,69 @@ int ToolDock::PositionBar( ToolBar *t, wxPoint & pos, wxRect & rect )
} }
// Get and cache the toolbar sizes // Get and cache the toolbar sizes
wxSize sz = tinfo[ ct ].min; wxSize sz = tinfo[ct].min;
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.
bool bTooWide = tw > stack[stkcnt].GetWidth(); while (stkcnt > 0)
// 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.
// If so, we'd have to at least change how we calculate 'bTooHigh'.
bool bTooHigh = th > stack[stkcnt].GetHeight();
if( bTooWide || bTooHigh )
{ {
// Destack entries until one is found in which this bar // Get out if it will fit
// will fit or until we run out of stacked entries bool bTooWide = tw > stack[stkcnt].GetWidth();
while( stkcnt > 0 ) // 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.
stkcnt--; // If so, we'd have to at least change how we calculate 'bTooHigh'.
bool bTooHigh = th > stack[stkcnt].GetHeight();
//bTooHigh &= stack[stkcnt].GetWidth() < (width - toolbarGap);
//bTooHigh = false;
if (!bTooWide && !bTooHigh)
// Get out if it will fit break;
bTooWide = tw > stack[stkcnt].GetWidth(); stkcnt--;
bTooHigh = th > stack[stkcnt].GetHeight();
if( !bTooWide && !bTooHigh )
{
break;
}
}
} }
// The current stack entry position is where the bar // The current stack entry position is where the bar
// will be placed. // will be placed.
cpos = stack[ stkcnt ].GetPosition(); cpos = stack[stkcnt].GetPosition();
// 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);
// Calc the next possible horizontal location. // Calc the next possible horizontal location.
int x = cpos.x + tw; int x = cpos.x + tw;
// Add a new stack entry // Add a new stack entry
stkcnt++; stkcnt++;
stack[ stkcnt ].SetX( x ); stack[stkcnt].SetX(x);
stack[ stkcnt ].SetY( cpos.y ); stack[stkcnt].SetY(cpos.y);
stack[ stkcnt ].SetWidth( width - x ); stack[stkcnt].SetWidth(width - x);
stack[ stkcnt ].SetHeight( th ); stack[stkcnt].SetHeight(th);
// Position the previous toolbar // Position the previous toolbar
if( ndx > 0 ) if (ndx > 0)
{ {
// Place the unstretched toolbar // Place the unstretched toolbar
tinfo[ lt ].rect.x = lpos.x; tinfo[lt].rect.x = lpos.x;
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

View File

@ -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();