Text truncation in a wxStaticText controt

49 views
Skip to first unread message

Marco DeFreitas

unread,
Jan 18, 2023, 5:27:18 PM1/18/23
to wx-u...@googlegroups.com

I am continuing to transition from wxGTK-2.8.12 to wxGTK-3.2.1 and I am noticing some truncation of text in my wxStaticText control under certain circumstances.

 

I am using Red Hat 8, wxGTK-3.2.1 and gcc 8.3.1. I was able to replicate the problem with the sample program (see below). This program first sets up a default font. I then have a wxNotebook  widget. The notebook then contains a wxCheckBox and a wxStaticText/wxTextCtrl combo.

 

When I build this on wxGTK-3.2.1 the text in the wxStaticText is slightly truncated. This did not happen under wxGTK-2.8.12. If I slightly resize the frame, all the text pops in.

 

I ran "gnome-tweaks" and modified the Fonts->Interface font to "Sans Regular 10" (it was previously "Cantarell Bold 11"). It works fine after that, but I don't want to impose that system setting on our users... I assume the font setting in my code should be all I needed to do?

 

What is also frustrating is that all the text shows up if I do any of the following:

   o Remove the wxNotebook

   o Make the text in the checkbox very short

   o Make the text in the wxStaticText very long

 

Any ideas on what might be happening? Thanks!

 

The test program is:

 

#include "wx/wx.h"

#include "wx/notebook.h"

 

class MyApp: public wxApp

{

public:

    virtual bool OnInit();

};

 

class MyFrame: public wxFrame

{

public:

    MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);

private:

};

 

DECLARE_APP(MyApp)

IMPLEMENT_APP(MyApp)

 

bool MyApp::OnInit()

{

    MyFrame *frame = new MyFrame("Test", wxDefaultPosition, wxDefaultSize);

    frame->Show( true );

    return true;

}

 

MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)

        : wxFrame(NULL, wxID_ANY, title, pos, size)

{

    wxFont font = wxFont(10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,

        wxFONTWEIGHT_NORMAL, false, "Sans");

    SetFont(font);

 

    wxBoxSizer *top_sizer = new wxBoxSizer(wxVERTICAL);

    wxNotebook *nb = new wxNotebook(this, wxID_ANY, wxDefaultPosition,

       wxDefaultSize);

    wxPanel *p = new wxPanel(nb);

    wxBoxSizer *panel_sizer = new wxBoxSizer(wxVERTICAL);

    wxCheckBox *cb = new wxCheckBox(p, wxID_ANY,

       "This is sample text used in this simple example for testing");

    panel_sizer->Add(cb, 0, wxLEFT|wxTOP, 5);

    wxBoxSizer *horiz_sizer = new wxBoxSizer(wxHORIZONTAL);

    wxStaticText *st1 = new wxStaticText(p, wxID_ANY,

       "Max elapsed time in compute mode (secs): ");

    horiz_sizer->Add(st1, 0, wxALIGN_CENTRE_VERTICAL);

    wxTextCtrl *t1 = new wxTextCtrl(p, wxID_ANY, wxEmptyString,

       wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);

    horiz_sizer->Add(t1, 0);

    panel_sizer->Add(horiz_sizer, 0, wxALL, 5);

    p->SetSizerAndFit(panel_sizer);

    nb->AddPage(p, "Test", true);

    top_sizer->Add(nb, 1, wxALL|wxEXPAND, 5);

    SetSizerAndFit(top_sizer);

}


Vadim Zeitlin

unread,
Jan 18, 2023, 6:18:51 PM1/18/23
to wx-u...@googlegroups.com
On Wed, 18 Jan 2023 17:27:05 -0500 Marco DeFreitas wrote:

MD> I am continuing to transition from wxGTK-2.8.12 to wxGTK-3.2.1 and I am
MD> noticing some truncation of text in my wxStaticText control under certain
MD> circumstances.
MD>
MD> I am using Red Hat 8, wxGTK-3.2.1 and gcc 8.3.1. I was able to replicate
MD> the problem with the sample program (see below).

