forked from google/gxui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
splitter_bar.go
92 lines (76 loc) · 2.16 KB
/
splitter_bar.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mixins
import (
"github.com/google/gxui"
"github.com/google/gxui/math"
"github.com/google/gxui/mixins/base"
)
type SplitterBarOuter interface {
base.ControlOuter
}
type SplitterBar struct {
base.Control
onDrag func(wndPnt math.Point)
outer SplitterBarOuter
theme gxui.Theme
onDragStart gxui.Event
onDragEnd gxui.Event
backgroundColor gxui.Color
foregroundColor gxui.Color
isDragging bool
}
func (b *SplitterBar) Init(outer SplitterBarOuter, theme gxui.Theme) {
b.Control.Init(outer, theme)
b.outer = outer
b.theme = theme
b.onDragStart = gxui.CreateEvent(func(gxui.MouseEvent) {})
b.onDragEnd = gxui.CreateEvent(func(gxui.MouseEvent) {})
b.backgroundColor = gxui.Red
b.foregroundColor = gxui.Green
}
func (b *SplitterBar) SetBackgroundColor(c gxui.Color) {
b.backgroundColor = c
}
func (b *SplitterBar) SetForegroundColor(c gxui.Color) {
b.foregroundColor = c
}
func (b *SplitterBar) OnSplitterDragged(f func(wndPnt math.Point)) {
b.onDrag = f
}
func (b *SplitterBar) IsDragging() bool {
return b.isDragging
}
func (b *SplitterBar) OnDragStart(f func(gxui.MouseEvent)) gxui.EventSubscription {
return b.onDragStart.Listen(f)
}
func (b *SplitterBar) OnDragEnd(f func(gxui.MouseEvent)) gxui.EventSubscription {
return b.onDragEnd.Listen(f)
}
// parts.DrawPaint overrides
func (b *SplitterBar) Paint(c gxui.Canvas) {
r := b.outer.Size().Rect()
c.DrawRect(r, gxui.CreateBrush(b.backgroundColor))
if b.foregroundColor != b.backgroundColor {
c.DrawRect(r.ContractI(1), gxui.CreateBrush(b.foregroundColor))
}
}
// InputEventHandler overrides
func (b *SplitterBar) MouseDown(e gxui.MouseEvent) {
b.isDragging = true
b.onDragStart.Fire(e)
var mms, mus gxui.EventSubscription
mms = e.Window.OnMouseMove(func(we gxui.MouseEvent) {
if b.onDrag != nil {
b.onDrag(we.WindowPoint)
}
})
mus = e.Window.OnMouseUp(func(we gxui.MouseEvent) {
mms.Unlisten()
mus.Unlisten()
b.isDragging = false
b.onDragEnd.Fire(we)
})
b.InputEventHandler.MouseDown(e)
}