mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-09-27 21:56:19 -04:00
c148941194
this simplifies error handling statements all over the ui code. Before we had to write: if err := foo.Render(target); err != nil { return err } which simplifies now to foo.Render(target)
33 lines
796 B
Go
33 lines
796 B
Go
package d2ui
|
|
|
|
import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
|
|
|
// static check that CustomWidget implements widget
|
|
var _ Widget = &CustomWidget{}
|
|
|
|
// CustomWidget is a widget with a fully custom render function
|
|
type CustomWidget struct {
|
|
*BaseWidget
|
|
renderFunc func(target d2interface.Surface)
|
|
}
|
|
|
|
// NewCustomWidget creates a new widget with custom render function
|
|
func (ui *UIManager) NewCustomWidget(renderFunc func(target d2interface.Surface)) *CustomWidget {
|
|
base := NewBaseWidget(ui)
|
|
|
|
return &CustomWidget{
|
|
BaseWidget: base,
|
|
renderFunc: renderFunc,
|
|
}
|
|
}
|
|
|
|
// Render draws the custom widget
|
|
func (c *CustomWidget) Render(target d2interface.Surface) {
|
|
c.renderFunc(target)
|
|
}
|
|
|
|
// Advance is a no-op
|
|
func (c *CustomWidget) Advance(elapsed float64) error {
|
|
return nil
|
|
}
|