Content cut off in wxBoxSizer 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.
Post Reply
TheGreatRambler
Knows some wx things
Knows some wx things
Posts: 29
Joined: Mon Feb 10, 2020 3:09 am

Content cut off in wxBoxSizer

Post by TheGreatRambler » Tue Feb 11, 2020 4:35 am

I am using a wxBoxSizer with wxHORIZONTAL set. It contains two elements, with each element being its own complicated sizer. When the main sizer is set to wxVERTICAL, everything displays, but I don't prefer this, it clutters the UI a bit (I have an idea for the upper portion of the right side that I haven't implemented).
Image
(Sorry, have a little thing in the corner there). Also, I can't make the window any smaller here, it's very nearly forced to be maximized.

Secondly, I tried to do wxHORIZONTAL, my goal. However, it didn't render the wxGrid, which was the other element in the parent wxBoxSizer. It is very likely that it's minimum size was larger than the screen, but then I would like some tips on how to make each of these elements responsive.
Image

Here's what I want the UI to look like:
Image

I'm adding widgets with a simple

Code: Select all

sizer->Add(widgetPtr, 1, wxEXPAND | wxALL);
As a side note, I'm using std::shared_ptr s to store sizers and other widgets within classes. This causes segfaults on close because the shared pointer deletes the element before wxWidgets handles it. How would I go about fixing that problem?

User avatar
doublemax
Moderator
Moderator
Posts: 15083
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Content cut off in wxBoxSizer

Post by doublemax » Tue Feb 11, 2020 6:11 am

I didn't really understand the first part of your post, it's unclear which parts of the screenshots correspond to what you're describing.

The layout you've shown can be achieved with a set of nested sizers
Gi1mcp5_new.png
Gi1mcp5_new.png (17.82 KiB) Viewed 384 times
blue = horizontal boxsizer, red = vertical
As a side note, I'm using std::shared_ptr s to store sizers and other widgets within classes. This causes segfaults on close because the shared pointer deletes the element before wxWidgets handles it. How would I go about fixing that problem?
Just don't use smart pointers. In 99% of cases you don't have to delete sizers and windows yourself, they'll be destroyed by their respective parent/owner.
Use the source, Luke!

TheGreatRambler
Knows some wx things
Knows some wx things
Posts: 29
Joined: Mon Feb 10, 2020 3:09 am

Re: Content cut off in wxBoxSizer

Post by TheGreatRambler » Tue Feb 11, 2020 10:24 pm

Thank you for your reply! I will definitely get rid of my smart pointers if they interfere with wxWidgets. About my other images, I will revise them here, because, yeah, they were rather unclear before.

Image
This image has exactly what is outlined in your diagram. The outer wxBoxSizer, however, is wxVERTICAL. All content renders (I'm using the same color scheme for box sizers)

Image
This image IS exactly what is outlined in your diagram, right down to the outer sizer being horizontal. As seen, however, half of the content does not display, only the first container I added to the parent sizer displays.

I have a hunch that my widgets are simply too GIGANTIC to fit. How could I implement responsive resizing of these widgets, even when I have the bitmap absolute pixel sizes defined that are rendered in the list ctrl and the grid?

Thanks

User avatar
doublemax
Moderator
Moderator
Posts: 15083
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Content cut off in wxBoxSizer

Post by doublemax » Tue Feb 11, 2020 11:16 pm

In the second image, the upper two buttons take up far too much height. I assume that's not intended.

When adding the horizonzal sizer containing these buttons to the vertical sizer, use 0 as proportion instead of 1, so that it doesn't grow in vertical direction. The difference between the "proportion" parameter and the wxEXPAND flag is often confusing for beginners. This might help: http://neume.sourceforge.net/sizerdemo/

The panel with the button layout, is that a "normal" wxPanel with the buttons placed using sizers? Or is it custom drawn? In the latter case you might have to override wxWindow::DoGetBestClientSize() and return a meaningful size, otherwise the sizer algorithm will collapse it to (0,0) size when there is not enough room.
Use the source, Luke!

TheGreatRambler
Knows some wx things
Knows some wx things
Posts: 29
Joined: Mon Feb 10, 2020 3:09 am

Re: Content cut off in wxBoxSizer

Post by TheGreatRambler » Tue Feb 11, 2020 11:23 pm

Yeah, the buttons are 100% too large, I just didn't want to focus on that problem yet. I don't know what you mean by panel with the button layout, I just use a wxGrid and have a custom wxGridCellRenderer. I only have one window with child widgets, and that is the wxFrame comprising the window, I have no wxPanels, though I considered it. I find this interesting:
... otherwise the sizer algorithm will collapse it to (0,0) size when there is not enough room
So, if a sizers minimum size exceeds its parent, widgets will be cut off? Is there a way I can prevent this behavior but still keep my UI like the ideal mockup?

Thanks

User avatar
doublemax
Moderator
Moderator
Posts: 15083
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Content cut off in wxBoxSizer

Post by doublemax » Wed Feb 12, 2020 6:31 am

I don't know what you mean by panel with the button layout
I meant the one that looks like a gamepad.
if a sizers minimum size exceeds its parent, widgets will be cut off? Is there a way I can prevent this behavior but still keep my UI like the ideal mockup?
If there's not enough room, there is nothing that can be done. But the wxGrids are scrollable, so i don't understand why there are no scrollbars.

Without having the sizer code to play around with, i don't know how to continue. Can you make a mock-up with colored empty panels (set a minimum size) and post the code?
Use the source, Luke!

TheGreatRambler
Knows some wx things
Knows some wx things
Posts: 29
Joined: Mon Feb 10, 2020 3:09 am

Re: Content cut off in wxBoxSizer

Post by TheGreatRambler » Thu Feb 13, 2020 4:31 am

I bit the bullet and just did

Code: Select all

SetMinSize(wxSize(0, 0));
It feels like bad form, but it accomplishes the task. Thank you for your help!

Post Reply