Looking for a tile layout kind of widget.

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.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Looking for a tile layout kind of widget.

Post by doublemax »

apoorv569 wrote: Wed Sep 22, 2021 9:53 am
doublemax wrote: Check out wxWrapSizer: https://docs.wxwidgets.org/trunk/classw ... sizer.html
Oh! This is nice, this does fix the problem somewhat. I noticed that when I expand the window size, more stuff appears, but once I get expand it to the point that the scrollbar disappears, and then I make the window small again, I don't get the scroll bar back
That's normal inside a wxScrolledWindow.

You need to catch the size event and force the virtual width to be the client width.

Code: Select all

  scrolled_window->Bind(wxEVT_SIZE, [this](wxSizeEvent& event) {
    SetVirtualSize( wxSize( GetClientSize().x, -1 ) );
  });
Use the source, Luke!
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: Looking for a tile layout kind of widget.

Post by apoorv569 »

doublemax wrote: That's normal inside a wxScrolledWindow.

You need to catch the size event and force the virtual width to be the client width.

Code: Select all

  scrolled_window->Bind(wxEVT_SIZE, [this](wxSizeEvent& event) {
    SetVirtualSize( wxSize( GetClientSize().x, -1 ) );
  });
I see, its working correctly now. Is it also possible to align all buttons in center of the window? Like if I have 3 items visible horizontally and there is only a few pixels of space needed to show the 4th item, then it shows blank space on the right side, and all the other items look off to the left side.

Image

Is it possible to always align/show all items in center?

I did add this to the m_TilesSizer flag which is the wrap sizer,

Code: Select all

            m_TilesSizer->Add(m_Tiles[y * m_nFieldWidth + x], 1, wxALL | wxALIGN_CENTER | wxEXPAND);
I assume its because wrap doesn't care about the wxALIGN_CENTER flag, as it always inserts all items either horizontally or vertically(?)
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Looking for a tile layout kind of widget.

Post by doublemax »

Is it possible to always align/show all items in center?
No.

However, if all tiles have the same size, id would be relatively easy to calculate all positions yourself without any sizer.
Use the source, Luke!
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: Looking for a tile layout kind of widget.

Post by apoorv569 »

doublemax wrote: No.

However, if all tiles have the same size, id would be relatively easy to calculate all positions yourself without any sizer.
So I can get rid of the WrapSizer completely and calculate the wrapping behavior and positioning manually? Like making
a custom sizer in a way?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Looking for a tile layout kind of widget.

Post by doublemax »

apoorv569 wrote: Thu Sep 23, 2021 9:44 am
doublemax wrote: No.

However, if all tiles have the same size, id would be relatively easy to calculate all positions yourself without any sizer.
So I can get rid of the WrapSizer completely and calculate the wrapping behavior and positioning manually? Like making
a custom sizer in a way?
Yes.
Use the source, Luke!
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: Looking for a tile layout kind of widget.

Post by apoorv569 »

doublemax wrote: Yes.
I see, how do I do that? Can you point me in the right direction? I assume it would be something like get visible items, and/or the width of visible items, if the width is more or less than parent panel widget, then do something?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Looking for a tile layout kind of widget.

Post by doublemax »

Take the client width of the parent. Calculate how many tiles you can fit in a row
Calculate the x-offset of the first item, so that the tiles are centered.
Loop over all tiles and set their x- and y-position.

Set virtual size of the scrolledwindow.

Repeat when ever the client width changes.
Use the source, Luke!
Post Reply