I am C
type myLeaf struct {
node.LeafEmbed
// some other fields
}
func NewMyLeaf() *myLeaf {
w := &myLeaf{}
w.Wrapper = w
return w
}
func (w *myLeaf) Paint(ctx *node.PaintContext, origin image.Point) error {
w.Marks.UnmarkNeedsPaint()
// draw to ctx ...
}
内:driver.Main()
如何从外部leafA := NewMyLeaf()
leafB := NewMyLeaf()
w := widget.NewFlow(widget.AxisVertical,
widget.NewSheet(leafA),
widget.NewSheet(leafB),
)
if err := widget.RunWindow(s, w, &widget.RunWindowOptions{
NewWindowOptions: screen.NewWindowOptions{},
}); err != nil {
log.Fatal(err)
}
为每个叶子(func (w *myLeaf) Paint(...) error
)在小部件树上执行myLeaf
?
也可以使用driver.Main()
,leafA
和leafB
的指针。
答案 0 :(得分:0)
当我们查找here时,我们发现widget.RunWindow( ... )
没有处理来自来电者的此类外部请求。
一个可行的方法是实现类似的函数MyRunWindow( ... )
并将Window
分配给全局接口。像这样:
func MyRunWindow(s screen.Screen, root node.Node, opts *RunWindowOptions) (err error) {
var nwo *screen.NewWindowOptions
// ... assign window options ...
if MyWindow, err = s.NewWindow(nwo); err != nil {
return err
}
// event loop, processing 'lifecycle.Event', 'input.Event', etc.
// and you can process own 'Events' in a type switch
for {
e := MyWindow.NextEvent()
if e = gef.Filter(e); e == nil {
continue
}
switch e := e.(type) {
case MyEvent:
// ... call on 'root' here
}
}
在来电者方面,您可以像这样使用全球Interface
:
MyWindow.Send(paint.Event{}) // for a needed call to root.Paint()
MyWindow.Send(MyEvent{}) // for your own event to be processed