forked from marcusolsson/tui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
padder.go
68 lines (53 loc) · 1.52 KB
/
padder.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
package tui
import "image"
var _ Widget = &Padder{}
// Padder is a widget to fill out space.
type Padder struct {
widget Widget
padding image.Point
}
// NewPadder returns a new Padder.
func NewPadder(x, y int, w Widget) *Padder {
return &Padder{
widget: w,
padding: image.Point{x, y},
}
}
// Draw draws the padded widget.
func (p *Padder) Draw(painter *Painter) {
painter.Translate(p.padding.X, p.padding.Y)
defer painter.Restore()
p.widget.Draw(painter)
}
// Size returns the size of the padded widget.
func (p *Padder) Size() image.Point {
return p.widget.Size().Add(p.padding.Mul(2))
}
// MinSizeHint returns the minimum size the widget is allowed to be.
func (p *Padder) MinSizeHint() image.Point {
return p.widget.MinSizeHint().Add(p.padding.Mul(2))
}
// SizeHint returns the recommended size for the padded widget.
func (p *Padder) SizeHint() image.Point {
return p.widget.SizeHint().Add(p.padding.Mul(2))
}
// SizePolicy returns the default layout behavior.
func (p *Padder) SizePolicy() (SizePolicy, SizePolicy) {
return p.widget.SizePolicy()
}
// Resize updates the size of the padded widget.
func (p *Padder) Resize(size image.Point) {
p.widget.Resize(size.Sub(p.padding.Mul(2)))
}
// OnKeyEvent handles key events.
func (p *Padder) OnKeyEvent(ev KeyEvent) {
p.widget.OnKeyEvent(ev)
}
// SetFocused set the focus on the widget.
func (p *Padder) SetFocused(f bool) {
p.widget.SetFocused(f)
}
// IsFocused returns true if the widget is focused.
func (p *Padder) IsFocused() bool {
return p.widget.IsFocused()
}