Opened 4 years ago

Closed 2 years ago

#12491 closed defect (fixed)

Multi-line wxButton labels

Reported by: JacekK Owned by:
Priority: normal Milestone:
Component: wxOSX (any toolkit) Version: stable-latest
Keywords: Cc: csomor
Blocked By: Blocking:
Patch: no

Description

If label text contains escape sequences, wxButton label setting behaviour is platform dependent. Here are two methods for setting button label text:
1)

btn = wx.Button(parent, -1, "This is\nlabel")

2)

btn = wx.Button(parent, -1)
btn.SetLabel("This is\nlabel")


On GTK/Linux both (1) and (2) method works fine.
On Windows platform, method (1) works, but (2) doesn't.
On OS X, method (1) doesn't work but (2) works.

Example images for Windows platform
http://img441.imageshack.us/img441/4656/dbuttonissue.jpg

and OS X
http://leafe.com/tmp/multilinebutton.png

Is this by design?

Attachments (3)

multiline-carbon.png download (23.8 KB) - added by robind 4 years ago.
multiline-cocoa.png download (22.6 KB) - added by robind 4 years ago.
multiline-carboncocoa.png download (12.1 KB) - added by disc 4 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 4 years ago by vadz

  • Component changed from wxPython to wxOSX (any toolkit)
  • Status changed from new to infoneeded_new
  • Summary changed from Issue with escape sequences in wxButton labes to Multi-line wxButton labels

This is definitely not by design and is a bug but this bug was already fixed in wxMSW 2.9. I think it was also fixed under wxOSX but I'm not sure, can anybody please test there? Here is a simple patch to use for testing:

  • samples/minimal/minimal.cpp

    a b MyFrame::MyFrame(const wxString& title) 
    172172    CreateStatusBar(2); 
    173173    SetStatusText("Welcome to wxWidgets!"); 
    174174#endif // wxUSE_STATUSBAR 
     175 
     176    new wxButton(this, -1, "A multi\nline button", wxPoint(5, 5)); 
     177    (new wxButton(this, -1, "", wxPoint(5, 55)))->SetLabel("Another\none"); 
    175178} 
    176179 
    177180 

comment:2 Changed 4 years ago by JacekK

  • Status changed from infoneeded_new to new

In wxPython, if I use multi-line label on instantiation, every further label changing works, e.g.:

		wb = wx.Button(self, -1, "\n")
		wb.SetLabel("This is\nalabel")

comment:3 Changed 4 years ago by vadz

  • Status changed from new to infoneeded_new

The question remains whether the original problem still exists in wxOSX 2.9.1 or not. If it's fixed there, the bug can be closed.

comment:4 Changed 4 years ago by robind

  • Status changed from infoneeded_new to new

No, wxOSX 2.9.1 still has the bug. (This is with the 2.9.1 tag, I don't have a workspace with the trunk version currently) I've added some multi-line buttons to the wxPython demo:

        b = wx.Button(self, 60, "Multi-line\button", (20, 280))
        b = wx.Button(self, 70, pos=(160, 280))
        b.SetLabel("Another\nmulti-line")    

I'll attach screenshots for both carbon and cocoa builds.

Changed 4 years ago by robind

Changed 4 years ago by robind

comment:5 Changed 4 years ago by vadz

  • Status changed from new to infoneeded_new
  • Version changed from 2.8.11 to 2.9-svn

Err, could it be because there is a typo in your ctor? It uses \button, not \nbutton, and the screenshots seem to indicate that the typo is not only here as "b" doesn't appear in the buttons labels.

Changed 4 years ago by disc

comment:6 Changed 4 years ago by disc

  • Status changed from infoneeded_new to new

I attached the results using trunk r65587 with the patch provided for minimal. Left is Carbon, on the right is Cocoa.

comment:7 Changed 4 years ago by vadz

  • Cc csomor added
  • Status changed from new to confirmed

Thanks!

So at least for Cocoa using '\n' in the label in ctor does work -- it just doesn't set the button size correctly.

But I seem to remember that the normal buttons height can't be changed in Cocoa at all. So we'd need to use the square buttons for them presumably to make them appear correctly.

Stefan, is this right?

comment:8 Changed 2 years ago by VZ

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

(In [72886]) Update the button bezel to account for multi-line labels in wxOSX.

If a button was created using a normal single-line label (including empty one)
and then its label was changed to something multi-line later, its size stayed
wrong in wxOSX as it still used the fixed size bezel used by normal buttons.

Adjust the bezel after each bezel change now to update the size of the button
if necessary.

Closes #12491.

Note: See TracTickets for help on using tickets.