Button behavior on GTK

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
pnq32
In need of some credit
In need of some credit
Posts: 2
Joined: Thu Jan 28, 2021 9:09 pm

Button behavior on GTK

Post by pnq32 »

I am trying to build a wxWidgets application for Linux and encountered the following button-related issues:

Issue 1: Display of shadows
The theme that I usually use (Materia) makes heavy use of shadows to display buttons. It also displays the "active" button (the one that you trigger when pressing Enter) a little bit darker than all others. Both of these aspects can be seen from the following demo GUI that I created using a native API for GTK3 (PyGObject):
materia-gtk.png
materia-gtk.png (10.6 KiB) Viewed 1900 times
When I try to recreate this GUI using wxWidgets, however, the shadows are not visible at all:
materia-wx.png
materia-wx.png (10.74 KiB) Viewed 1900 times
Other themes that I tested (such as Adawita) did not suffer from this effect. However, this is probably because they just do not make use of shadows:
adawita-wx.png
adawita-wx.png (8.62 KiB) Viewed 1900 times
This is the wxFrame code that I used to create the wxWidgets demo application:

Code: Select all

wxBoxSizer *BoxSizer = new wxBoxSizer(wxHORIZONTAL);
wxButton *LeftButton = new wxButton(this, -1, "Button #1");
wxButton *RightButton = new wxButton(this, -1, "Button #2");
BoxSizer->Add(LeftButton, 0, wxALL, 20);
BoxSizer->Add(RightButton, 0, (wxALL & ~wxLEFT), 20);
SetSizerAndFit(BoxSizer);
Is there anything I can do to fix this problem?

Issue 2: Mouse click event changes the focus
In the native application, clicking into the window itself, i.e., the gray background, does not alter the currently active button. In the wxWidgets application, however, clicking into the background will always activate the last button that I added (Button #2). However, this is not exactly what I want. I would prefer if the previously activated button would just continue to be active. Is there a way to achieve this?

Information on the platform
I am running Fedora with GNOME 3.38.3 (Wayland) and installed wxWidgets from the official repository. CMake configures the project as follows:

Code: Select all

-- The CXX compiler identification is GNU 10.2.1
-- Found wxWidgets: -pthread;;;-lwx_gtk3u_core-3.0;-lwx_baseu-3.0 (found version "3.0.5")
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Button behavior on GTK

Post by ONEEYEMAN »

Hi,
pnq32 wrote: Thu Jan 28, 2021 9:32 pm I am trying to build a wxWidgets application for Linux and encountered the following button-related issues:

Issue 1: Display of shadows
The theme that I usually use (Materia) makes heavy use of shadows to display buttons. It also displays the "active" button (the one that you trigger when pressing Enter) a little bit darker than all others. Both of these aspects can be seen from the following demo GUI that I created using a native API for GTK3 (PyGObject):
materia-gtk.png

When I try to recreate this GUI using wxWidgets, however, the shadows are not visible at all:
adawita-wx.png

Other themes that I tested (such as Adawita) did not suffer from this effect. However, this is probably because they just do not make use of shadows:
adawita-wx.png

This is the wxFrame code that I used to create the wxWidgets demo application:

Code: Select all

wxBoxSizer *BoxSizer = new wxBoxSizer(wxHORIZONTAL);
wxButton *LeftButton = new wxButton(this, -1, "Button #1");
wxButton *RightButton = new wxButton(this, -1, "Button #2");
BoxSizer->Add(LeftButton, 0, wxALL, 20);
BoxSizer->Add(RightButton, 0, (wxALL & ~wxLEFT), 20);
SetSizerAndFit(BoxSizer);
Is there anything I can do to fix this problem?
What wx version do you use?
How did you configure you build?
Can you see it in the widgets sample?
pnq32 wrote: Thu Jan 28, 2021 9:32 pm Issue 2: Mouse click event changes the focus
In the native application, clicking into the window itself, i.e., the gray background, does not alter the currently active button. In the wxWidgets application, however, clicking into the background will always activate the last button that I added (Button #2). However, this is not exactly what I want. I would prefer if the previously activated button would just continue to be active. Is there a way to achieve this?
Is this on the frame or the dialog?
In order to not to do it create an empty get focus event for the panel (or whatever TLW you use)
pnq32 wrote: Thu Jan 28, 2021 9:32 pm Information on the platform
I am running Fedora with GNOME 3.38.3 (Wayland) and installed wxWidgets from the official repository. CMake configures the project as follows:

Code: Select all

-- The CXX compiler identification is GNU 10.2.1
-- Found wxWidgets: -pthread;;;-lwx_gtk3u_core-3.0;-lwx_baseu-3.0 (found version "3.0.5")
The theme issue might be related to the Wayland - I don't know. Try to send an E-mail to wx-users ML where you can get Paul (GTK core developer).

Thank you.
pnq32
In need of some credit
In need of some credit
Posts: 2
Joined: Thu Jan 28, 2021 9:09 pm

Re: Button behavior on GTK

Post by pnq32 »

Thank you for your response.
ONEEYEMAN wrote: Thu Jan 28, 2021 11:46 pm What wx version do you use?
How did you configure you build?
Can you see it in the widgets sample?
In the initial demo application, I used a version 3.0.5 build that I didn't configure myself.
To answer your third question, I built version 3.1.4 from source as follows:

Code: Select all

mkdir gtk-build
cd gtk-build
../configure --prefix=/some/local/path
make -j4
make install
Compiling the widgets sample app from the samples subdirectory resulted in an application that suffers from the same issue. I also tried to use X11 instead of Wayland. It didn't make a difference.
pnq32 wrote: Thu Jan 28, 2021 9:32 pm Is this on the frame or the dialog?
In order to not to do it create an empty get focus event for the panel (or whatever TLW you use)
The example that I provided was probably a little bit misleading. In fact, it was just a wxFrame. This is the code:

Code: Select all

MyFrame::MyFrame()
    : wxFrame(NULL, wxID_ANY, "wxWidgets")
{
    wxBoxSizer *BoxSizer = new wxBoxSizer(wxHORIZONTAL);
    wxButton *LeftButton = new wxButton(this, -1, "Button #1");
    wxButton *RightButton = new wxButton(this, -1, "Button #2");
    BoxSizer->Add(LeftButton, 0, wxALL, 20);
    BoxSizer->Add(RightButton, 0, (wxALL & ~wxLEFT), 20);
    SetSizerAndFit(BoxSizer);
}
I tried to register EVT_SET_FOCUS as follows (as the last statement in the constructor):

Code: Select all

Bind(wxEVT_SET_FOCUS, &MyFrame::OnFocus, this);
Unfortunately, the OnFocus method does not get invoked when I click into the frame. Is the frame itself even able to trigger such an event?
User avatar
doublemax
Moderator
Moderator
Posts: 19102
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Button behavior on GTK

Post by doublemax »

Check if it makes any difference (for both issues) if you use a wxPanel as parent for the buttons.

If not, try asking on the mailing list https://groups.google.com/g/wx-users or open separate tickets at http://trac.wxwidgets.org/
Use the source, Luke!
Post Reply