GUI Components not hidden on switching panels Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
jgoodchild
Knows some wx things
Knows some wx things
Posts: 28
Joined: Thu Jul 28, 2016 9:09 am

Re: GUI Components not hidden on switching panels

Post by jgoodchild »

ONEEYEMAN wrote: Fri Oct 08, 2021 12:52 pm Is there any reason you reinventing the wheel and don't use sizers?
Sorry, I didn't explain the situation very well. The application uses the full screen (our customers just use the computer for that one application, which is a control system for TV studio equipment, driving it from a touch screen). Its main window is never re-sized, and nor are any child windows. When I said that the items displayed are scaled to the size of the screen, it is not dynamic scaling; the scaling is based on the number of pixels in the display, so that we can cope (to some extent) with different screen sizes, although in practice we also supply the hardware for the application, so the screen size is typically almost always the same. We have optimised for 22 inch screens, so it might not look too good with other dimensions.

So we haven't reinvented sizers. Whether we could actually achieve the same control over positioning of items on the screen with sizers, I don't know, but whoever first implemented the program clearly didn't think they were necessary even if they would have been useful.
doublemax wrote: Fri Oct 08, 2021 10:45 am With "hidden" you mean that the place where the item should be, is empty? Not that it's replaced by another item?
Yes, that is what I mean.
Is the behavior consistent? I.E. if you start the program multiple times, are always the same items missing?
It seems to be fairly consistent, although I have seen very occasional cases of something magically reappearing after previously being missing, and also the other way round: something that was displayed then disappearing later, on switching pages. Once the initial change has been seen, then it seems be to consistent thereafter.

Anyway, I have produced a cut-down version of my application. This program demonstrates the problem on Linux with wxWidgets version 3.0.5, running on Debian 10. (It should also show the problem on Ubuntu 20.04, or at least our main application does; I have not tried the cut-down version myself on Ubuntu).

The problem does not occur, however, on Windows when built with wxWidgets version 3.0.2; nor does it occur on Debian 8 with 3.0.2 (although I would have thought that the thing of more relevance would be the version of GTK rather than wxWidgets). I have yet to try wxWidgets 3.0.2 with the newer GTK on Debian 10, nor 3.0.5 on Windows.

I have tried to remove as much of the irrelevant code as possible, but even so there are 32 source files, I'm afraid. I have attached this within a .tar file.

The source file of most relevance is IniConfigPage.cpp. There is a #define near the top of the file:

#define INI_CONFIG_PANEL_ONLY

When compiled with this symbol defined, the problem does not manifest. With it commented out, however, then the problem occurs - the panel (CHeadInfoPanel) on the right-hand side of the screen (which contains a number of items) is missing.
Note that when working, the idea is that text should be shown within the panel when one of the items on the left-hand side of the screen is selected. (I notice on Windows that the selection doesn't fully work - the items are supposed to change colour from green to yellow when selected. I would be interested to know why that is, also!)

The difference between the 2 cases is that when INI_CONFIG_PANEL_ONLY is #defined, a wxPanel is instantiated on part of the screen, without anything being added to it. When the symbol is removed, then an object of the CIniControl class is instantiated in the same position instead. The position of this class should not overlap with anything else that is supposed to be displayed.

I am quite prepared to believe that there is something peculiar about the CIniControl class that might trigger the fault, but if so, I don't understand why it seems to work in some environments and not others. I have also simplified the class so that it doesn't actually do very much, and the fault still happens.

By the way, if anyone does go so far as to actually buiid and run the program, then to exit, press the DONE button in the bottom right, which brings up a different (dummy) page. Then press MENU and EXIT. You can get back to the original page by pressing MENU and then the INI Config Settings button.

Thanks in advance for any help!
Attachments
tc2.tar
Cut-down application source code
(210 KiB) Downloaded 8 times
User avatar
[email protected]
Earned some good credits
Earned some good credits
Posts: 144
Joined: Wed Jul 29, 2020 6:06 pm

Re: GUI Components not hidden on switching panels

Post by [email protected] »

I haven't built it yet (and i could build it only under Windows anyway), but from looking at the code i have a few comments:

There are a few RedrawDC() methods where you create a wxPaintDC. This is bad when the method is called from inside a paint event handler (and i think they always are). There should only be one wxPaintDC in a paint event handler.

Code: Select all

wxGraphicsContext *gc = wxGraphicsContext::Create(dc);
When you create a wxGraphicsContext , you need to delete it before leaving the method (just "delete gc;")

For debugging:

- change the app from fullscreen to resizable window. Observing if anything happens to the hidden elements while resizing can give some useful information.

- remove the SetBackgroundStyle(wxBG_STYLE_CUSTOM) and empty EVT_ERASE_BACKGROUND in CBufferedControl, so that the button background *is* drawn by the OS. Also, set a distinct background color for them. If the buttons appear, you know that the buttons are there, just your custom drawing fails.
jgoodchild
Knows some wx things
Knows some wx things
Posts: 28
Joined: Thu Jul 28, 2016 9:09 am

Re: GUI Components not hidden on switching panels

Post by jgoodchild »

[email protected] wrote: Wed Oct 13, 2021 11:20 am When you create a wxGraphicsContext, you need to delete it before leaving the method (just "delete gc;")
Ah, yes, thank you. The failure to delete the wxGraphicsContext proved to be the cause of the immediate problem, which embarrassingly I now realize is a fault I had introduced recently (and was too stupid to spot) when rearranging things to try to get rid of the original problem.
There are a few RedrawDC() methods where you create a wxPaintDC. This is bad when the method is called from inside a paint event handler (and i think they always are). There should only be one wxPaintDC in a paint event handler.
I must confess I had always wondered why the wxPaintDC was created before calling RedrawDC with it passed as a wxDC, and then subsequently not used, because a wxPaintDC was generally needed. Why not pass it as wxPaintDC? I have now implemented this, and it does seem to improve things.

However, I still have a problem with things not being displayed. This time it isn't that the item itself is missing, but that it is not being updated when it should be, but can be later, for example on switching between applications. I will be starting a new thread on that..

Anyway, thanks very much for the help!
Post Reply