Browse Source

Updated Render to work like before. Panel center.

Steve Thielemann 3 years ago
parent
commit
0c9786c54b
2 changed files with 30 additions and 1 deletions
  1. 16 0
      door/line.go
  2. 14 1
      door/panel.go

+ 16 - 0
door/line.go

@@ -57,3 +57,19 @@ func RenderBlueYellow(text string) string {
 	}
 	return output
 }
+
+type Render struct {
+	Line      string
+	Result    string
+	Pos       int
+	LastColor string
+}
+
+func (r *Render) Append(color string, len int) {
+	if color != r.LastColor {
+		r.LastColor = color
+		r.Result += color
+	}
+	r.Result += r.Line[r.Pos : r.Pos+len]
+	r.Pos += len
+}

+ 14 - 1
door/panel.go

@@ -23,7 +23,7 @@ type Panel struct {
 	BorderColor string
 	Lines       []Line
 	Title       string
-        TitleColor  string
+	TitleColor  string
 	TitleOffset int
 }
 
@@ -164,3 +164,16 @@ func (p *Panel) Spacer() Line {
 	l.Text = strings.Repeat(BOXES[pos].top, p.Width)
 	return l
 }
+
+func (p *Panel) Center() {
+	p.CenterX()
+	p.CenterY()
+}
+
+func (p *Panel) CenterX() {
+	p.X = (Width - p.Width) / 2
+}
+
+func (p *Panel) CenterY() {
+	p.Y = (Height - len(p.Lines)) / 2
+}