#15637 closed defect (fixed)

Solution for wxStaticText horizontal alignment and vertical spacing problem

Reported by: juliansmart Owned by:
Priority: high Milestone: 3.0.0
Component: GUI-all Version: 3.0.0-rc2
Keywords: Sizer spacing Cc:
Blocked By: Blocking:
Patch: no

Description

As discussed on wx-dev, r66452 added 2 pixels to the wxStaticText height on Windows in order to align it horizontally with text controls when using sizers.

The problem with that is the change in vertical spacing compared with 2.8 - especially when large dialogs have been carefully crafted to optimize use of space. A couple of extra pixels can multiply rapidly when using labels and controls stacked vertically. Also there must be many other layout cases where you really do want the actual, minimum height of a wxStaticText, not a fudged height for a particular use case.

So the attached patch solves it by separating out the best client size and the extra size that should be added for optimal alignment (a new GetExtraSizeForAlignment() virtual function). Sizers instruct sizer items on whether this should be added in, depending on the kind of sizer. A wxBoxSizer will want to use GetExtraSizeForAlignment() in horizontal mode, but not in vertical mode. All other sizers assume horizontal algnment is desirable.

Currently it's wxMSW specific, but it's not impossible we could find a use for it on other platforms to improve alignment.

This should cover most cases automatically with no application code changes.

Attachments (3)

alignmentfix.diff download (7.3 KB) - added by juliansmart 11 months ago.
Alignment/spacing fix
minimal_usingonepixel.jpg download (15.8 KB) - added by juliansmart 11 months ago.
Minimal test of a horizontal sizer when we're only adding 1 pixel to wxStaticText
richtext_usingonepixel.jpg download (62.1 KB) - added by juliansmart 11 months ago.
Richtext sample dialog when we're only adding 1 pixel to wxStaticText - now the wxStaticText and wxTextCtrl are aligned.

Download all attachments as: .zip

Change History (4)

Changed 11 months ago by juliansmart

Alignment/spacing fix

Changed 11 months ago by juliansmart

Minimal test of a horizontal sizer when we're only adding 1 pixel to wxStaticText

Changed 11 months ago by juliansmart

Richtext sample dialog when we're only adding 1 pixel to wxStaticText - now the wxStaticText and wxTextCtrl are aligned.

comment:1 Changed 11 months ago by VZ

  • Resolution set to fixed
  • Status changed from new to closed

(In [75129]) Reduce the extra space added to wxMSW wxStaticText to just 1 pixel.

This seems to be still enough to align the static text label and the text
control contents when they are positioned next to each other but reduces the
amount of "lost" space when they are positioned under each other.

Closes #15637.

Note: See TracTickets for help on using tickets.