forked from google/gxui
/
code_editor.go
45 lines (37 loc) · 1.12 KB
/
code_editor.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
// 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 basic
import (
"github.com/google/gxui"
"github.com/google/gxui/math"
"github.com/google/gxui/mixins"
)
type CodeEditor struct {
mixins.CodeEditor
theme *Theme
}
func CreateCodeEditor(theme *Theme) gxui.CodeEditor {
t := &CodeEditor{}
t.theme = theme
t.Init(t, theme.Driver(), theme, theme.DefaultMonospaceFont())
t.SetTextColor(theme.TextBoxDefaultStyle.FontColor)
t.SetMargin(math.Spacing{L: 3, T: 3, R: 3, B: 3})
t.SetPadding(math.Spacing{L: 3, T: 3, R: 3, B: 3})
t.SetBorderPen(gxui.TransparentPen)
return t
}
// mixins.CodeEditor overrides
func (t *CodeEditor) Paint(c gxui.Canvas) {
t.CodeEditor.Paint(c)
if t.HasFocus() {
r := t.Size().Rect()
c.DrawRoundedRect(r, 3, 3, 3, 3, t.theme.FocusedStyle.Pen, t.theme.FocusedStyle.Brush)
}
}
func (t *CodeEditor) CreateSuggestionList() gxui.List {
l := t.theme.CreateList()
l.SetBackgroundBrush(t.theme.CodeSuggestionListStyle.Brush)
l.SetBorderPen(t.theme.CodeSuggestionListStyle.Pen)
return l
}