Re: #16088: best size is not updated after SetFont() with GTK >= 3.6

73 views
Skip to first unread message

wxTrac

unread,
Apr 13, 2020, 9:33:04 AM4/13/20
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+------------------
Reporter: pcor | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: wxGTK | Version:
Resolution: | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+------------------
Changes (by carandraug):

* Attachment "wx-large-font.png" added.

example not sized properly for font

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088>

wxTrac

unread,
Apr 13, 2020, 9:46:48 AM4/13/20
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+------------------
Reporter: pcor | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: wxGTK | Version:
Resolution: | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+------------------
Changes (by carandraug):

* cc: carandraug+dev@… (added)


Comment:

I'm still affected by what I think is this issue. On this ticket
description and history there's mention of commits with partial
workarounds but I don't get what they're doing and how to work around it
on my side.

Maybe my bug is different? I'm on GTK 3.24.5 (Debian 10.3 - latest Debian
stable) and wxWidgets 3.1.3. I have this minimal example:

{{{
#include <wx/wx.h>

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

IMPLEMENT_APP(App)

bool App::OnInit()
{
wxFrame* frame = new wxFrame (NULL, wxID_ANY, "frame label");

wxStaticText* label = new wxStaticText(frame, wxID_ANY, "");
label->SetLabel(wxGetLibraryVersionInfo().GetVersionString());
wxFont font = label->GetFont();
for (int i = 0; i < 3; i++)
font.MakeLarger();
label->SetFont(font);

wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
sizer->Add(label, wxSizerFlags().Expand());
frame->SetSizerAndFit(sizer);

frame->Show(true);
return true;
}
}}}

which leads to the following which I believe is caused because it does not
take into account the resized font:

[[Image(ticket:16088:wx-large-font.png)]]

If I do not increase the font size, then I get the string "wxWidgets
3.1.3". I have also found this issue also affects StatusBar.

Am I doing something wrong? How do I work around this?

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:4>

wxTrac

unread,
Apr 13, 2020, 12:12:16 PM4/13/20
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+-----------------------
Reporter: pcor | Owner:
Type: defect | Status: confirmed
Priority: normal | Milestone:
Component: wxGTK | Version:
Resolution: | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+-----------------------
Changes (by pcor):

* status: new => confirmed


Comment:

