2

I'm obviously missing some basic understanding of either Go or Wx Widgets.

I'm trying to create a very basic table with checkboxes in the first column.

table := wx.NewGrid(w, wx.ID_ANY)
table.CreateGrid(4, 2)
table.SetCellEditor(0, 0, wx.SwigIsGridCellBoolRenderer{})

That code gives me this error:

invalid type for composite literal: wx.SwigIsGridCellBoolRenderer

I know I also have to set the editor. But I'm not even that far. The more detailed the answer, the better. Thank you!

4

1 回答 1

2

错误提示您正在使用复合文字,可用于创建支柱、切片、数组、映射或这些的派生值。

这个:

wx.SwigIsGridCellBoolRenderer{}

将是 type 的空复合文字wx.SwigIsGridCellBoolRenderer,但该类型不是您可以与复合文字一起使用的类型。它是一个接口类型:

type SwigIsGridCellBoolRenderer interface {
    SwigGetGridCellBoolRenderer() GridCellBoolRenderer
}

wx.NewGrid()返回一个类型,wx.Grid该类型是带有方法的接口:

SetCellEditor(arg2 int, arg3 int, arg4 SwigIsGridCellEditor)

所以你必须向它传递一个满足/实现wx.SwigIsGridCellEditor接口的值。

这个接口只有一个方法:

type SwigIsGridCellEditor interface {
    SwigGetGridCellEditor() GridCellEditor
}

所以任何有这种SwigGetGridCellEditor()方法的类型都可以在这里使用。这些类型是:

  • wx.SwigClassGridCellTextEditor
  • wx.SwigClassGridCellAutoWrapStringEditor
  • wx.SwigClassGridCellBoolEditor
  • wx.SwigClassGridCellChoiceEditor
  • wx.SwigClassGridCellEnumEditor
  • 等等

因此,创建上述之一的实例,您可以将其传递给table.SetCellEditor().

例如:

editor := wx.NewGridCellTextEditor()
table.SetCellEditor(0, 0, editor)
于 2018-05-10T14:54:31.173 回答