Skip to content

Commit 3b7aa07

Browse files
hishamhmBenBE
authored andcommitted
DisplayOptions: "Dec"/"Inc" operations in the function bar
For numeric entries in Display Options, this gives users a hint of which keys operate on the value, and allows the value to be decreasable/increasable using the mouse as well.
1 parent b2e86aa commit 3b7aa07

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

DisplayOptionsPanel.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ in the source distribution for its full text.
2424

2525
static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
2626

27+
static const char* const DisplayOptionsDecIncFunctions[] = {"Dec ", "Inc ", " ", "Done ", NULL};
28+
static const char* const DisplayOptionsDecIncKeys[] = {"- ", "+ ", " ", "F10", NULL};
29+
static const int DisplayOptionsDecIncEvents[] = {'-', '+', ERR, KEY_F(10)};
30+
2731
static void DisplayOptionsPanel_delete(Object* object) {
2832
Panel* super = (Panel*) object;
2933
DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
34+
FunctionBar_delete(this->decIncBar);
3035
Panel_done(super);
3136
free(this);
3237
}
@@ -73,6 +78,28 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
7378
result = HANDLED;
7479
}
7580
break;
81+
case KEY_UP:
82+
case KEY_DOWN:
83+
case KEY_NPAGE:
84+
case KEY_PPAGE:
85+
case KEY_HOME:
86+
case KEY_END:
87+
{
88+
OptionItem* previous = selected;
89+
Panel_onKey(super, ch);
90+
selected = (OptionItem*) Panel_getSelected(super);
91+
if (previous != selected) {
92+
result = HANDLED;
93+
}
94+
}
95+
/* fallthrough */
96+
case EVENT_SET_SELECTED:
97+
if (OptionItem_kind(selected) == OPTION_ITEM_NUMBER) {
98+
super->currentBar = this->decIncBar;
99+
} else {
100+
Panel_setDefaultBar(super);
101+
}
102+
break;
76103
}
77104

78105
if (result == HANDLED) {
@@ -104,6 +131,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
104131
FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL);
105132
Panel_init(super, 1, 1, 1, 1, Class(OptionItem), true, fuBar);
106133

134+
this->decIncBar = FunctionBar_new(DisplayOptionsDecIncFunctions, DisplayOptionsDecIncKeys, DisplayOptionsDecIncEvents);
107135
this->settings = settings;
108136
this->scr = scr;
109137

DisplayOptionsPanel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Released under the GNU GPLv2+, see the COPYING file
77
in the source distribution for its full text.
88
*/
99

10+
#include "FunctionBar.h"
1011
#include "Panel.h"
1112
#include "ScreenManager.h"
1213
#include "Settings.h"
@@ -17,6 +18,7 @@ typedef struct DisplayOptionsPanel_ {
1718

1819
Settings* settings;
1920
ScreenManager* scr;
21+
FunctionBar* decIncBar;
2022
} DisplayOptionsPanel;
2123

2224
extern const PanelClass DisplayOptionsPanel_class;

0 commit comments

Comments
 (0)