One possibility is to add a `wxEVT_SHOW` handler.
{{{
#!diff

IMPLEMENT_APP(App)

+static void onShow(wxShowEvent& e)
+{
+ wxWindow* win = static_cast<wxWindow*>(e.GetEventObject());
+ win->GetSizer()->SetSizeHints(win);
+ win->Unbind(wxEVT_SHOW, onShow);
+}
+
bool App::OnInit()
{
wxFrame* frame = new wxFrame (NULL, wxID_ANY, "frame label");
+ frame->Bind(wxEVT_SHOW, onShow);

wxStaticText* label = new wxStaticText(frame, wxID_ANY, "");
label->SetLabel(wxGetLibraryVersionInfo().GetVersionString());
}}}

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:5>

wxTrac

unread,
Apr 13, 2020, 12:28:01 PM4/13/20
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+-----------------------
Reporter: pcor | Owner:
Type: defect | Status: confirmed
Priority: normal | Milestone:
Component: wxGTK | Version:
Resolution: | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+-----------------------

Comment (by vadz):

Could/should we have such `wxEVT_SHOW` handler in wxGTK itself? We'd need
to remember if the size of the frame had been explicitly set to something
else though, to avoid overriding it with the fitting values, but this
ought to be possible.

And this still wouldn't help if you do something depending on the best
size computed using the wrong font in your code, but it should cover most
of the realistic use cases in which we just want the initial layout to be
correct.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:6>

wxTrac

unread,
Apr 13, 2020, 1:41:43 PM4/13/20
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+-----------------------
Reporter: pcor | Owner:
Type: defect | Status: confirmed
Priority: normal | Milestone:
Component: wxGTK | Version:
Resolution: | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+-----------------------

Comment (by pcor):

Replying to [comment:6 vadz]:
> Could/should we have such `wxEVT_SHOW` handler in wxGTK itself?

I don't know... the frame sizing code is already very complicated. There
are so any ways the sizing can happen. Maybe we could somehow record that
some form of `wxSizer::Fit()` had been called. But I strongly suspect this
could be a whack-a-mole situation.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:7>

wxTrac

unread,
Apr 13, 2020, 3:28:16 PM4/13/20
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+-----------------------
Reporter: pcor | Owner:
Type: defect | Status: confirmed
Priority: normal | Milestone:
Component: wxGTK | Version:
Resolution: | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+-----------------------

Comment (by vadz):

Yes, I agree with everything you say but OTOH we still need some way of
making this work. Can we provide some new GTK-compatible API for this?
E.g. some new event in which the initial layout could be done, once
everything is available?

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:8>

wxTrac

unread,
Apr 20, 2020, 10:18:19 AM4/20/20
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+-----------------------
Reporter: pcor | Owner:
Type: defect | Status: confirmed
Priority: normal | Milestone:
Component: wxGTK | Version:
Resolution: | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+-----------------------

Comment (by Paul Cornett <paulcor@…>):

In [changeset:"f655a52fba3109570ec7cdf137c2173c7921edd2/git-wxWidgets"
f655a52fb/git-wxWidgets]:
{{{
#!CommitTicketReference repository="git-wxWidgets"
revision="f655a52fba3109570ec7cdf137c2173c7921edd2"
Allow wxSizer::Fit() to work properly when called from TLW ctor on GTK3

Style information affecting sizes may not be updated by GTK until TLW is
shown
See #16088
}}}

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:9>

wxTrac

unread,
Apr 12, 2021, 6:25:29 PM4/12/21
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+-----------------------
Reporter: pcor | Owner:
Type: defect | Status: confirmed
Priority: normal | Milestone:
Component: wxGTK | Version:
Resolution: | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+-----------------------

Comment (by Vadim Zeitlin <vadim@…>):

In [changeset:"9c0a8be1dc32063d91ed1901fd5fcd54f4f955a1/git-wxWidgets"
9c0a8be1d/git-wxWidgets]:
{{{
#!CommitTicketReference repository="git-wxWidgets"
revision="9c0a8be1dc32063d91ed1901fd5fcd54f4f955a1"
Merge branch 'gtk-initial-size'

Fix initial size of TLWs in wxGTK when using both sizers and explicit
SetSize() calls.

See https://github.com/wxWidgets/wxWidgets/pull/2322

See #16088, #19134.
}}}

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:10>

wxTrac

unread,
Apr 12, 2021, 6:35:02 PM4/12/21
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+--------------------
Reporter: pcor | Owner:
Type: defect | Status: closed
Priority: normal | Milestone:
Component: wxGTK | Version:
Resolution: fixed | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+--------------------
Changes (by vadz):

* status: confirmed => closed
* resolution: => fixed


Comment:

This was fixed by f655a52fba3109570ec7cdf137c2173c7921edd2 and,
importantly, remains fixed in 3.1.5 as I've confirmed by testing the
changes of 9c0a8be1dc32063d91ed1901fd5fcd54f4f955a1

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:11>

wxTrac

unread,
Apr 19, 2021, 6:27:56 AM4/19/21
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+----------------------
Reporter: pcor | Owner:
Type: defect | Status: reopened
Priority: normal | Milestone:
Component: wxGTK | Version:
Resolution: | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+----------------------
Changes (by jpo234):

* cc: jpo234@… (added)
* status: closed => reopened
* resolution: fixed =>


Comment:

This is still broken for the attached test program when one switches to
the second panel of a wxSimplebook.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:12>

wxTrac

unread,
Apr 19, 2021, 6:31:03 AM4/19/21
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+----------------------
Reporter: pcor | Owner:
Type: defect | Status: reopened
Priority: normal | Milestone:
Component: wxGTK | Version:
Resolution: | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+----------------------
Changes (by jpo234):

* cc: jpo234@… (removed)


Comment:

It's still broken for the following test case:

{{{
#include <wx/wx.h>
#include <wx/simplebook.h>

class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
class MyFrame : public wxFrame
{
protected:
wxSimplebook* m_simplebook1;
wxPanel* m_panel1;
wxStaticText* m_staticText1;
wxPanel* m_panel2;
wxStaticText* m_staticText2;
wxButton* m_button1;

int m_book_page;

// Virtual event handlers, overide them in your derived class
virtual void OnButtonClick(wxCommandEvent& event) {
m_book_page = (m_book_page == 0) ? 1 : 0;
m_simplebook1->ChangeSelection(m_book_page);
}
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize&
size);
};


wxIMPLEMENT_APP(MyApp);

bool MyApp::OnInit()
{
MyFrame* frame = new MyFrame("Hello World", wxPoint(50, 50),
wxSize(450, 340));
frame->Show(true);
return true;
}

MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize&
size)
: wxFrame(NULL, wxID_ANY, title, pos, size)
{
this->SetSizeHints(wxDefaultSize, wxDefaultSize);

wxBoxSizer* bSizer1;
bSizer1 = new wxBoxSizer(wxVERTICAL);

m_simplebook1 = new wxSimplebook(this, wxID_ANY,
wxDefaultPosition, wxDefaultSize, 0);
m_panel1 = new wxPanel(m_simplebook1, wxID_ANY, wxDefaultPosition,
wxDefaultSize, wxTAB_TRAVERSAL);
wxBoxSizer* bSizer2;
bSizer2 = new wxBoxSizer(wxVERTICAL);

m_staticText1 = new wxStaticText(m_panel1, wxID_ANY, wxT("Panel
1"), wxDefaultPosition, wxDefaultSize, 0);
m_staticText1->Wrap(-1);
m_staticText1->SetFont(wxFont(15, wxFONTFAMILY_DEFAULT,
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString));

bSizer2->Add(m_staticText1, 0, wxALL, 5);


m_panel1->SetSizer(bSizer2);
m_simplebook1->AddPage(m_panel1, wxT("a page"), false);
m_panel2 = new wxPanel(m_simplebook1, wxID_ANY, wxDefaultPosition,
wxDefaultSize, wxTAB_TRAVERSAL);
wxBoxSizer* bSizer3;
bSizer3 = new wxBoxSizer(wxVERTICAL);

m_staticText2 = new wxStaticText(m_panel2, wxID_ANY, wxT("Panel
2"), wxDefaultPosition, wxDefaultSize, 0);
m_staticText2->Wrap(-1);
m_staticText2->SetFont(wxFont(30, wxFONTFAMILY_DEFAULT,
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString));

bSizer3->Add(m_staticText2, 0, wxALL, 5);


m_panel2->SetSizer(bSizer3);
m_simplebook1->AddPage(m_panel2, wxT("a page"), false);

bSizer1->Add(m_simplebook1, 1, wxEXPAND | wxALL, 5);

m_button1 = new wxButton(this, wxID_ANY, wxT("Switch"),
wxDefaultPosition, wxDefaultSize, 0);
bSizer1->Add(m_button1, 0, wxALL, 5);


this->SetSizer(bSizer1);

this->Centre(wxBOTH);

// Connect Events
m_button1->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(MyFrame::OnButtonClick), NULL, this);

m_book_page = m_simplebook1->GetSelection();
}

}}}

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:13>

wxTrac

unread,
Apr 19, 2021, 7:20:54 AM4/19/21
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+-----------------------
Reporter: pcor | Owner:
Type: defect | Status: confirmed
Priority: normal | Milestone: 3.1.6
Component: wxGTK | Version:
Resolution: | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+-----------------------
Changes (by vadz):

* status: reopened => confirmed
* milestone: => 3.1.6


Comment:

Thanks, I can reproduce the problem. Will try to debug it, unless someone
already sees what it is (and how to fix it).

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:14>

wxTrac

unread,
Apr 30, 2021, 3:15:59 PM4/30/21
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+-----------------------
Reporter: pcor | Owner:
Type: defect | Status: confirmed
Priority: normal | Milestone: 3.1.6
Component: wxGTK | Version:
Resolution: | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+-----------------------

Comment (by pcor):

Patch to `minimal` sample which reproduces the problem:
{{{
#!diff
diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
index 470e765423..f71afae69f 100644
--- a/samples/minimal/minimal.cpp
+++ b/samples/minimal/minimal.cpp
@@ -112,6 +112,9 @@ wxIMPLEMENT_APP(MyApp);
// the application class
//
----------------------------------------------------------------------------

+#include "wx/simplebook.h"
+static wxSimplebook* book;
+
// 'Main program' equivalent: the program execution "starts" here
bool MyApp::OnInit()
{
@@ -123,6 +126,25 @@ bool MyApp::OnInit()
// create the main application window
MyFrame *frame = new MyFrame("Minimal wxWidgets App");

+ book = new wxSimplebook(frame);
+ wxWindow* page = new wxWindow(book, wxID_ANY);
+ wxWindow* text = new wxStaticText(page, wxID_ANY, "First Page");
+ wxFont font(text->GetFont());
+ font.SetFractionalPointSize(font.GetFractionalPointSize() * 2);
+ text->SetFont(font);
+ wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
+ sizer->Add(text);
+ page->SetSizer(sizer);
+ book->AddPage(page, "page 1");
+ page = new wxWindow(book, wxID_ANY);
+ text = new wxStaticText(page, wxID_ANY, "Second Page");
+ text->SetFont(font);
+ sizer = new wxBoxSizer(wxVERTICAL);
+ sizer->Add(text);
+ page->SetSizer(sizer);
+ book->AddPage(page, "page 2");
+ frame->SetClientSize(400, 200);
+
// and show it (the frames, unlike simple controls, are not shown
when
// created initially)
frame->Show(true);
@@ -188,6 +210,8 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
+ book->ChangeSelection(1 - book->GetSelection());
+ return;
wxMessageBox(wxString::Format
(
"Welcome to %s!\n"
}}}

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:15>

wxTrac

unread,
Apr 30, 2021, 3:16:44 PM4/30/21
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+-----------------------
Reporter: pcor | Owner:
Type: defect | Status: confirmed
Priority: normal | Milestone: 3.1.6
Component: wxGTK | Version:
Resolution: | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+-----------------------

Comment (by Paul Cornett <paulcor@…>):

In [changeset:"3217a4e8a26bf30758c00852738c0612ca931909/git-wxWidgets"
3217a4e8a/git-wxWidgets]:
{{{
#!CommitTicketReference repository="git-wxWidgets"
revision="3217a4e8a26bf30758c00852738c0612ca931909"
Fix best size for windows which are hidden when TLW is shown with GTK3

GTK3's style cache is not updated for hidden windows until after they are
shown
See #16088
}}}

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:16>

wxTrac

unread,
May 3, 2021, 10:12:32 AM5/3/21
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+-----------------------
Reporter: pcor | Owner:
Type: defect | Status: confirmed
Priority: normal | Milestone: 3.1.6
Component: wxGTK | Version:
Resolution: | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+-----------------------
Changes (by jpo234):

* cc: jpo234@… (added)


Comment:

@Paul: I got the patch from
https://github.com/wxWidgets/wxWidgets/commit/3217a4e8a26bf30758c00852738c0612ca931909.diff
and cleanly applied it to 3.1.5. I now get the following SEGV in my
application:


{{{
Thread 1 "hettras-console" received signal SIGSEGV, Segmentation fault.
0x00007ffff79a96c5 in wxWindow::GTKSizeRevalidate (this=0x555555ea7720) at
../src/gtk/window.cpp:5881
5881 if (win->m_needSizeEvent)
(gdb) bt
#0 0x00007ffff79a96c5 in wxWindow::GTKSizeRevalidate()
(this=0x555555ea7720) at ../src/gtk/window.cpp:5881
#1 0x00007ffff7992392 in wxTopLevelWindowGTK::Show(bool)
(this=0x555555ea7720, show=true) at ../src/gtk/toplevel.cpp:1161
#2 0x00007ffff7991944 in wxTopLevelWindowGTK::ShowFullScreen(bool, long)
(this=0x555555ea7720, show=true) at ../src/gtk/toplevel.cpp:924
#3 0x00007ffff79fc78a in wxFrame::ShowFullScreen(bool, long)
(this=0x555555ea7720, show=true, style=31) at ../src/gtk/frame.cpp:115
#4 0x0000555555b2922d in HETTRASConsoleApp::OnInit() ()
#5 0x0000555555b29525 in wxAppConsoleBase::CallOnInit() ()
#6 0x00007ffff74a16a6 in wxEntry(int&, wchar_t**) (argc=@0x7ffff761f090:
1, argv=0x555555d48b90) at ../src/common/init.cpp:488
#7 0x00007ffff74a17c2 in wxEntry(int&, char**) (argc=@0x7fffffffde7c: 1,
argv=0x7fffffffdf78) at ../src/common/init.cpp:516
#8 0x0000555555b28fd7 in main ()
(gdb) p win
$1 = (wxWindow *) 0x0
}}}

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:17>

wxTrac

unread,
May 3, 2021, 12:27:04 PM5/3/21
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+-----------------------
Reporter: pcor | Owner:
Type: defect | Status: confirmed
Priority: normal | Milestone: 3.1.6
Component: wxGTK | Version:
Resolution: | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+-----------------------

Comment (by Paul Cornett <paulcor@…>):

In [changeset:"a3b7244efe1b49facd6bf7620b73ca2ebf9ac836/git-wxWidgets"
a3b7244ef/git-wxWidgets]:
{{{
#!CommitTicketReference repository="git-wxWidgets"
revision="a3b7244efe1b49facd6bf7620b73ca2ebf9ac836"
Fix possible crash after 3217a4e8a2

3217a4e8a2 (Fix best size for windows which are hidden when TLW is shown
with GTK3, 2021-04-30) did not account for possibility that window needing
revalidated best size is also the TLW.
See #16088
}}}

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:18>

wxTrac

unread,
May 4, 2021, 4:49:03 AM5/4/21
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+-----------------------
Reporter: pcor | Owner:
Type: defect | Status: confirmed
Priority: normal | Milestone: 3.1.6
Component: wxGTK | Version:
Resolution: | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+-----------------------

Comment (by jpo234):

Yes! With the latest patch applied my application now works with wxGTK3.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:19>

wxTrac

unread,
Jun 14, 2021, 6:18:23 PM6/14/21
to wx-...@googlegroups.com
#16088: best size is not updated after SetFont() with GTK >= 3.6
---------------------+--------------------
Reporter: pcor | Owner:
Type: defect | Status: closed
Priority: normal | Milestone: 3.1.6
Component: wxGTK | Version:
Resolution: fixed | Keywords: gtk3
Blocked By: | Blocking:
Patch: 0 |
---------------------+--------------------
Changes (by vadz):

* status: confirmed => closed
* resolution: => fixed


Comment:

I think this can be closed now, thanks for fixing it!

--
Ticket URL: <https://trac.wxwidgets.org/ticket/16088#comment:20>
Reply all
Reply to author
Forward
0 new messages