1. 6-rows x 8-cols of buttons -sizers setup

Greetings:

I am trying to change a vertical box of 6 buttons,

to a 6-rows x 8-cols of buttons. But I am all tangled up. Please help, Thanks!

--[include statements] 
include wxeud.e    
without warning    
 
--[constants]  
constant Red = create( wxColour, {#FF,#00,#00} )  
 
--[create the controls]    
constant     
    main        = create( wxFrame, {0, -1, "TXTool", -1, -1, 400, 300} ),  
    panl        = create( wxPanel, main ),  
    scrollwin   = create( wxScrolledWindow, {panl, new_id(), -1, -1, -1, -1, 0} ),  
    txted       = create( wxTextCtrl, {panl, -1, "Enter Text Here"} ),  
    panlbox     = create( wxBoxSizer, {wxVERTICAL} ),  
    scrollbox   = create( wxBoxSizer, {wxVERTICAL} ),  
    left2right  = create( wxBoxSizer, {wxHORIZONTAL} ) 
 
--[event handlers and other code]  
add_window_to_sizer( panlbox, scrollwin, 1, wxGROW, 0 )  
add_window_to_sizer( panlbox, txted, 0, wxGROW, 0 )  
set_sizer( panl, panlbox )  
set_sizer( panl, left2right )  
 
set_sizer( scrollwin, scrollbox )    
set_sizer( scrollwin, left2right )  
set_scrollbars( scrollwin, 0, 20, 0, 50, 0, 0, 0 )    
set_back_color( scrollwin, Red )   
  
-- fill the window with some buttons    6 x 8 buttonMatrix 
atom tempbtn    
for i = 1 to 6 do    
for j = 1 to 8 do 
    tempbtn = create( wxButton, {scrollwin, -1, sprintf("Button %d", i), 0, 0, 90, 60} )    
    add_window_to_sizer( left2right, tempbtn, 0, wxGROW, 0 )   
end for --j  
 
    add_window_to_sizer( scrollbox, left2right, 0, wxGROW, 0 )   
end for --i   
    
wxMain( main )  
new topic     » topic index » view message » categorize

2. Re: 6-rows x 8-cols of buttons -sizers setup

vmars said...

Greetings:

I am trying to change a vertical box of 6 buttons,

to a 6-rows x 8-cols of buttons. But I am all tangled up. Please help, Thanks!

I'm not sure exactly what you're trying to accomplish, but there is a special sizer for making grids: wxFlexGridSizer. To use the approach that you're using, I think you would need to make more sizers, and nest them. So, you could have a single vertical sizer, and then a horizontal sizer for each row of the grid.

Here's an example using a wxFlexGridSizer. Essentially, you tell it how big to make it, and then just fill up the cells:

--[include statements]  
include wxeud.e     
without warning     
  
--[constants]   
constant Red = create( wxColour, {#FF,#00,#00} )   
  
--[create the controls]     
constant      
    main        = create( wxFrame, {0, -1, "TXTool", -1, -1, 400, 300} ),   
    panl        = create( wxPanel, main ),   
    scrollwin   = create( wxScrolledWindow, {panl, new_id(), -1, -1, -1, -1, 0} ),   
    txted       = create( wxTextCtrl, {panl, -1, "Enter Text Here"} ),   
    panlbox     = create( wxBoxSizer, {wxVERTICAL} ),   
    scrollbox   = create( wxBoxSizer, {wxVERTICAL} ), 
    button_grid = create( wxFlexGridSizer, { 6, 8, 5, 5 }) 
     
--[event handlers and other code]   
add_window_to_sizer( panlbox, scrollwin, 1, wxGROW, 0 )   
add_window_to_sizer( panlbox, txted, 0, wxGROW, 0 )   
 
set_scrollbars( scrollwin, 20, 20, 50, 50, 0, 0, 0 )  
set_back_color( scrollwin, Red )    
 
add_sizer_to_sizer( scrollbox, button_grid, 1, wxGROW, 0 ) 
atom tempbtn     
for i = 1 to 6 do     
	for j = 1 to 8 do  
	    tempbtn = create( wxButton, {scrollwin, -1, sprintf("Button %dx%d", i & j), 0, 0, 90, 60} )     
	    add_window_to_sizer( button_grid, tempbtn, 1, wxGROW, 0 )    
	end for --j   
end for --i    
 
set_sizer( panl, panlbox ) 
set_sizer( scrollwin, scrollbox )    
     
wxMain( main )   

Matt

new topic     » goto parent     » topic index » view message » categorize

3. Re: 6-rows x 8-cols of buttons -sizers setup

Ah, the ol' wxFlexGridSizer.

That's downright wonderful.

Thank you very much! ...V

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu