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

set background of a row #657

Closed
mortezadadgar opened this issue Dec 3, 2023 · 2 comments
Closed

set background of a row #657

mortezadadgar opened this issue Dec 3, 2023 · 2 comments

Comments

@mortezadadgar
Copy link

Hey,
sorry asking this as a issue there's no discussion to ask questions like this; as a personal project i have been trying to write a file explorer program to list files or directory based of their size so all i'm trying to is to set the background of a row in ui like this
512KiB Go <- I want the current selection row to have a separate background as others
128KiB C
I can set the background of size text and file/dirs individually which results into:
image
as you can see there's a space between them which is not affected by changing the style as they have different x position
this is the function that i used to draw this tree:

func drawTree(dirs []fileAttr, screen tcell.Screen) {
	styleSizes := tcell.StyleDefault.Background(tcell.ColorBlack).Foreground(tcell.ColorYellow).Bold(true)

	var y int
	var style tcell.Style
	for i, dir := range dirs {
		var size string
		if i == currentSel {
			style = style.Background(tcell.ColorWhite).Foreground(tcell.ColorBlack)
		} else {
			style = style.Background(tcell.ColorBlack).Foreground(tcell.ColorWhite)
		}
		size = strconv.Itoa(dir.size / 1024 / 1024)
		drawText(screen, 4, y, style, "MiB")
		drawText(screen, 0, y, styleSizes, size)
		drawText(screen, 10, y, style, dir.name)
		y++
	}
}

one way i can think of is to change x position of remaining spaces between 4 and 10 but that would be so hacky

@gdamore
Copy link
Owner

gdamore commented Dec 3, 2023

If you want to only change the style without changing the text you can do that. I thought I had created a SetStyle API, but it looks for setting the style on a given cell, but it looks like I didn't for some reason.

Anyway, you can do GetContent() , and then change the Style return value, and pass the results back to SetContent(). You can just iterate over all the cells.

I'll see if I can provide some better convenience functions for this, because changing the style seems super useful.

(I can also see wanting to have an API to quickly change the style of a region. So I might look at that too.)

@gdamore
Copy link
Owner

gdamore commented Dec 4, 2023

This is really a duplicate of #579 ... so I'm closing it as such.

Note that I do intend to implement this functionality, which is why I've made some other changes to reduce code duplicate in the repo today.

@gdamore gdamore closed this as completed Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants