mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-16 17:35:57 -05:00
d2ui: Add a custom widget
this allows us to encapsulate any custom render functionality into this custom widget. It further helps us to remove the renderer from game_controls.
This commit is contained in:
parent
627bc8ec65
commit
bad07defe8
32
d2core/d2ui/custom_widget.go
Normal file
32
d2core/d2ui/custom_widget.go
Normal file
@ -0,0 +1,32 @@
|
||||
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) error
|
||||
}
|
||||
|
||||
// NewCustomWidget creates a new widget with custom render function
|
||||
func (ui *UIManager) NewCustomWidget(renderFunc func(target d2interface.Surface) error) *CustomWidget {
|
||||
base := NewBaseWidget(ui)
|
||||
|
||||
return &CustomWidget{
|
||||
BaseWidget: base,
|
||||
renderFunc: renderFunc,
|
||||
}
|
||||
}
|
||||
|
||||
// Render draws the custom widget
|
||||
func (c *CustomWidget) Render(target d2interface.Surface) error {
|
||||
return c.renderFunc(target)
|
||||
}
|
||||
|
||||
// Advance is a no-op
|
||||
func (c *CustomWidget) Advance(elapsed float64) error {
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user