0

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
}
Chemdream
  • 618
  • 2
  • 9
  • 25
  • I would put code samples here, but it's literally 1000s of lines. – Chemdream Jan 13 '20 at 20:30
  • what is the parent for the simple book page? – Igor Jan 13 '20 at 22:55
  • The parent of the simple book is the main panel. So: Frame->Panel->Sizer->SimpleBook->Panel->Sizer->control objects – Chemdream Jan 14 '20 at 00:19
  • not the simple book - it's page. What parameter is passed there in constructor? Also - you don't have to put the whole code - just the constructor and the layout code. – Igor Jan 14 '20 at 01:27
  • `sizer that shows all the main info.`, what does this do? – macroland Jan 14 '20 at 13:45
  • @macroland That's where the simplebook is. Each page is a panel. Each panel has a sizer. two of the pages are for simple input boxes and save buttons. One page is a grid. – Chemdream Jan 14 '20 at 14:07
  • You show a panel with 2 sizers, which is impossible: each window has at most 1 sizer. So it's really not clear what are you doing. – VZ. Jan 14 '20 at 14:44
  • @VZ I fixed up the sizer thing in the description. The main panel has a V sizer with H sizers in it. That was just a typo before. – Chemdream Jan 14 '20 at 19:14
  • @Igor I added some code. – Chemdream Jan 14 '20 at 19:33

1 Answers1

1

You must create wxSimplebook pages with the book control itself as parent and not some completely different window.

VZ.
  • 21,740
  • 3
  • 39
  • 42