-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcomponent.go
74 lines (65 loc) · 1.9 KB
/
component.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
64
65
66
67
68
69
70
71
72
73
74
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2014 Stanley Steel
package view
import (
"github.com/sesteel/go-view/color"
"github.com/sesteel/go-view/event"
)
type Component interface {
View
Style() Style
}
type DefaultComponent struct {
DefaultView
style Style
Background color.RGBA
BorderColor color.RGBA
BorderWidth float64
event.EventDispatcher
}
// NewComponent creates a new DefaultComponent. DefaultComponent
// is generally not usable from a user perspective; it is useful
// for referencing, compositing or embedding in other components,
// however.
//
// Aside, the name passed into this function reprsents this component
// programtically and should be unique in cases where context may be
// ambiguous. It is intended to support testing and accessibility
// frameworks.
func NewComponent(parent View, name string) *DefaultComponent {
c := new(DefaultComponent)
c.parent = parent
c.name = name
c.style = NewStyle()
c.Background = color.WidgetBackground
c.BorderColor = color.WidgetBorder
c.BorderWidth = 1
return c
// return &DefaultComponent{
// DefaultView{
// parent,
// name},
// color.WidgetBackground,
// color.WidgetBorder,
// 1,
// }
}
func (self *DefaultComponent) Draw(surface *Surface) {
parent := self.parent
for parent != nil {
parent = parent.Parent()
}
surface.SetAntialias(ANTIALIAS_SUBPIXEL)
surface.SetSourceRGBA(self.Background)
surface.RoundedRectangle(0.5, 0.5, float64(surface.Width()), float64(surface.Height()), 0, 0, 0, 0)
surface.Fill()
surface.SetLineWidth(self.BorderWidth)
surface.RoundedRectangle(0.5, 0.5, float64(surface.Width()), float64(surface.Height()), 0, 0, 0, 0)
surface.StrokePreserve()
}
func (c *DefaultComponent) Style() Style {
return c.style
}