wxWidgets - Sizers

BlitzMax Modules Forums/Brucey's Modules/wxWidgets - Sizers

I'm playing around with Sizers and so far I figured out how that stuff works, but now I reached a point where I'm stuck.

I'm trying to set up a dynamic dialog box with an array of up to 3x3 images in the area of tGridS.

'*** +---------+-+---------------------+
'*** |         |S|                     |
'*** | Buttons |P| tGridS              |
'*** |         |C|                     |
'*** +---------+-+---------------------+
'*** |         |S|                     |
'*** | Spacer  |P| StaticBoxSizer      |
'*** |         |C| (ComboBoxes)        |
'*** +---------+-+---------------------+
'***		
'*** tGridS holds up to 3x3 images
'***	


The dialog box should only start with one visible image in the topleft position of tGridS (wxGridSizer.CreateRC(3,3,0,0)). The other possible positions are set to tGridS.Show(tCanvas[x,y], False).

The respective controls are not visible in the dialog but despite the Show(False) command and the call of Layout() in several places I did not manage to reduce the dialog box to the minimum size needed with only one image visible (I started with only wxGridSizer.CreateRC(1,1,0,0) to make things easier).

Is there anywhere out there a working example for a dynamic dialog?

Maybe I'm using the wrong Sizer for the result I would like to achive.

I would appreciate any hints that would help me to get where I want to.

-- Peter

try setting the SizerItem proportion to 1 for the hidden ones and the visible one to something like 10.
That way the other hidden items should take up very little of the screen real estate.

in this example i have 2 items set to 1 so they take 50% of the space each.
ie bSizerMiddlePortion.Add(m_radioBoxShowTasks, 1, wxALL, 5)
and
bSizerMiddlePortion.Add(m_radioBoxShowMainTasks, 1, wxALL, 5)

Local bSizerMiddlePortion:wxBoxSizer
bSizerMiddlePortion = New wxBoxSizer.Create(wxHORIZONTAL)
Local m_radioBoxShowTasksChoices:String[] = [ "Show My Tasks", "Show My Depts Tasks", "Show ALL Tasks" ]
m_radioBoxShowTasks = New wxRadioBox.Create(m_panelMain, wxID_ANY, "Show Team Member Main Tasks",,,,, m_radioBoxShowTasksChoices, 1, wxRA_SPECIFY_ROWS)
m_radioBoxShowTasks.Enable(False)
m_radioBoxShowTasks.SetToolTip("Main Tasks - Show yours, your departments, or ALL")
bSizerMiddlePortion.Add(m_radioBoxShowTasks, 1, wxALL, 5)

Local m_radioBoxShowMainTasksChoices:String[] = [ "Active Tasks", "Completed Tasks", "Cancelled Tasks", "ALL Tasks" ]
m_radioBoxShowMainTasks = New wxRadioBox.Create(m_panelMain, wxID_ANY, "Filter Main Tasks",,,,, m_radioBoxShowMainTasksChoices, 1, wxRA_SPECIFY_ROWS)
m_radioBoxShowMainTasks.SetToolTip("Decide which type of Main Task you want to view")
bSizerMiddlePortion.Add(m_radioBoxShowMainTasks, 1, wxALL, 5)

bSizerPanel.AddSizer(bSizerMiddlePortion, 0, wxEXPAND, 5)


After much trawling through the wxWidgets source code... :-p ... it seems that a wxGridSizer is doesn't care if you are showing an item or not.

Instead, try using a wxFlexGridSizer, which is a subclass of wxGridSizer. You also need to call Fit() on your window to get it to recalculate itself.

Example :

hidden.bmx
'
' Example application stub generated by wxCodeGen v1.10 : 01 Sep 2008 10:44:15
'
SuperStrict

Framework wx.wxApp

Import "hiddengen.bmx"

New MyApp.run()

Type MyApp Extends wxApp

	Method OnInit:Int()

		Local frame:MyFrame1 = MyFrame1(New MyFrame1.Create())
		frame.Centre()
		
		frame.Show()

		Return True
	End Method

End Type



