diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-06-01 20:21:25 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2024-06-23 12:53:15 +0200 |
commit | 20a4aeab6e92c8f16fa02783c750b86558d8fb51 (patch) | |
tree | be5c7b57ed157c65304aa90fbc6e9e3f5cc32f6f /pkg | |
parent | a5620ebe3a9665908d39a2e668589b2c8a2e8112 (diff) |
Support showing checkboxes or radio buttons in menus
For checkboxes it probably doesn't really make sense to use them yet, because
we'd have to find a way how you can toggle them without closing the dialog; but
we already provide rendering for them to lay the ground.
But radio buttons can be used already, because for those it is ok to close the
dialog when choosing a different option (as long as there is only one grounp of
radio buttons in the panel, that is).
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/context/menu_context.go | 16 | ||||
-rw-r--r-- | pkg/gui/types/common.go | 30 |
2 files changed, 45 insertions, 1 deletions
diff --git a/pkg/gui/context/menu_context.go b/pkg/gui/context/menu_context.go index e4b26f884..f1438b221 100644 --- a/pkg/gui/context/menu_context.go +++ b/pkg/gui/context/menu_context.go @@ -107,7 +107,21 @@ func (self *MenuViewModel) GetDisplayStrings(_ int, _ int) [][]string { keyLabel = style.FgCyan.Sprint(keybindings.LabelFromKey(item.Key)) } - displayStrings = utils.Prepend(displayStrings, keyLabel) + checkMark := "" + switch item.Widget { + case types.MenuWidgetNone: + // do nothing + case types.MenuWidgetRadioButtonSelected: + checkMark = "(•)" + case types.MenuWidgetRadioButtonUnselected: + checkMark = "( )" + case types.MenuWidgetCheckboxSelected: + checkMark = "[✓]" + case types.MenuWidgetCheckboxUnselected: + checkMark = "[ ]" + } + + displayStrings = utils.Prepend(displayStrings, keyLabel, checkMark) return displayStrings }) } diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go index fc9168406..61c27de49 100644 --- a/pkg/gui/types/common.go +++ b/pkg/gui/types/common.go @@ -217,6 +217,30 @@ type DisabledReason struct { ShowErrorInPanel bool } +type MenuWidget int + +const ( + MenuWidgetNone MenuWidget = iota + MenuWidgetRadioButtonSelected + MenuWidgetRadioButtonUnselected + MenuWidgetCheckboxSelected + MenuWidgetCheckboxUnselected +) + +func MakeMenuRadioButton(value bool) MenuWidget { + if value { + return MenuWidgetRadioButtonSelected + } + return MenuWidgetRadioButtonUnselected +} + +func MakeMenuCheckBox(value bool) MenuWidget { + if value { + return MenuWidgetCheckboxSelected + } + return MenuWidgetCheckboxUnselected +} + type MenuItem struct { Label string @@ -232,6 +256,12 @@ type MenuItem struct { // item, as opposed to having to navigate to it Key Key + // A widget to show in front of the menu item. Supported widget types are + // checkboxes and radio buttons, + // This only handles the rendering of the widget; the behavior needs to be + // provided by the client. + Widget MenuWidget + // The tooltip will be displayed upon highlighting the menu item Tooltip string |