Can button arrays be created via the GUI and if so, how? 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
User avatar
mloutris
In need of some credit
In need of some credit
Posts: 7
Joined: Mon Feb 19, 2018 3:08 pm

Can button arrays be created via the GUI and if so, how?

Post by mloutris »

I'm just wondering if an array of buttons can be created via the wxWidgets GUI?
For calculators, keyboards (typing and musical) etc, this would be a neat feature.
If there is no way to do this, does it sound like a reasonable project?
I would think that the user could be prompted for the rows and columns, and then use the existing button interface to generate an array of buttons.
Thanks,
-Mike
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Can button arrays be created via the GUI and if so, how?

Post by doublemax »

Code: Select all

wxPanel *panel = new wxPanel(this, wxID_ANY);

const int numRows = 8;
const int numCols = 6;

wxFlexGridSizer *fgs = new wxFlexGridSizer( numRows, numCols, 3, 3 );
for(int row = 0; row < numRows; row++ )
{
  for(int col = 0; col < numCols; col++ )
  {
    fgs->Add( new wxButton(panel, wxID_ANY, wxString::Format("%d %d", row, col)) );
  }
}
panel->SetSizer(fgs);
Use the source, Luke!
User avatar
mloutris
In need of some credit
In need of some credit
Posts: 7
Joined: Mon Feb 19, 2018 3:08 pm

Re: Can button arrays be created via the GUI and if so, how?

Post by mloutris »

Thank you, DoubleMax!

I'm interpreting your reply to mean that button arrays **cannot** be currently created via the GUI, but you are showing the manually entered code to support the array.
Adding the ability to do this graphically is probably best left until I have time to dig into the source code.

Thanks again!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Can button arrays be created via the GUI and if so, how?

Post by PB »

That is not on wxWidgets but on the RAD tool such as wxFormBuilder, wxSmith, wxCrafter, or wxGlade.

TBH, the layouts you mentioned are not usually just uniform arrays of buttons.

If you have a nontrivial layout such as this, you are probably better of with code.
Last edited by PB on Thu Mar 18, 2021 9:27 pm, edited 1 time in total.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Can button arrays be created via the GUI and if so, how?

Post by doublemax »

mloutris wrote: Thu Mar 18, 2021 9:14 pm I'm interpreting your reply to mean that button arrays **cannot** be currently created via the GUI, but you are showing the manually entered code to support the array.
Sorry, i misunderstood your question. I don't know if there is any RAD tool that can do this, as i never use one. It should be easy to implement, but then again, it's for a very specific use case.
Use the source, Luke!
User avatar
mloutris
In need of some credit
In need of some credit
Posts: 7
Joined: Mon Feb 19, 2018 3:08 pm

Re: Can button arrays be created via the GUI and if so, how?

Post by mloutris »

Hi DoubleMax

Thank you for following up, and I agree, once I understand more about how wxWidgets works, it should not be too difficult.
I would politely disagree that creating arrays of buttons is that special a use case, and it does motivate me to dig into the internals.
Right now, I'm just trying to figure out how the existing controls work! ;-)

Take care and thank you for you help!

-Mike
Post Reply