Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxStaticText not wrapping text on Mac (Windows and Linux work OK) #23341

Closed
lszl84 opened this issue Mar 12, 2023 · 11 comments
Closed

wxStaticText not wrapping text on Mac (Windows and Linux work OK) #23341

lszl84 opened this issue Mar 12, 2023 · 11 comments
Labels
macOS Specific to Cocoa macOS port

Comments

@lszl84
Copy link

lszl84 commented Mar 12, 2023

Description

The code below does not wrap the lines on Mac OS. Works correctly on Windows and Linux (see screenshots).

#include <wx/wx.h>

class MyApp : public wxApp
{
public:
    virtual bool OnInit();
};

wxIMPLEMENT_APP(MyApp);

class MyFrame : public wxFrame
{
public:
    MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size);
};

bool MyApp::OnInit()
{
    MyFrame *frame = new MyFrame("Hello World", wxDefaultPosition, wxDefaultSize);
    frame->Show(true);
    return true;
}

const auto paraText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nisl vitae ultricies lacinia, nisl nisl aliquam nisl, vitae aliquam";

MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size)
    : wxFrame(nullptr, wxID_ANY, title, pos, size)
{
    auto paragraph = new wxStaticText(this, wxID_ANY, paraText);
    paragraph->SetFont(wxFont(20, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
    paragraph->SetBackgroundColour(wxColour(200, 100, 100));
}

Screenshot 2023-03-12 at 20 11 03

Screenshot 2023-03-12 at 20 09 51

Screenshot 2023-03-12 at 20 09 43

Platform and version information

  • wxWidgets version you use: 3.2.2
  • wxWidgets port you use: wxOSX
  • OS and its version: Ventura 13.2.1 (22D68)
@vadz vadz added the macOS Specific to Cocoa macOS port label Mar 12, 2023
@vadz
Copy link
Contributor

vadz commented Mar 12, 2023

Apparently we need to use setPreferredMaxLayoutWidth: for this to work, but I'm really not sure. Maybe @csomor would have some idea?

It would be definitely nice if this worked, but for now you could probably use wxGenericStaticText as a workaround.

@csomor
Copy link
Contributor

csomor commented Mar 13, 2023

@vadz as far as I remember wxStaticText didn't have the guarantee to automatically wrap lines earlier, did it ?

@csomor
Copy link
Contributor

csomor commented Mar 13, 2023

wxGenericStaticText does need a call to Wrap, as does wxStaticText on macOS.

@lszl84
Copy link
Author

lszl84 commented Mar 13, 2023

From the user perspective, it is pretty confusing that the behavior is different on Mac than on the other platforms. If that is to be left as is, then it would be a good idea to mention this in the documentation.

@csomor
Copy link
Contributor

csomor commented Mar 13, 2023

@lszl84 since we are usually using native controls, these kind of things may always happen. And I thought we had discussed and even documented this somewhen in the last 25 years, but I forgot when and where. And the fact that wxGenericStaticText behaves exactly that way, could be proof .. But we can always adapt, we just need a clear concept on when exactly for which flags this should happen on macOS as well.

@vadz
Copy link
Contributor

vadz commented Mar 13, 2023

Wrap() was a rather ugly (because it modifies the actual label!) workaround for wxStaticText not doing this automatically in all ports added a long time ago (see 5d1b491 (added wxStaticText::Wrap(), 2005-08-16)), but I think it would be nice if it were not needed.

So if Mac could implement the same behaviour as the other ports, it would be best.

BTW, I have no idea how could we have an automatic test for something like this. Making background white and checking that we have some non-white pixels below the first line of text?

@csomor
Copy link
Contributor

csomor commented Mar 13, 2023

ok, so I'll change the linebreak mode from Clip to WordWrap and let's see what happens ...

@csomor
Copy link
Contributor

csomor commented Mar 13, 2023

opened #23345 for this

@vadz
Copy link
Contributor

vadz commented Mar 14, 2023

@lszl84 Could you please test the PR above and check if it fixes the problem without introducing any new ones?

@lszl84
Copy link
Author

lszl84 commented Mar 15, 2023

@vadz looks good to me

Screenshot 2023-03-15 at 18 21 58

@vadz vadz closed this as completed in 9c8dfe5 Mar 18, 2023
@vadz vadz added the backport-3.2 Fix applied to master but still has to be backported to stable 3.2 label Mar 18, 2023
@vadz
Copy link
Contributor

vadz commented Mar 18, 2023

If we don't get any complaints about the change in behaviour under macOS, we probably should backport the commit above to 3.2 too.

@vadz vadz removed the backport-3.2 Fix applied to master but still has to be backported to stable 3.2 label Jul 3, 2023
vadz pushed a commit to vadz/wxWidgets that referenced this issue Jul 3, 2023
Instead of just clipping the label, wrap it. This is more consistent
with wxMSW and wxGTK and also generally more useful.

See wxWidgets#23341, wxWidgets#23345.

(cherry picked from commit 9c8dfe5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
macOS Specific to Cocoa macOS port
Projects
None yet
Development

No branches or pull requests

3 participants