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

Expose SetDirty #505

Closed
microo8 opened this issue Dec 2, 2021 · 1 comment
Closed

Expose SetDirty #505

microo8 opened this issue Dec 2, 2021 · 1 comment

Comments

@microo8
Copy link

microo8 commented Dec 2, 2021

After this time, I think this #436 PR isn't going to be merged so I think there could be a simpler way.
What if we leave image tracking on the user, and just expose SetDirty(x, y int, dirty bool) method.

I'm working on a app that shows some images. I know the positions and regions these images occupy.
When the screen changes (I scroll down or something), I can calculate cells that need to be redrawn.
Just need the SetDirty function to force tcell to redraw the cells.
I was already thinking about some hacky ways, that I can set the backgroud color to a darker/lighter, then
screen.Show() and then right back to the original color. But that's not pretty.
Using screen.Sync() is too slow and the screen and all the images blink too much.

Would this be possible? Just expose SetDirty?

@microo8 microo8 changed the title SetDirtyRegion Expose SetDirty Dec 2, 2021
@microo8
Copy link
Author

microo8 commented Dec 2, 2021

So I made it. I think it's hacky, but it's less work.
Before, there where just spaces in the area where the image was.
Now I Set the area to unicode's Braille Blank (or just the rune '\u2800')
I think it is the same width and tcell is forced to redraw the areas where the image was before,
because on the new frame, there are no Braille Blanks, just spaces.

so just:

var imageArea image.Rect = calculateImageArea()
for x := imageArea.Min.X; x < imageArea.Max.X; x++ {
    for y := imageArea.Min.Y; y < imageArea.Max.Y; y++ {
        s.SetContent(x+ctx.X, y+ctx.Y, '\u2800', nil, tcell.StyleDefault)
    }
}

and when there's no image just:

s.SetContent(x+ctx.X, y+ctx.Y, ' ', nil, tcell.StyleDefault)

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

1 participant