blob: d44a8549a6fef1ecd350400f73f74acd1523f73a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package widgets
import (
"strings"
"github.com/gizak/termui/v3/widgets"
"github.com/xxxserxxx/lingo/v2"
)
// Used by all widgets
var tr lingo.Translations
type HelpMenu struct {
widgets.Paragraph
}
func NewHelpMenu(tra lingo.Translations) *HelpMenu {
tr = tra
help := &HelpMenu{
Paragraph: *widgets.NewParagraph(),
}
help.Paragraph.Text = tra.Value("help.help")
return help
}
func (help *HelpMenu) Resize(termWidth, termHeight int) {
textWidth := 53
var nlines int
var line string
for nlines, line = range strings.Split(help.Text, "\n") {
if textWidth < len(line) {
textWidth = len(line) + 2
}
}
textHeight := nlines + 2
x := (termWidth - textWidth) / 2
y := (termHeight - textHeight) / 2
help.Paragraph.SetRect(x, y, textWidth+x, textHeight+y)
}
|