Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change List border to single line #933

Open
abitrolly opened this issue Jan 5, 2024 · 8 comments
Open

Change List border to single line #933

abitrolly opened this issue Jan 5, 2024 · 8 comments

Comments

@abitrolly
Copy link
Contributor

After calling list.SetBorder(true) (see the code below) the default width of https://pkg.go.dev/github.com/rivo/tview#List is double line.

image

I want to change that to single line, but can't find the API. There are two functions that may do this, but it is not clear what parameters they get and what is the effect.

If changing the style is possible, an example would be appreciated.

package main

import (
	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()
	list := tview.NewList().
		AddItem("List item 1", "Some explanatory text", 'a', nil).
		AddItem("List item 2", "Some explanatory text", 'b', nil).
		AddItem("List item 3", "Some explanatory text", 'c', nil).
		AddItem("List item 4", "Some explanatory text", 'd', nil).
		AddItem("Quit", "Press to exit", 'q', func() {
			app.Stop()
		})
	list.SetBorder(true) // <-- this adds double borders
	if err := app.SetRoot(list, true).SetFocus(list).Run(); err != nil {
		panic(err)
	}
}
@digitallyserviced
Copy link
Contributor

digitallyserviced commented Jan 5, 2024

@abitrolly
This is rather simple. However it will change it across every widget that uses a border and has focus.

reference borders.go for the changeable border sections

tview.Borders.HorizontalFocus = tview.BoxDrawingsHeavyHorizontal
tview.Borders.VerticalFocus = tview.BoxDrawingsHeavyVertical
tview.Borders.TopLeftFocus = tview.BoxDrawingsHeavyDownAndRight
tview.Borders.TopRightFocus = tview.BoxDrawingsHeavyDownAndLeft
tview.Borders.BottomLeftFocus = tview.BoxDrawingsHeavyUpAndRight
tview.Borders.BottomRightFocus = tview.BoxDrawingsHeavyUpAndLeft

reference semigraphics.go for the border graphic names you can use

The ability to set specific borders on individual widgets is not available in the current tview. I do however have a fork that allows this to be set on the Box that all widgets subclass.
However, my fork box.go has far more changes than simply the border definition feature.

https://github.com/digitallyserviced/tview/blob/611a26b9bad195005135a6ce0215280c68d57903/box.go#L411-L415

Anyhow that link should give you a starting point to hack in the ability for setting different border styles per primitive/widget/box

@abitrolly
Copy link
Contributor Author

Thanks for the confirmation that tview currently doesn't allow to set border drawing chars for separate components. )

Nice to see that it is already implemented in the fork. I think tview could adopt the BorderStyle structure.

https://github.com/digitallyserviced/tview/blob/digitally/borders.go#L5

I guess it is even possible to preserve existing properties of tcell.Style that is passed to current version of tview Box.SetBorderStyle(), so that API is backwards compatible.

@abitrolly
Copy link
Contributor Author

Found #747 with the request to dynamically set border rules.

@digitallyserviced
Copy link
Contributor

digitallyserviced commented Jan 7, 2024

Found #747 with the request to dynamically set border rules.
@abitrolly
Yah, you can also see a few PR's that me, and others have submitted to add features, but do not seem to get much attention or consideration and just dangle.

I wish I could give you some promising news about it being avialable in original tview, but I gave up trying to make PR's for many of the changes I've done to my fork (there's a lot).

You can also see that tslocum has quite a few PR's submitted that he just gave up and began integrating into his own fork tslocum/cview but both tview/cview dont have all the things that my fork has done.

Here is a bit of a preview of my own app using my tview fork's differences.

265284960-f36d2cc4-6e58-45e4-ab00-d4602495d66a

@digitallyserviced
Copy link
Contributor

digitallyserviced commented Jan 7, 2024

@abitrolly
Also I will put this here as a reference.

If you were looking for more detailed styling support. My app uses this for being able to define styles in textviews/anywhere you would do [fg:bg:attr] and can setup a named style with the 3 params, and then use the name instead where [labelColor] would translate to the same fg:bg:attr that you define.

Also my tview-theming has support for a theme.toml to define strings and formatting in such a way to be watch/auto-reloaded when developing.

https://github.com/digitallyserviced/tview-theming

[FormatStrings]
badgeThreeLineField = '''[badgeText]       [#303030:-] [:#505050]
[badgeText] [::r]%[1]s [:#303030:-] [#303030:-] [:#505050]
[badgeText]     [#303030:-] [:#505050]'''

[TagStyles]

  [TagStyles.badgeText]
    Attributes = "b"
    BG = "#303030"
    FG = "magenta"

@abitrolly
Copy link
Contributor Author

@digitallyserviced the biggest challenge in maintaining (public) libraries is to design interfaces in future compatible manner. Do not break things, and ensure that future extensibility is possible. I see that at least your Box.SetBorderStyle implementation breaks API, so that's one reason to avoid the change.

As for your other changes, they don't seem to be related to single or double line problem.

@carpii
Copy link
Sponsor Contributor

carpii commented Jan 17, 2024

@digitallyserviced - You regularly promote your fork, and indeed you seem to have made a lot of improvements to it.

But the problem is, it's a big bunch of undocumented changes.
No serious developer is going to switch from an official repo to a random fork where none of the changes have been documented.

@digitallyserviced
Copy link
Contributor

digitallyserviced commented Apr 28, 2024

@digitallyserviced - You regularly promote your fork, and indeed you seem to have made a lot of improvements to it.

But the problem is, it's a big bunch of undocumented changes. No serious developer is going to switch from an official repo to a random fork where none of the changes have been documented.

I never expected anyone to siwtch to it, which is why it's never actually advertised as something to do. rather it is a tool to reference and gain insight.

I completely agree, ye sit's not ready for production or main-stream use. However, it is a useful tool fo gai insight, and ideas about how to go about doing things that aren't available currently, but with a bit of work and creativity, it can be implemented.

@carpii @abitrolly

in no way am i trying to foce or push my fork on anyone. Most of it is yes it undocumented, and while it may not be for the common user/layman, it has been quite helpful to others who have wanted to cherry pick additional goodies.

My goal was never to replace, or make tview a competing framework, but rather as an example as the possibilities.

I just dont have the time to polish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants