]> git.0d.be Git - barnard.git/commitdiff
uiterm: prefix View methods with ui
authorTim Cooper <tim.cooper@layeh.com>
Sun, 7 Dec 2014 02:12:33 +0000 (22:12 -0400)
committerTim Cooper <tim.cooper@layeh.com>
Sun, 7 Dec 2014 02:12:33 +0000 (22:12 -0400)
uiterm/label.go
uiterm/textbox.go
uiterm/textview.go
uiterm/tree.go
uiterm/ui.go
uiterm/view.go

index 4cda72c99422024b871dd3bb655c59713ef13464..5bc6652bc538294136105ea2828046d22dc76676 100644 (file)
@@ -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) {
 }
index 483456f9b8bf97b15dd6f37a4f2f5d55d0d7dafd..ff97a09c67c8e3d924839969c5979b9d8d9f0c4c 100644 (file)
@@ -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()
 }
index dc23c5def5e3e20eea97ce5db888431d13157a07..cf161b2aedc03e921131247a59cc5982a4e26621 100644 (file)
@@ -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) {
 }
index dd5d3db9f2b5b7a2e2c1bc9e1c29ea9ac0697458..135e937e3af2eff387a9c65231a955c9b9990e1e 100644 (file)
@@ -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) {
 }
index 57908c8db5d1a54ad26976534e6cb60fc7caf09c..39ddf02b3b100d9130f1371326107284ea39c98c 100644 (file)
@@ -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
 }
 
index c9b6a65dd35995dc9426f3a1b32d77e82b62c1de..c63387f247a11f778ea43e6173cd8a48c4fe593d 100644 (file)
@@ -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)
 }