chore: ⬆️ updated deps
This commit is contained in:
+36
-21
@@ -107,23 +107,30 @@ s.SetStyle(defStyle)
|
||||
s.Clear()
|
||||
```
|
||||
|
||||
Text may be drawn on the screen using `SetContent`.
|
||||
Text may be drawn on the screen using `Put`, `PutStr`, or `PutStrStyled`.
|
||||
|
||||
```go
|
||||
s.SetContent(0, 0, 'H', nil, defStyle)
|
||||
s.SetContent(1, 0, 'i', nil, defStyle)
|
||||
s.SetContent(2, 0, '!', nil, defStyle)
|
||||
s.Put(0, 0, 'H', defStyle)
|
||||
s.Put(1, 0, 'i', defStyle)
|
||||
s.Put(2, 0, '!', defStyle)
|
||||
```
|
||||
|
||||
To draw text more easily, define a render function.
|
||||
which is equivalent to
|
||||
|
||||
```go
|
||||
s.PutStrStyled(0, 0, "Hi!", defStyle)
|
||||
````
|
||||
|
||||
To draw text more easily with wrapping, define a render function.
|
||||
|
||||
```go
|
||||
func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string) {
|
||||
row := y1
|
||||
col := x1
|
||||
for _, r := range []rune(text) {
|
||||
s.SetContent(col, row, r, nil, style)
|
||||
col++
|
||||
var width int
|
||||
for text != "" {
|
||||
text, width = s.Put(col, row, text, style)
|
||||
col += width
|
||||
if col >= x2 {
|
||||
row++
|
||||
col = x1
|
||||
@@ -131,6 +138,10 @@ func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string
|
||||
if row > y2 {
|
||||
break
|
||||
}
|
||||
if width == 0 {
|
||||
// incomplete grapheme at end of string
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -178,9 +189,10 @@ import (
|
||||
func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string) {
|
||||
row := y1
|
||||
col := x1
|
||||
for _, r := range []rune(text) {
|
||||
s.SetContent(col, row, r, nil, style)
|
||||
col++
|
||||
var width int
|
||||
for text != "" {
|
||||
text, width = s.Put(col, row, text, style)
|
||||
col += width
|
||||
if col >= x2 {
|
||||
row++
|
||||
col = x1
|
||||
@@ -188,6 +200,10 @@ func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string
|
||||
if row > y2 {
|
||||
break
|
||||
}
|
||||
if width == 0 {
|
||||
// incomplete grapheme at end of string
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,26 +218,26 @@ func drawBox(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string)
|
||||
// Fill background
|
||||
for row := y1; row <= y2; row++ {
|
||||
for col := x1; col <= x2; col++ {
|
||||
s.SetContent(col, row, ' ', nil, style)
|
||||
s.Put(col, row, " ", style)
|
||||
}
|
||||
}
|
||||
|
||||
// Draw borders
|
||||
for col := x1; col <= x2; col++ {
|
||||
s.SetContent(col, y1, tcell.RuneHLine, nil, style)
|
||||
s.SetContent(col, y2, tcell.RuneHLine, nil, style)
|
||||
s.Put(col, y1, string(tcell.RuneHLine), style)
|
||||
s.Put(col, y2, string(tcell.RuneHLine), style)
|
||||
}
|
||||
for row := y1 + 1; row < y2; row++ {
|
||||
s.SetContent(x1, row, tcell.RuneVLine, nil, style)
|
||||
s.SetContent(x2, row, tcell.RuneVLine, nil, style)
|
||||
s.Put(x1, row, string(tcell.RuneVLine), style)
|
||||
s.Put(x2, row, string(tcell.RuneVLine), style)
|
||||
}
|
||||
|
||||
// Only draw corners if necessary
|
||||
if y1 != y2 && x1 != x2 {
|
||||
s.SetContent(x1, y1, tcell.RuneULCorner, nil, style)
|
||||
s.SetContent(x2, y1, tcell.RuneURCorner, nil, style)
|
||||
s.SetContent(x1, y2, tcell.RuneLLCorner, nil, style)
|
||||
s.SetContent(x2, y2, tcell.RuneLRCorner, nil, style)
|
||||
s.Put(x1, y1, string(tcell.RuneULCorner), style)
|
||||
s.Put(x2, y1, string(tcell.RuneURCorner), style)
|
||||
s.Put(x1, y2, string(tcell.RuneLLCorner), style)
|
||||
s.Put(x2, y2, string(tcell.RuneLRCorner), style)
|
||||
}
|
||||
|
||||
drawText(s, x1+1, y1+1, x2-1, y2-1, style, text)
|
||||
@@ -310,4 +326,3 @@ func main() {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user