mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
add optional tooltip to menu widget
This commit is contained in:
@@ -11,13 +11,14 @@ type Padding [2]int // x,y padding
|
||||
type Menu struct {
|
||||
ui.Block
|
||||
SortItems bool // enable automatic sorting of menu items
|
||||
Selectable bool // whether menu is navigable
|
||||
SubText string // optional text to display before items
|
||||
TextFgColor ui.Attribute
|
||||
TextBgColor ui.Attribute
|
||||
Selectable bool
|
||||
cursorPos int
|
||||
items Items
|
||||
padding Padding
|
||||
toolTip *ToolTip
|
||||
}
|
||||
|
||||
func NewMenu() *Menu {
|
||||
@@ -71,13 +72,9 @@ func (m *Menu) SetCursor(s string) (success bool) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Sort menu items(if enabled) and re-calculate window size
|
||||
func (m *Menu) refresh() {
|
||||
if m.SortItems {
|
||||
sort.Sort(m.items)
|
||||
}
|
||||
m.calcSize()
|
||||
ui.Render(m)
|
||||
// SetToolTip sets an optional tooltip string to show at bottom of screen
|
||||
func (m *Menu) SetToolTip(lines ...string) {
|
||||
m.toolTip = NewToolTip(lines...)
|
||||
}
|
||||
|
||||
func (m *Menu) SelectedItem() Item {
|
||||
@@ -117,6 +114,10 @@ func (m *Menu) Buffer() ui.Buffer {
|
||||
}
|
||||
}
|
||||
|
||||
if m.toolTip != nil {
|
||||
buf.Merge(m.toolTip.Buffer())
|
||||
}
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
@@ -134,6 +135,15 @@ func (m *Menu) Down() {
|
||||
}
|
||||
}
|
||||
|
||||
// Sort menu items(if enabled) and re-calculate window size
|
||||
func (m *Menu) refresh() {
|
||||
if m.SortItems {
|
||||
sort.Sort(m.items)
|
||||
}
|
||||
m.calcSize()
|
||||
ui.Render(m)
|
||||
}
|
||||
|
||||
// Set width and height based on menu items
|
||||
func (m *Menu) calcSize() {
|
||||
m.Width = 7 // minimum width
|
||||
|
||||
Reference in New Issue
Block a user