diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2023-01-22 01:56:29 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2023-01-22 02:18:19 +0900 |
commit | d51980a3f50dfa8ce43b01a3dce216afb8a0bd8f (patch) | |
tree | 6041fc67bd7108153363a155b0c05348e65ee11d /src/tui | |
parent | c3d73e7ecbe56358949400f5314fee2d6976885a (diff) |
Add 'transform-border-label' and 'transform-preview-label'
Diffstat (limited to 'src/tui')
-rw-r--r-- | src/tui/light.go | 37 | ||||
-rw-r--r-- | src/tui/tcell.go | 30 | ||||
-rw-r--r-- | src/tui/tui.go | 1 |
3 files changed, 45 insertions, 23 deletions
diff --git a/src/tui/light.go b/src/tui/light.go index a336cac0..3ff4ded7 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -719,25 +719,38 @@ func (r *LightRenderer) NewWindow(top int, left int, width int, height int, prev w.fg = r.theme.Fg.Color w.bg = r.theme.Bg.Color } - w.drawBorder() + w.drawBorder(false) return w } -func (w *LightWindow) drawBorder() { +func (w *LightWindow) DrawHBorder() { + w.drawBorder(true) +} + +func (w *LightWindow) drawBorder(onlyHorizontal bool) { switch w.border.shape { case BorderRounded, BorderSharp, BorderBold, BorderDouble: - w.drawBorderAround() + w.drawBorderAround(onlyHorizontal) case BorderHorizontal: w.drawBorderHorizontal(true, true) case BorderVertical: + if onlyHorizontal { + return + } w.drawBorderVertical(true, true) case BorderTop: w.drawBorderHorizontal(true, false) case BorderBottom: w.drawBorderHorizontal(false, true) case BorderLeft: + if onlyHorizontal { + return + } w.drawBorderVertical(true, false) case BorderRight: + if onlyHorizontal { + return + } w.drawBorderVertical(false, true) } } @@ -779,23 +792,25 @@ func (w *LightWindow) drawBorderVertical(left, right bool) { } } -func (w *LightWindow) drawBorderAround() { +func (w *LightWindow) drawBorderAround(onlyHorizontal bool) { w.Move(0, 0) color := ColBorder if w.preview { color = ColPreviewBorder } hw := runewidth.RuneWidth(w.border.horizontal) - vw := runewidth.RuneWidth(w.border.vertical) tcw := runewidth.RuneWidth(w.border.topLeft) + runewidth.RuneWidth(w.border.topRight) bcw := runewidth.RuneWidth(w.border.bottomLeft) + runewidth.RuneWidth(w.border.bottomRight) rem := (w.width - tcw) % hw w.CPrint(color, string(w.border.topLeft)+repeat(w.border.horizontal, (w.width-tcw)/hw)+repeat(' ', rem)+string(w.border.topRight)) - for y := 1; y < w.height-1; y++ { - w.Move(y, 0) - w.CPrint(color, string(w.border.vertical)) - w.CPrint(color, repeat(' ', w.width-vw*2)) - w.CPrint(color, string(w.border.vertical)) + if !onlyHorizontal { + vw := runewidth.RuneWidth(w.border.vertical) + for y := 1; y < w.height-1; y++ { + w.Move(y, 0) + w.CPrint(color, string(w.border.vertical)) + w.CPrint(color, repeat(' ', w.width-vw*2)) + w.CPrint(color, string(w.border.vertical)) + } } w.Move(w.height-1, 0) rem = (w.width - bcw) % hw @@ -1040,7 +1055,7 @@ func (w *LightWindow) FinishFill() { } func (w *LightWindow) Erase() { - w.drawBorder() + w.drawBorder(false) // We don't erase the window here to avoid flickering during scroll w.Move(0, 0) } diff --git a/src/tui/tcell.go b/src/tui/tcell.go index 366cb775..ad0182cf 100644 --- a/src/tui/tcell.go +++ b/src/tui/tcell.go @@ -512,7 +512,7 @@ func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, height: height, normal: normal, borderStyle: borderStyle} - w.drawBorder() + w.drawBorder(false) return w } @@ -670,7 +670,11 @@ func (w *TcellWindow) CFill(fg Color, bg Color, a Attr, str string) FillReturn { return w.fillString(str, NewColorPair(fg, bg, a)) } -func (w *TcellWindow) drawBorder() { +func (w *TcellWindow) DrawHBorder() { + w.drawBorder(true) +} + +func (w *TcellWindow) drawBorder(onlyHorizontal bool) { shape := w.borderStyle.shape if shape == BorderNone { return @@ -718,17 +722,19 @@ func (w *TcellWindow) drawBorder() { _screen.SetContent(x, bot-1, w.borderStyle.horizontal, nil, style) } } - switch shape { - case BorderRounded, BorderSharp, BorderBold, BorderDouble, BorderVertical, BorderLeft: - for y := top; y < bot; y++ { - _screen.SetContent(left, y, w.borderStyle.vertical, nil, style) + if !onlyHorizontal { + switch shape { + case BorderRounded, BorderSharp, BorderBold, BorderDouble, BorderVertical, BorderLeft: + for y := top; y < bot; y++ { + _screen.SetContent(left, y, w.borderStyle.vertical, nil, style) + } } - } - switch shape { - case BorderRounded, BorderSharp, BorderBold, BorderDouble, BorderVertical, BorderRight: - vw := runewidth.RuneWidth(w.borderStyle.vertical) - for y := top; y < bot; y++ { - _screen.SetContent(right-vw, y, w.borderStyle.vertical, nil, style) + switch shape { + case BorderRounded, BorderSharp, BorderBold, BorderDouble, BorderVertical, BorderRight: + vw := runewidth.RuneWidth(w.borderStyle.vertical) + for y := top; y < bot; y++ { + _screen.SetContent(right-vw, y, w.borderStyle.vertical, nil, style) + } } } switch shape { diff --git a/src/tui/tui.go b/src/tui/tui.go index 5a86453b..203da76c 100644 --- a/src/tui/tui.go +++ b/src/tui/tui.go @@ -426,6 +426,7 @@ type Window interface { Width() int Height() int + DrawHBorder() Refresh() FinishFill() Close() |