2018-02-18 23:25:02 -08:00
|
|
|
package widgets
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2021-02-16 16:24:34 -06:00
|
|
|
"github.com/gizak/termui/v3/widgets"
|
2021-02-03 12:28:46 -06:00
|
|
|
lingo "github.com/xxxserxxx/lingo"
|
2018-02-18 23:25:02 -08:00
|
|
|
)
|
|
|
|
|
2021-02-16 16:24:34 -06:00
|
|
|
// Used by all widgets
|
2020-05-05 08:13:25 -05:00
|
|
|
var tr lingo.Translations
|
2018-02-18 23:25:02 -08:00
|
|
|
|
|
|
|
type HelpMenu struct {
|
2021-02-16 16:24:34 -06:00
|
|
|
widgets.Paragraph
|
2018-02-18 23:25:02 -08:00
|
|
|
}
|
|
|
|
|
2020-05-05 08:13:25 -05:00
|
|
|
func NewHelpMenu(tra lingo.Translations) *HelpMenu {
|
|
|
|
tr = tra
|
2021-02-16 16:24:34 -06:00
|
|
|
help := &HelpMenu{
|
|
|
|
Paragraph: *widgets.NewParagraph(),
|
2018-12-31 16:55:50 -08:00
|
|
|
}
|
2021-02-16 16:24:34 -06:00
|
|
|
help.Paragraph.Text = tra.Value("help.help")
|
|
|
|
return help
|
2018-02-18 23:25:02 -08:00
|
|
|
}
|
|
|
|
|
2020-04-27 20:33:41 -05:00
|
|
|
func (help *HelpMenu) Resize(termWidth, termHeight int) {
|
2018-12-31 16:55:50 -08:00
|
|
|
textWidth := 53
|
2021-02-16 16:24:34 -06:00
|
|
|
var nlines int
|
|
|
|
var line string
|
|
|
|
for nlines, line = range strings.Split(help.Text, "\n") {
|
2020-04-16 10:18:00 -05:00
|
|
|
if textWidth < len(line) {
|
|
|
|
textWidth = len(line) + 2
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 16:24:34 -06:00
|
|
|
textHeight := nlines + 2
|
2018-12-31 16:55:50 -08:00
|
|
|
x := (termWidth - textWidth) / 2
|
|
|
|
y := (termHeight - textHeight) / 2
|
|
|
|
|
2021-02-16 16:24:34 -06:00
|
|
|
help.Paragraph.SetRect(x, y, textWidth+x, textHeight+y)
|
2019-07-15 16:06:37 -07:00
|
|
|
}
|