jroimartin / gocui

Minimalist Go package aimed at creating Console User Interfaces.
BSD 3-Clause "New" or "Revised" License
9.92k stars 608 forks source link

view titles #30

Closed dcu closed 8 years ago

dcu commented 9 years ago

hi,

is there a way to add a title to the view? If not, that'd be nice to have, it can be in the same level as the frame like https://github.com/gizak/termui does.

The syntax could be something like this:

if v, err := g.SetView(...); err != nil {
    v.Title = "Title"
    v.TitleAlign = "left|right|center"
}
jroimartin commented 9 years ago

I'd prefer to keep views as simple as possible, think on them just as buffers. In the case of needing a title, I would add another view above just with the title (one line height, you can disable borders, etc.)

jroimartin commented 8 years ago

I've implemented this feature based on the PR #36 from @conejoninja. You can check it on branch view-title commit bb01d13a959295e85f4eb6b4bf0cfdec6526252d. The main difference between my patch and the original PR is that I iterate over the title string, avoiding unnecessary iterations during the draw loop.

I've also added an example with all the test cases under _examples/title.go to test long titles, overlap between views, small views with title, etc.

Could you please check if it works as expected? :)

jroimartin commented 8 years ago

This is the output of _examples/title.go:

image

conejoninja commented 8 years ago

Looks good to me, no problems so far

jroimartin commented 8 years ago

Great. I've just merged it!