Ticket #10008 (confirmed defect)

Opened 2 months ago

Last modified 7 weeks ago

Not using negative sizes in wxBoxSizer breaks AUI layout

Reported by: hartwigw Owned by:
Priority: normal Milestone: 2.9.0
Component: wxAui Version: 2.9-svn
Keywords: wxBoxSizer negative sizes Cc: jjn, biwillia76
Blocked By: Patch: no
Blocking:

Description

Assume the following code:

wxBoxSizer boxSizerPtr(new wxBoxSizer(wxHORIZONTAL));

boxSizerPtr->Add(firstWindow,0,0,0);
boxSizerPtr->AddStretchSpacer();
boxSizerPtr->Add(secondWindow,0,0,0);

this->SetSizer(boxSizerPtr);
...
Now, if the surrounding window's horizontal size is smaller than the size of its children, namely

this->GetSize().GetWidth() < firstWindow.GetSize().GetWidth()+secondWindow.GetSize().GetWidth()

than inside the box sizer's calculation method the stretch spacer's size becomes negative (at least temporarily). The width of the stretch spacer is adjusted later to zero but the remaining calculation is done with the previously calculated negative size.

Hartwig

Patch:

--- sizer_old.cpp 2008-05-08 09:02:13.000000000 +0200
+++ sizer_new.cpp 2008-09-28 10:03:12.000000000 +0200
@@ -1750,7 +1750,7 @@

item->SetDimension( child_pos, child_size );


- pt.y += height;
+ pt.y += item->GetSize().GetHeight();

}
else
{

@@ -1788,7 +1788,7 @@

item->SetDimension( child_pos, child_size );


- pt.x += width;
+ pt.x += item->GetSize().GetWidth();

}

}


Attachments

boxsizer_diff.txt (0.5 kB) - added by hartwigw 2 months ago.
aui_problem.jpg (116.7 kB) - added by jjn 7 weeks ago.

Change History

Changed 2 months ago by hartwigw

Changed 2 months ago by vadz

  • status changed from new to closed
  • resolution set to fixed

I think it's wrong to use negative delta at all in this code so I've solved it differently in r56010. Please let me know if you have any problems with this fix, thanks!

Changed 7 weeks ago by jjn

  • cc jjn added
  • status changed from closed to reopened
  • resolution deleted

This fix breaks the layout system of wxAUI.
Run auidemo and drag the vertical toolbar to the bottom. (screenshot attached)

Changed 7 weeks ago by jjn

Changed 7 weeks ago by vadz

  • cc biwillia76 added
  • status changed from reopened to confirmed
  • summary changed from wxBoxSizer is calculating item's position incorrectly to Not using negative sizes in wxBoxSizer breaks AUI layout
  • patch unset

The change still looks correct to me but it did indeed break wxAUI layout (interestingly enough, in different ways under MSW and GTK: under MSW the neighbouring pane keeps its size but starts encroaching on the status bar while under GTK it is resized when the toolbar is moved).

I can't find the problem myself but it seems that it is due to calling SetMinSize() with too big values somewhere, apparently because the code doesn't take into the account the fact that the toolbar size is smaller now that it doesn't show some buttons.

Ben, I'd be grateful for any help with this one because I am just too lost in wxAUI code. And I don't want to revert r56010 because it really seems like the correct thing to do.

TIA!

Changed 7 weeks ago by jjn

The problem occurs in the vertical direction only. When you drag a horizontal toolbar to the right, the minimum width also exceeds the real one, but nothing happens. Therefore SetMinSize() might be not a real problem.

I think it is hard to fix the AUI layout algorithm, even if Ben is not busy :) Alternatively don't you add something like the flag that allows negative delta to wxBoxSizer?

Changed 7 weeks ago by vadz

  • version changed from 2.8.x to 2.9-svn
  • component changed from GUI-all to wxAui
  • milestone changed from 2.8.9 to 2.9.0

Thanks for this observation, it's indeed an argument against my theory. But now I'm even more puzzled as I don't understand where does this difference between vertical and horizontal directions come from.

As for the special flag: this would be awfully ugly. It really shouldn't be needed and I hope this can be fixed before the official 2.9.0 release to avoid the need for it.

Note: See TracTickets for help on using tickets.