-
Notifications
You must be signed in to change notification settings - Fork 6
/
canvas.go
63 lines (52 loc) · 1.73 KB
/
canvas.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package control
import (
"context"
"github.com/goradd/goradd/pkg/page"
"github.com/goradd/html5tag"
)
type CanvasI interface {
page.ControlI
}
// Canvas is a GoRADD control that is an HTML canvas control. It currently does not have any primitives
// to draw on the canvas, and is here primarily to create a canvas that you would draw on using JavaScript.
type Canvas struct {
page.ControlBase
}
// NewCanvas creates a Canvas control
func NewCanvas(parent page.ControlI, id string) *Canvas {
p := &Canvas{}
p.Init(p, parent, id)
return p
}
// Init is called by subcontrols. You do not normally need to call it.
func (c *Canvas) Init(self any, parent page.ControlI, id string) {
c.ControlBase.Init(self, parent, id)
c.Tag = "canvas"
}
// DrawingAttributes is called by the framework to get the temporary attributes that are specifically set by
// this control just before drawing.
func (c *Canvas) DrawingAttributes(ctx context.Context) html5tag.Attributes {
a := c.ControlBase.DrawingAttributes(ctx)
a.SetData("grctl", "canvas")
return a
}
// CanvasCreator is the initialization structure for declarative creation of buttons
type CanvasCreator struct {
// ID is the control id
ID string
page.ControlOptions
}
// Create is called by the framework to create a new control from the Creator. You
// do not normally need to call this.
func (c CanvasCreator) Create(ctx context.Context, parent page.ControlI) page.ControlI {
ctrl := NewCanvas(parent, c.ID)
ctrl.ApplyOptions(ctx, c.ControlOptions)
return ctrl
}
// GetCanvas is a convenience method to return the canvas with the given id from the page.
func GetCanvas(c page.ControlI, id string) *Canvas {
return c.Page().GetControl(id).(*Canvas)
}
func init() {
page.RegisterControl(&Canvas{})
}