Make empty list boxes narrower by default in wxMSW

Allocating 100px (+ margins) for empty listboxes in wxMSW resulted in a
surprising behaviour when the best size of a listbox became (significantly)
smaller after adding some items to it.

One possible solution could be to ensure that all listboxes are at least as
wide as empty ones, but it seems wrong to insist on always allocating 100+ px
when a listbox could be much narrower.

So try to mitigate the problem by making the empty listboxes narrower by
default which should reduce the chance of them becoming narrower still after
appending some items to them, even if it doesn't completely eliminate it.

Also, as a side effect, this commit replaces non-font-and-DPI-dependent
hard-coded 100px value with a more reasonable value based on text metrics.
This commit is contained in:
Vadim Zeitlin
2016-07-01 20:37:19 +02:00
parent 3d4da0ceeb
commit f9df538788

View File

@@ -616,7 +616,7 @@ wxSize wxListBox::DoGetBestClientSize() const
// give it some reasonable default value if there are no strings in the
// list
if ( wListbox == 0 )
wListbox = 100;
wListbox = 6*GetCharWidth();
// the listbox should be slightly larger than the widest string
wListbox += 3*GetCharWidth();