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