Browse Source

Initial idea on RenderF returning output string.

Instead of returning a mess of struct we need to walk, why
not just output the line?  This will be easier on memory, and
easier on me.
Steve Thielemann 3 years ago
parent
commit
031d658ba0
1 changed files with 45 additions and 0 deletions
  1. 45 0
      door/line.go

+ 45 - 0
door/line.go

@@ -0,0 +1,45 @@
+package door
+
+// This was the way I did it in door++...
+// Don't
+/*
+type RenderOutput struct {
+	Color string
+	Pos   int
+	Len   int
+}
+
+type Render struct {
+	Text    string
+	Outputs []RenderOutput
+}
+*/
+
+type Line struct {
+	Text         string
+	DefaultColor string
+	RenderF      func(string) string
+	UpdateF      func() string
+}
+
+func (l *Line) Update() bool {
+	if l.UpdateF == nil {
+		return false
+	}
+	NewText := l.UpdateF()
+	if NewText != l.Text {
+		l.Text = NewText
+		return true
+	}
+	return false
+}
+
+func (l *Line) Output(d *Door) {
+	if l.RenderF == nil {
+		output := l.DefaultColor + l.Text
+		d.Write(output)
+	} else {
+		output := l.RenderF(l.Text)
+		d.Write(output)
+	}
+}