[GH-ISSUE #747] Allow overriding border runes per instance of Box #548

Open
opened 2026-03-04 01:05:55 +03:00 by kerem · 3 comments
Owner

Originally created by @moson-mo on GitHub (Jul 23, 2022).
Original GitHub issue: https://github.com/rivo/tview/issues/747

Borders of focused elements are drawn differently than for unfocused ones (thicker / double lines).

Would be nice if there is a method to control that behavior.
While it's possible to override the runes that are used for focused elements globally, one might want to have this for specific boxes/containers only.

The only way to work around it is to use SetDrawFunc and draw the borders yourself I guess?

I'm thinking about a boolean like borderIgnoreFocus added to the Box struct with a method SetBorderIgnoreFocus(ignore bool) which can then be checked in the DrawForSubclass

https://github.com/rivo/tview/issues/747#issuecomment-1198967978

Originally created by @moson-mo on GitHub (Jul 23, 2022). Original GitHub issue: https://github.com/rivo/tview/issues/747 Borders of focused elements are drawn differently than for unfocused ones (thicker / double lines). Would be nice if there is a method to control that behavior. While it's possible to override the runes that are used for focused elements globally, one might want to have this for specific boxes/containers only. The only way to work around it is to use SetDrawFunc and draw the borders yourself I guess? ~~I'm thinking about a boolean like `borderIgnoreFocus` added to the Box struct with a method `SetBorderIgnoreFocus(ignore bool)` which can then be checked in the `DrawForSubclass`~~ https://github.com/rivo/tview/issues/747#issuecomment-1198967978
Author
Owner

@moson-mo commented on GitHub (Jul 29, 2022):

switch it in an overloaded Draw func

This assumes you use your own primitives though, or I'm missing something 🤔
I want to be able to override what characters are used to print the borders per instance (not type) of a component. Also the built-in ones.

E.g. you have 5 nested Flex components. For the top 3, I want to print single borders.

This would make it possible: github.com/moson-mo/tview@2571a960ab

Example:

// Demo code for the Box primitive.
package main

import (
	"github.com/gdamore/tcell/v2"
	"github.com/rivo/tview"
)

var myStyle = &tview.BoxBorders{
	Horizontal:  tview.BoxDrawingsLightHorizontal,
	Vertical:    tview.BoxDrawingsLightVertical,
	TopLeft:     tview.BoxDrawingsLightArcDownAndRight,
	TopRight:    tview.BoxDrawingsLightArcDownAndLeft,
	BottomLeft:  tview.BoxDrawingsLightArcUpAndRight,
	BottomRight: tview.BoxDrawingsLightArcUpAndLeft,

	HorizontalFocus:  tview.BoxDrawingsLightHorizontal,
	VerticalFocus:    tview.BoxDrawingsLightVertical,
	TopLeftFocus:     tview.BoxDrawingsLightArcDownAndRight,
	TopRightFocus:    tview.BoxDrawingsLightArcDownAndLeft,
	BottomLeftFocus:  tview.BoxDrawingsLightArcUpAndRight,
	BottomRightFocus: tview.BoxDrawingsLightArcUpAndLeft,
}

func main() {
	flex := tview.NewFlex()
	box := tview.NewBox().
		SetBorder(true).
		SetBorderAttributes(tcell.AttrBold).
		SetTitle("A [red]c[yellow]o[green]l[darkcyan]o[blue]r[darkmagenta]f[red]u[yellow]l[white] [black:red]c[:yellow]o[:green]l[:darkcyan]o[:blue]r[:darkmagenta]f[:red]u[:yellow]l[white:] [::bu]title")
	flex.AddItem(box, 0, 1, true).
		SetBorder(true).
		SetCustomBorders(myStyle)
	if err := tview.NewApplication().SetRoot(flex, true).Run(); err != nil {
		panic(err)
	}
}

Don't know if this has a chance of being merged ?

<!-- gh-comment-id:1198967978 --> @moson-mo commented on GitHub (Jul 29, 2022): > switch it in an overloaded Draw func This assumes you use your own primitives though, or I'm missing something 🤔 I want to be able to override what characters are used to print the borders per instance (not type) of a component. Also the built-in ones. E.g. you have 5 nested `Flex` components. For the top 3, I want to print single borders. This would make it possible: https://github.com/moson-mo/tview/commit/2571a960ab9763ccb763316d876f90f80e8f51ac Example: ```go // Demo code for the Box primitive. package main import ( "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) var myStyle = &tview.BoxBorders{ Horizontal: tview.BoxDrawingsLightHorizontal, Vertical: tview.BoxDrawingsLightVertical, TopLeft: tview.BoxDrawingsLightArcDownAndRight, TopRight: tview.BoxDrawingsLightArcDownAndLeft, BottomLeft: tview.BoxDrawingsLightArcUpAndRight, BottomRight: tview.BoxDrawingsLightArcUpAndLeft, HorizontalFocus: tview.BoxDrawingsLightHorizontal, VerticalFocus: tview.BoxDrawingsLightVertical, TopLeftFocus: tview.BoxDrawingsLightArcDownAndRight, TopRightFocus: tview.BoxDrawingsLightArcDownAndLeft, BottomLeftFocus: tview.BoxDrawingsLightArcUpAndRight, BottomRightFocus: tview.BoxDrawingsLightArcUpAndLeft, } func main() { flex := tview.NewFlex() box := tview.NewBox(). SetBorder(true). SetBorderAttributes(tcell.AttrBold). SetTitle("A [red]c[yellow]o[green]l[darkcyan]o[blue]r[darkmagenta]f[red]u[yellow]l[white] [black:red]c[:yellow]o[:green]l[:darkcyan]o[:blue]r[:darkmagenta]f[:red]u[:yellow]l[white:] [::bu]title") flex.AddItem(box, 0, 1, true). SetBorder(true). SetCustomBorders(myStyle) if err := tview.NewApplication().SetRoot(flex, true).Run(); err != nil { panic(err) } } ``` Don't know if this has a chance of being merged ?
Author
Owner

@rivo commented on GitHub (Aug 11, 2022):

This is a bit like #692. It looks like everybody wants something different for their borders.

I'm planning to add more general customization options for primitives that will go beyond a simple "change the code points used to draw a border". (It's one of the major features that have been requested a lot.) But it'll have to wait. Currently, I'm working on a text area which was by far voted as most important and it's a major project on its own.

<!-- gh-comment-id:1212433526 --> @rivo commented on GitHub (Aug 11, 2022): This is a bit like #692. It looks like everybody wants something different for their borders. I'm planning to add more general customization options for primitives that will go beyond a simple "change the code points used to draw a border". (It's one of the major features that have been requested a lot.) But it'll have to wait. Currently, I'm working on a [text area](https://github.com/rivo/tview/tree/textarea) which was by far voted as most important and it's a major project on its own.
Author
Owner

@golangdojo99 commented on GitHub (Sep 27, 2022):

@rivo, any updates on adding this?

<!-- gh-comment-id:1259215878 --> @golangdojo99 commented on GitHub (Sep 27, 2022): @rivo, any updates on adding this?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#548
No description provided.