问题
I have a WxWidgets project that is setup like this:
Main Frame->Main Panel->Vertical Sizer
->Horizontal Sizer for a few buttons etc
->Horizontal Sizer that shows all the main info.
->In that main sizer, I have a SimpleBook
->The Simple book has 3 panels in it.
No matter what, the SimpleBook's visable page is under the top "few buttons" sizer.
When having a panel in a sizer, the does the panel abide by the sizer's location within window?
This looked "perfect" when the SimpleBook was a Sizer. But I'm trying to fix bugs in this stackoverflow question.
EDIT: Adding simple code. Any mistakes etc in here is simply a copy/paste error. The code compiles perfectly fine. It was hard to find all the relevant pieces to copy here.
type ControlWindow struct {
wx.Frame
panel wx.Panel
gamePanel wx.Panel
editProfilePanel wx.Panel
newProfilePanel wx.Panel
mainBook wx.Simplebook
profileChoice ControlChoice
platformChoice ControlChoice
vSizerEditProfile wx.BoxSizer
vSizerNewProfile wx.BoxSizer
gridSizerEditProfile wx.FlexGridSizer
vSizerMainArea wx.BoxSizer
vSizerGameGrid wx.BoxSizer
statusbar wx.StatusBar
toolbar wx.ToolBar
menubar wx.MenuBar
hSizerSearch wx.BoxSizer
nextResults wx.Button
prevResults wx.Button
auiManager wx.AuiManager
}
func MainWindow() ControlWindow {
getPlatforms()
w := ControlWindow{}
w.Frame = wx.NewFrame(wx.NullWindow, -1, title", wx.DefaultPosition, wx.NewSizeT(800, 600))
mainSizer := wx.NewBoxSizer(wx.VERTICAL)
w.panel = wx.NewPanel(w, wx.ID_ANY)
w.mainBook = wx.NewSimplebook(w.panel, wx.ID_ANY)
blankPanel := wx.NewPanel(w, wx.ID_ANY)
w.gamePanel = wx.NewPanel(w.panel, wx.ID_ANY)
w.GameGrid = wx.NewGrid(w.gamePanel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.EXPAND|wx.ALL)
w.vSizerGameGrid = wx.NewBoxSizer(wx.VERTICAL)
w.vSizerGameGrid.Add(w.GameGrid)
w.editProfilePanel = wx.NewPanel(w.panel, wx.ID_ANY)
w.newProfilePanel = wx.NewPanel(w.panel, wx.ID_ANY)
w.vSizerNewProfile = wx.NewBoxSizer(wx.VERTICAL)
vSizer := wx.NewBoxSizer(wx.VERTICAL)
hSizerLoad := wx.NewBoxSizer(wx.HORIZONTAL)
w.hSizerSearch = wx.NewBoxSizer(wx.HORIZONTAL)
w.vSizerMainArea = wx.NewBoxSizer(wx.HORIZONTAL)
w.vSizerEditProfile = wx.NewBoxSizer(wx.VERTICAL)
w.gridSizerEditProfile = wx.NewFlexGridSizer(3, 3, 7)
hSizerLoad.Add(w.platformChoice.Choice)
hSizerLoad.Add(w.profileChoice.Choice)
hSizerLoad.Add(profileEditButton)
hSizerLoad.Add(newProfileButton)
w.hSizerSearch.Add(searchInput)
w.hSizerSearch.Add(searchBy)
w.hSizerSearch.Add(searchButton)
w.hSizerSearch.Add(resetSearch)
w.hSizerSearch.Add(perPage)
w.hSizerSearch.Add(w.prevResults, 0, wx.ALIGN_BOTTOM)
w.hSizerSearch.Add(w.totalGamesLabel, 0, wx.ALIGN_BOTTOM)
w.hSizerSearch.Add(w.nextResults, 0, wx.ALIGN_BOTTOM)
//Just so I can see where the panel actually is.
blankPanel.SetBackgroundColour(wx.GetBLUE())
w.mainBook.AddPage(blankPanel, "Blank Panel", true)
w.mainBook.AddPage(w.gamePanel, "Game Panel Text", false)
w.mainBook.AddPage(w.editProfilePanel, "Edit Profile Panel Text", false)
w.mainBook.AddPage(w.newProfilePanel, "New Profile Panel Text", false)
w.vSizerMainArea.Add(w.mainBook, 1, wx.EXPAND|wx.ALL)
w.vSizerMainArea.Layout()
/*This is what I had before but it left artifacts when hiding and showing sizers.
**So that's why I'm trying to use simplebook...
* w.vSizerMainArea.Add(w.vSizerGameGrid, 1, wx.EXPAND|wx.ALL, 5)
* w.vSizerMainArea.Add(w.vSizerNewProfile, 1, wx.EXPAND|wx.ALL, 5)
* w.vSizerMainArea.Add(w.vSizerEditProfile, 1, wx.EXPAND|wx.ALL, 5)
* w.vSizerMainArea.Hide(w.vSizerGameGrid, false)
* w.vSizerMainArea.Hide(w.vSizerNewProfile, false)
* w.vSizerMainArea.Hide(w.vSizerEditProfile, false)
*/
hSizerRunButtons.Add(SaveProfileGameChanges, 0, wx.ALIGN_BOTTOM)
hSizerRunButtons.Add(RunButton, 0, wx.ALIGN_BOTTOM)
vSizer.Add(hSizerLoad, 0, wx.EXPAND|wx.ALL, 5)
vSizer.Add(w.hSizerSearch, 0, wx.EXPAND|wx.ALL, 5)
vSizer.Add(w.vSizerMainArea, 3, wx.EXPAND|wx.ALL, 5)
vSizer.Add(hSizerRunButtons, 0, wx.EXPAND|wx.ALL, 5)
w.panel.SetSizer(vSizer)
mainSizer.Add(w.panel, 1, wx.ALL|wx.EXPAND, 5)
w.SetSizer(mainSizer)
return w
}
回答1:
You must create wxSimplebook
pages with the book control itself as parent and not some completely different window.
来源:https://stackoverflow.com/questions/59723728/wxwidgets-panels-in-sizers-dont-seem-to-be-working