// Draw draws the label to the given buffer. func (l *Label) Draw(dst *tulib.Buffer) { r := l.rect if r.Width < 0 || r.Height < 0 { return } dst.Fill(r, l.proto) dst.DrawLabel(r, &l.params, []byte(string(l.text))) }
// Draw draws the Input to the given buffer. func (i *Input) Draw(dst *tulib.Buffer) { r := i.rect if r.Width < 0 || r.Height < 0 { return } dst.Fill(r, i.proto) dst.DrawLabel(r, &i.promptParams, i.prompt) r.X += len(i.prompt) r.Width -= r.X dst.DrawLabel(r, &i.textParams, []byte(string(i.text))) i.drawCursor(dst) }
// Draw draws the Textbox to the given buffer. func (t *Textbox) Draw(dst *tulib.Buffer) { r := t.rect if r.Width < 0 || r.Height < 0 { return } // Draw title bar. r.Height = 1 dst.Fill(r, t.titleProto) dst.DrawLabel(r, &t.titleParams, []byte(t.title)) r = t.rect if r.Height < 1 { return } r.Y++ r.Height-- // Text background. dst.Fill(r, t.textProto) // Text lines. lines := t.lines if len(lines) > r.Height { lines = lines[len(lines)-r.Height:] } max := r.Y + r.Height r.Height = 1 for _, line := range lines { wrapped := linewrap.SingleLine(line, r.Width, 0, 0, linewrap.Left) for _, w := range wrapped { dst.DrawLabel(r, &t.textParams, []byte(w)) r.Y++ if r.Y > max { return } } } }
func (ac *autocompl) draw_onto(buf *tulib.Buffer, x, y int) { ac.validate_cursor() h := ac.desired_height() dst := find_place_for_rect(buf.Rect, tulib.Rect{x, y + 1, 1, h}) ac.adjust_view(dst.Height) w := ac.desired_width(dst.Height) dst = find_place_for_rect(buf.Rect, tulib.Rect{x, y + 1, w, h}) slider_i, slider_r := ac.slider_pos_and_rune(dst.Height) lp := default_label_params r := dst r.Width-- r.Height = 1 for i := 0; i < dst.Height; i++ { lp.Fg = termbox.ColorBlack lp.Bg = termbox.ColorWhite n := ac.view + i if n == ac.cursor { lp.Fg = termbox.ColorWhite lp.Bg = termbox.ColorBlue } buf.Fill(r, termbox.Cell{ Fg: lp.Fg, Bg: lp.Bg, Ch: ' ', }) buf.DrawLabel(r, &lp, ac.actual_proposals()[n].display) sr := ' ' if i == slider_i { sr = slider_r } buf.Set(r.X+r.Width, r.Y, termbox.Cell{ Fg: termbox.ColorWhite, Bg: termbox.ColorBlue, Ch: sr, }) r.Y++ } }
// drawCursor draws the cursor. func (i *Input) drawCursor(dst *tulib.Buffer) { if !i.focus { return } r := i.rect if r.Width < 0 || r.Height < 0 { return } cs := i.cursorPos r.X += len(i.prompt) + cs r.Width = 1 var data []byte if cs >= len(i.text) { data = []byte{' '} } else { data = []byte(string(i.text[cs : cs+1])) } dst.DrawLabel(r, &i.cursorParams, data) }
func (v *TextView) PaintTo(buffer *tulib.Buffer, rect Rect) error { clearRect(buffer, rect) buffer.DrawLabel(rect.TulibRect(), v.params, v.text) return nil }