@@ -19,17 +19,17 @@ func (l *Label) uiInitialize(ui *Ui) { | |||
l.ui = ui | |||
} | |||
func (l *Label) setActive(active bool) { | |||
func (l *Label) uiSetActive(active bool) { | |||
} | |||
func (l *Label) setBounds(x0, y0, x1, y1 int) { | |||
func (l *Label) uiSetBounds(x0, y0, x1, y1 int) { | |||
l.x0 = x0 | |||
l.y0 = y0 | |||
l.x1 = x1 | |||
l.y1 = y1 | |||
} | |||
func (l *Label) draw() { | |||
func (l *Label) uiDraw() { | |||
reader := strings.NewReader(l.Text) | |||
for y := l.y0; y < l.y1; y++ { | |||
for x := l.x0; x < l.x1; x++ { | |||
@@ -44,8 +44,8 @@ func (l *Label) draw() { | |||
} | |||
} | |||
func (l *Label) keyEvent(mod Modifier, key Key) { | |||
func (l *Label) uiKeyEvent(mod Modifier, key Key) { | |||
} | |||
func (l *Label) characterEvent(chr rune) { | |||
func (l *Label) uiCharacterEvent(chr rune) { | |||
} |
@@ -23,18 +23,18 @@ func (t *Textbox) uiInitialize(ui *Ui) { | |||
t.ui = ui | |||
} | |||
func (t *Textbox) setBounds(x0, y0, x1, y1 int) { | |||
func (t *Textbox) uiSetActive(active bool) { | |||
t.active = active | |||
} | |||
func (t *Textbox) uiSetBounds(x0, y0, x1, y1 int) { | |||
t.x0 = x0 | |||
t.y0 = y0 | |||
t.x1 = x1 | |||
t.y1 = y1 | |||
} | |||
func (t *Textbox) setActive(active bool) { | |||
t.active = active | |||
} | |||
func (t *Textbox) draw() { | |||
func (t *Textbox) uiDraw() { | |||
var setCursor = false | |||
reader := strings.NewReader(t.Text) | |||
for y := t.y0; y < t.y1; y++ { | |||
@@ -54,7 +54,7 @@ func (t *Textbox) draw() { | |||
} | |||
} | |||
func (t *Textbox) keyEvent(mod Modifier, key Key) { | |||
func (t *Textbox) uiKeyEvent(mod Modifier, key Key) { | |||
redraw := false | |||
switch key { | |||
case KeyCtrlC: | |||
@@ -79,13 +79,13 @@ func (t *Textbox) keyEvent(mod Modifier, key Key) { | |||
} | |||
} | |||
if redraw { | |||
t.draw() | |||
t.uiDraw() | |||
termbox.Flush() | |||
} | |||
} | |||
func (t *Textbox) characterEvent(chr rune) { | |||
func (t *Textbox) uiCharacterEvent(chr rune) { | |||
t.Text = t.Text + string(chr) | |||
t.draw() | |||
t.uiDraw() | |||
termbox.Flush() | |||
} |
@@ -22,10 +22,10 @@ func (t *Textview) uiInitialize(ui *Ui) { | |||
t.ui = ui | |||
} | |||
func (t *Textview) setActive(active bool) { | |||
func (t *Textview) uiSetActive(active bool) { | |||
} | |||
func (t *Textview) setBounds(x0, y0, x1, y1 int) { | |||
func (t *Textview) uiSetBounds(x0, y0, x1, y1 int) { | |||
t.x0 = x0 | |||
t.y0 = y0 | |||
t.x1 = x1 | |||
@@ -102,7 +102,7 @@ func (t *Textview) Clear() { | |||
t.parsedLines = nil | |||
} | |||
func (t *Textview) draw() { | |||
func (t *Textview) uiDraw() { | |||
var reader *strings.Reader | |||
line := len(t.parsedLines) - 1 - t.CurrentLine | |||
if line < 0 { | |||
@@ -140,8 +140,8 @@ func (t *Textview) draw() { | |||
} | |||
} | |||
func (t *Textview) keyEvent(mod Modifier, key Key) { | |||
func (t *Textview) uiKeyEvent(mod Modifier, key Key) { | |||
} | |||
func (t *Textview) characterEvent(chr rune) { | |||
func (t *Textview) uiCharacterEvent(chr rune) { | |||
} |
@@ -48,7 +48,11 @@ func (t *Tree) uiInitialize(ui *Ui) { | |||
t.ui = ui | |||
} | |||
func (t *Tree) setBounds(x0, y0, x1, y1 int) { | |||
func (t *Tree) uiSetActive(active bool) { | |||
t.active = active | |||
} | |||
func (t *Tree) uiSetBounds(x0, y0, x1, y1 int) { | |||
t.x0 = x0 | |||
t.y0 = y0 | |||
t.x1 = x1 | |||
@@ -91,7 +95,7 @@ func (t *Tree) rebuild_rec(parent TreeItem, level int) []renderedTreeItem { | |||
return lines | |||
} | |||
func (t *Tree) draw() { | |||
func (t *Tree) uiDraw() { | |||
if t.lines == nil { | |||
t.Rebuild() | |||
} | |||
@@ -124,11 +128,7 @@ func (t *Tree) draw() { | |||
} | |||
} | |||
func (t *Tree) setActive(active bool) { | |||
t.active = active | |||
} | |||
func (t *Tree) keyEvent(mod Modifier, key Key) { | |||
func (t *Tree) uiKeyEvent(mod Modifier, key Key) { | |||
switch key { | |||
case KeyArrowUp: | |||
t.activeLine = bounded(t.activeLine-1, 0, len(t.lines)-1) | |||
@@ -142,5 +142,5 @@ func (t *Tree) keyEvent(mod Modifier, key Key) { | |||
t.ui.Refresh() | |||
} | |||
func (t *Tree) characterEvent(ch rune) { | |||
func (t *Tree) uiCharacterEvent(ch rune) { | |||
} |
@@ -52,7 +52,7 @@ func (ui *Ui) Refresh() { | |||
termbox.Clear(termbox.Attribute(ui.Fg), termbox.Attribute(ui.Bg)) | |||
termbox.HideCursor() | |||
for _, element := range ui.elements { | |||
element.View.draw() | |||
element.View.uiDraw() | |||
} | |||
termbox.Flush() | |||
} | |||
@@ -65,11 +65,11 @@ func (ui *Ui) Active() View { | |||
func (ui *Ui) SetActive(name string) { | |||
element, _ := ui.elements[name] | |||
if ui.activeElement != nil { | |||
ui.activeElement.View.setActive(false) | |||
ui.activeElement.View.uiSetActive(false) | |||
} | |||
ui.activeElement = element | |||
if element != nil { | |||
element.View.setActive(true) | |||
element.View.uiSetActive(true) | |||
} | |||
ui.Refresh() | |||
} | |||
@@ -118,7 +118,7 @@ func (ui *Ui) Run() error { | |||
func (ui *Ui) onCharacterEvent(ch rune) { | |||
if ui.activeElement != nil { | |||
ui.activeElement.View.characterEvent(ch) | |||
ui.activeElement.View.uiCharacterEvent(ch) | |||
} | |||
} | |||
@@ -129,7 +129,7 @@ func (ui *Ui) onKeyEvent(mod Modifier, key Key) { | |||
} | |||
} | |||
if ui.activeElement != nil { | |||
ui.activeElement.View.keyEvent(mod, key) | |||
ui.activeElement.View.uiKeyEvent(mod, key) | |||
} | |||
} | |||
@@ -147,13 +147,10 @@ func (ui *Ui) Add(name string, view View) error { | |||
func (ui *Ui) SetBounds(name string, x0, y0, x1, y1 int) error { | |||
element, ok := ui.elements[name] | |||
if !ok { | |||
return errors.New("view cannot be found") | |||
return errors.New("view does not exist") | |||
} | |||
element.X0 = x0 | |||
element.Y0 = y0 | |||
element.X1 = x1 | |||
element.Y1 = y1 | |||
element.View.setBounds(x0, y0, x1, y1) | |||
element.X0, element.Y0, element.X1, element.Y1 = x0, y0, x1, y1 | |||
element.View.uiSetBounds(x0, y0, x1, y1) | |||
return nil | |||
} | |||
@@ -2,9 +2,9 @@ package uiterm | |||
type View interface { | |||
uiInitialize(ui *Ui) | |||
setActive(active bool) | |||
setBounds(x0, y0, x1, y1 int) | |||
draw() | |||
keyEvent(mod Modifier, key Key) | |||
characterEvent(ch rune) | |||
uiSetActive(active bool) | |||
uiSetBounds(x0, y0, x1, y1 int) | |||
uiDraw() | |||
uiKeyEvent(mod Modifier, key Key) | |||
uiCharacterEvent(ch rune) | |||
} |