2019-03-05 20:52:18 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
type Context interface {
|
2019-04-10 19:20:39 +00:00
|
|
|
Animate()
|
2019-03-05 20:52:18 +00:00
|
|
|
HasQuit() bool
|
|
|
|
Images() *Images
|
|
|
|
Quit()
|
|
|
|
Renderer() Renderer
|
|
|
|
Style() *Style
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ Context = &context{}
|
|
|
|
var _ EventTarget = &context{}
|
|
|
|
|
|
|
|
type context struct {
|
2019-04-10 19:20:39 +00:00
|
|
|
animate bool
|
|
|
|
quit bool
|
|
|
|
r Renderer
|
|
|
|
view Control
|
|
|
|
ims *Images
|
|
|
|
style *Style
|
2019-03-05 20:52:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 19:20:39 +00:00
|
|
|
func (c *context) Animate() { c.animate = true }
|
|
|
|
|
2019-03-05 20:52:18 +00:00
|
|
|
func (c *context) HasQuit() bool { return c.quit }
|
|
|
|
|
|
|
|
func (c *context) Images() *Images { return c.ims }
|
|
|
|
|
|
|
|
func (c *context) Quit() { c.quit = true }
|
|
|
|
|
|
|
|
func (c *context) Renderer() Renderer { return c.r }
|
|
|
|
|
|
|
|
func (c *context) Style() *Style { return c.style }
|
|
|
|
|
|
|
|
// Handle implement EventTarget
|
|
|
|
func (c *context) Handle(e Event) {
|
|
|
|
switch e.(type) {
|
|
|
|
case *DisplayCloseEvent:
|
|
|
|
c.Quit()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.view.Handle(c, e)
|
|
|
|
}
|