我正在创建一个通过 wx.grid 显示大量数据的 WX Widgets 应用程序。
我实际上正在使用 WX.Go。
无论我做什么,网格都不会在滚动窗口内,网格甚至会越过状态栏。
我要做的就是将网格放在可滚动的窗口/面板中。
w := ControlWindow{}
w.Frame = wx.NewFrame(wx.NullWindow, -1, "FooBar", wx.DefaultPosition, wx.NewSizeT(600, 400))
w.statusbar = w.CreateStatusBar()
w.statusbar.SetStatusText("Welcome to FooBar")
w.SetBackgroundColour(wx.GetBLACK())
scroller := wx.NewScrolledWindow(w, wx.ID_ANY)
scroller.SetScrollbar(wx.VERTICAL, 1, 1, 1)
scroller.SetBackgroundColour(wx.GetGREEN())
w.menubar = wx.NewMenuBar()
menuFile := wx.NewMenu()
menuFile.Append(wx.ID_EXIT)
wx.Bind(w, wx.EVT_MENU, func(e wx.Event) {
w.Close(true)
}, wx.ID_EXIT)
w.menubar.Append(menuFile, "&File")
w.SetMenuBar(w.menubar)
vSizer := wx.NewBoxSizer(wx.VERTICAL)
/*add system choices */
filesFolder := strings.Join([]string{ThisFolder, "systems"}, Slash)
err := filepath.Walk(filesFolder, func(path string, info os.FileInfo, err error) error {
SystemFiles = append(SystemFiles, path)
return nil
})
if err != nil {
checkErr(err)
}
for _, file := range SystemFiles {
if !FileExists(file) {
continue
}
xmlFile, err := os.Open(file)
checkErr(err)
decoder := xml.NewDecoder(xmlFile)
...loop through to create SystemsAutoComplete = append(SystemsAutoComplete, attribute.Value) which is a []string
sort.Strings(SystemsAutoComplete)
systemsGrid := wx.NewGrid(w, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize)
systemsGrid.CreateGrid(0, 3)
for _, stemp := range SystemsAutoComplete {
systemsGrid.AppendRows(1)
renderer := wx.NewGridCellBoolRenderer()
systemsGrid.SetCellRenderer(systemsGrid.GetNumberRows()-1, 0, renderer)
editor := wx.NewGridCellBoolEditor()
systemsGrid.SetCellEditor(systemsGrid.GetNumberRows()-1, 0, editor)
systemsGrid.SetCellValue(systemsGrid.GetNumberRows()-1, 2, stemp)
systemsGrid.SetReadOnly(systemsGrid.GetNumberRows()-1, 2, true)
systemsGrid.AutoSizeColumns(true)
}
vSizer.Add(systemsGrid,1,wx.EXPAND,5)
scroller.SetSizer(vSizer)
scroller.FitInside()
return w
我已经尽可能地简化了代码。我仍然得到相同的结果。
package main
import (
"github.com/dontpanic92/wxGo/wx"
)
type ControlWindow struct {
wx.Frame
statusbar wx.StatusBar
toolbar wx.ToolBar
menubar wx.MenuBar
auiManager wx.AuiManager
}
func main() {
wx1 := wx.NewApp()
w := ControlWindow{}
w.Frame = wx.NewFrame(wx.NullWindow, -1, "FooBar", wx.DefaultPosition, wx.NewSizeT(600, 400))
w.SetBackgroundColour(wx.GetBLACK())
scroller := wx.NewScrolledWindow(w, wx.ID_ANY)
scroller.SetScrollbar(wx.VERTICAL, 1, 1, 1)
scroller.SetBackgroundColour(wx.GetGREEN())
vSizer := wx.NewBoxSizer(wx.VERTICAL)
grid := wx.NewGrid(scroller, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize)
grid.CreateGrid(60, 1)
vSizer.Add(grid, 1, wx.EXPAND, 5)
scroller.SetSizer(vSizer)
scroller.SetAutoLayout(true)
scroller.Layout()
scroller.Fit()
scroller.SetScrollbar(0, 16, 50, 15)
w.Show()
wx1.MainLoop()
w.Destroy()
return
}