Type MyFrame1 Extends MyFrame1Base

	Field flag:Int = False
	
	Method OnInit()
		Super.OnInit()

		' hide some buttons
		gSizer1.Show(m_button2, False)
		gSizer1.Show(m_button3, False)
		gSizer1.Show(m_button4, False)
		gSizer1.Show(m_button5, False)
		gSizer1.Show(m_button6, False)
		gSizer1.Show(m_button7, False)
		gSizer1.Show(m_button8, False)
		gSizer1.Show(m_button9, False)
		
		gSizer1.Layout()
		
		' snap to fit...
		Fit()
	End Method

	Method OnShowHide(event:wxCommandEvent)
		flag = Not flag
		gSizer1.Show(m_button9 , flag)
		
		gSizer1.Layout()
		
		' snap to fit...
		Fit()
	End Method

End Type


hiddengen.bmx
'
' BlitzMax code generated with wxCodeGen v1.10 : 01 Sep 2008 11:53:49
' 
' 
' PLEASE DO "NOT" EDIT THIS FILE!
' 
SuperStrict

Import wx.wxButton
Import wx.wxFrame
Import wx.wxWindow


Type MyFrame1Base Extends wxFrame

	Field m_button10:wxButton
	Field gSizer1:wxFlexGridSizer
	Field m_button1:wxButton
	Field m_button2:wxButton
	Field m_button3:wxButton
	Field m_button4:wxButton
	Field m_button5:wxButton
	Field m_button6:wxButton
	Field m_button7:wxButton
	Field m_button8:wxButton
	Field m_button9:wxButton


	Method Create:MyFrame1Base(parent:wxWindow = Null,id:Int = wxID_ANY, title:String = "", x:Int = -1, y:Int = -1, w:Int = -1, h:Int = -1, style:Int = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL)
		return MyFrame1Base(Super.Create(parent, id, title, x, y, w, h, style))
	End Method

	Method OnInit()

		Local bSizer1:wxBoxSizer
		bSizer1 = new wxBoxSizer.Create(wxHORIZONTAL)


		Local bSizer2:wxBoxSizer
		bSizer2 = new wxBoxSizer.Create(wxVERTICAL)

		m_button10 = new wxButton.Create(Self, wxID_ANY, "Click to toggle")
		bSizer2.Add(m_button10, 0, wxALL, 5)

		bSizer1.AddSizer(bSizer2, 0, wxEXPAND, 5)


		gSizer1 = new wxFlexGridSizer.CreateRC(3, 3, 0, 0)
		gSizer1.SetFlexibleDirection( wxBOTH )
		gSizer1.SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED )

		m_button1 = new wxButton.Create(Self, wxID_ANY, "1,1")
		gSizer1.Add(m_button1, 0, wxALL, 5)

		m_button2 = new wxButton.Create(Self, wxID_ANY, "2,1")
		gSizer1.Add(m_button2, 0, wxALL, 5)

		m_button3 = new wxButton.Create(Self, wxID_ANY, "3,1")
		gSizer1.Add(m_button3, 0, wxALL, 5)

		m_button4 = new wxButton.Create(Self, wxID_ANY, "1,2")
		gSizer1.Add(m_button4, 0, wxALL, 5)

		m_button5 = new wxButton.Create(Self, wxID_ANY, "2,2")
		gSizer1.Add(m_button5, 0, wxALL, 5)

		m_button6 = new wxButton.Create(Self, wxID_ANY, "3,2")
		gSizer1.Add(m_button6, 0, wxALL, 5)

		m_button7 = new wxButton.Create(Self, wxID_ANY, "1,3")
		gSizer1.Add(m_button7, 0, wxALL, 5)

		m_button8 = new wxButton.Create(Self, wxID_ANY, "2,3")
		gSizer1.Add(m_button8, 0, wxALL, 5)

		m_button9 = new wxButton.Create(Self, wxID_ANY, "3,3")
		gSizer1.Add(m_button9, 0, wxALL, 5)

		bSizer1.AddSizer(gSizer1, 1, wxEXPAND, 5)

		SetSizer(bSizer1)
		Layout()
		bSizer1.Fit(Self)

		m_button10.ConnectAny(wxEVT_COMMAND_BUTTON_CLICKED, _OnShowHide, Null, Self)
	End Method

	Function _OnShowHide(event:wxEvent)
		MyFrame1Base(event.sink).OnShowHide(wxCommandEvent(event))
	End Function

	Method OnShowHide(event:wxCommandEvent)
		DebugLog "Please override MyFrame1.OnShowHide()"
		event.Skip()
	End Method

End Type


:o)

Thanks for the tip with wxFlexGridSizer.

I just inserted the 4 letters to the respective source code line and 'voila' everything looks as intended now.

You saved my day.

-- Peter