Hi Marco,

Unfortunately I don't see it here (Debian Bookworm) and I don't have a Red
Hat 8 system to test it on easily.

MD> I ran "gnome-tweaks" and modified the Fonts->Interface font to "Sans
MD> Regular 10" (it was previously "Cantarell Bold 11").

My Gnome installation uses "Cantarell Regular 11" but changing it to
"Cantarell Bold 11" doesn't make the problem appear neither and, in fact,
doesn't change the appearance of your example at all -- which seems to make
sense because it sets its own font anyhow, instead of using the default.

However if I replace wxFONTWEIGHT_NORMAL with wxFONTWEIGHT_BOLD in your
code, the "(secs)" part of the label indeed gets truncated, so it seems to
be related to using a wrong font for determining the control best size (and
not updating it afterwards). Just to be clear, is this what you're seeing
too? And, also, does the problem go away if you don't call SetFont() at
all?

Thanks,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Marco DeFreitas

unread,
Jan 18, 2023, 7:16:38 PM1/18/23
to wx-users
Hi Vadim,

Thanks for your quick reply!

VZ>  ...the "(secs)" part of the label indeed gets truncated, so it seems to
VZ> be related to using a wrong font for determining the control best size 
VZ> (and not updating it afterwards). Just to be clear, is this what you're 
VZ> seeing too?

Yes... the "(secs)" part getting truncated is exactly what I am seeing. 

VZ> And, also, does the problem go away if you don't call SetFont()
VZ> at all?

 If I do not set the font in this sample program, then the problem does go away (although for application specific reasons I do need to set it in my full application).

Thanks,
MD

Marco DeFreitas

unread,
Jan 23, 2023, 10:13:12 AM1/23/23
to wx-users
VZ> ...so it seems to be related to using a wrong font for determining 
VZ> the control best size (and not updating it afterwards). 

Would this require an update in the wxGTK source code? If so, is this something you will be able to look at?

Thanks,
MD


Vadim Zeitlin

unread,
Jan 23, 2023, 10:22:39 AM1/23/23
to wx-u...@googlegroups.com
On Mon, 23 Jan 2023 07:13:12 -0800 (PST) Marco DeFreitas wrote:

MD> VZ> ...so it seems to be related to using a wrong font for determining
MD> VZ> the control best size (and not updating it afterwards).
MD>
MD> Would this require an update in the wxGTK source code?

Almost certainly so, yes.

MD> If so, is this something you will be able to look at?

I'd like to do it, but I'm busy with other, non wx-related, things right
now so I couldn't find time for this yet. And, of course, there is no
guarantee that I can solve the issue even if/when I do find time because I
think that Paul had already spent time on this and apparently the
workarounds already in place for updating the layout information when GTK
styles change are not enough to handle this case...

Regards,

Vadim Zeitlin

unread,
Feb 7, 2023, 7:34:22 AM2/7/23
to wx-u...@googlegroups.com
On Wed, 18 Jan 2023 16:16:38 -0800 (PST) Marco DeFreitas wrote:

MD> Hi Vadim,
MD>
MD> Thanks for your quick reply!
MD>
MD> VZ> ...the "(secs)" part of the label indeed gets truncated, so it seems to
MD> VZ> be related to using a wrong font for determining the control best size
MD> VZ> (and not updating it afterwards). Just to be clear, is this what you're
MD> VZ> seeing too?
MD>
MD> Yes... the "(secs)" part getting truncated is exactly what I am seeing.

Just FYI, I still didn't have time to look at this, but I've created
https://github.com/wxWidgets/wxWidgets/issues/23233, to which you can
subscribe to be notified about the updates to it, to at least remember to
do it before 3.3.0.

Regards,
Reply all
Reply to author
Forward
0 new messages