Skip to content

Commit 5bb71f9

Browse files
committed
DisplayOptions: "Inc"/"Dec" 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 increasable/decreasable using the mouse as well.
1 parent b2e86aa commit 5bb71f9

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

CommandLine.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ in the source distribution for its full text.
3232
#include "Machine.h"
3333
#include "MainPanel.h"
3434
#include "MetersPanel.h"
35+
#include "DisplayOptionsPanel.h"
3536
#include "Panel.h"
3637
#include "Platform.h"
3738
#include "Process.h"
@@ -425,6 +426,7 @@ int CommandLine_run(int argc, char** argv) {
425426

426427
ScreenManager_delete(scr);
427428
MetersPanel_cleanup();
429+
DisplayOptionsPanel_cleanup();
428430

429431
UsersTable_delete(ut);
430432

DisplayOptionsPanel.c

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

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

27+
static const char* const DisplayOptionsIncDecFunctions[] = {"Inc ", "Dec ", " ", "Done ", NULL};
28+
static const char* const DisplayOptionsIncDecKeys[] = {"+ ", "- ", " ", "F10", NULL};
29+
static const int DisplayOptionsIncDecEvents[] = {'+', '-', ERR, KEY_F(10)};
30+
static FunctionBar* DisplayOptions_incDecBar = NULL;
31+
32+
void DisplayOptionsPanel_cleanup(void) {
33+
if (DisplayOptions_incDecBar) {
34+
FunctionBar_delete(DisplayOptions_incDecBar);
35+
DisplayOptions_incDecBar = NULL;
36+
}
37+
}
38+
2739
static void DisplayOptionsPanel_delete(Object* object) {
2840
Panel* super = (Panel*) object;
2941
DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
@@ -73,6 +85,28 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
7385
result = HANDLED;
7486
}
7587
break;
88+
case KEY_UP:
89+
case KEY_DOWN:
90+
case KEY_NPAGE:
91+
case KEY_PPAGE:
92+
case KEY_HOME:
93+
case KEY_END:
94+
{
95+
OptionItem* previous = selected;
96+
Panel_onKey(super, ch);
97+
selected = (OptionItem*) Panel_getSelected(super);
98+
if (previous != selected) {
99+
result = HANDLED;
100+
}
101+
}
102+
/* fallthrough */
103+
case EVENT_SET_SELECTED:
104+
if (OptionItem_kind(selected) == OPTION_ITEM_NUMBER) {
105+
super->currentBar = DisplayOptions_incDecBar;
106+
} else {
107+
Panel_setDefaultBar(super);
108+
}
109+
break;
76110
}
77111

78112
if (result == HANDLED) {
@@ -104,6 +138,10 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
104138
FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL);
105139
Panel_init(super, 1, 1, 1, 1, Class(OptionItem), true, fuBar);
106140

141+
if (!DisplayOptions_incDecBar) {
142+
DisplayOptions_incDecBar = FunctionBar_new(DisplayOptionsIncDecFunctions, DisplayOptionsIncDecKeys, DisplayOptionsIncDecEvents);
143+
}
144+
107145
this->settings = settings;
108146
this->scr = scr;
109147

DisplayOptionsPanel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ typedef struct DisplayOptionsPanel_ {
2121

2222
extern const PanelClass DisplayOptionsPanel_class;
2323

24+
void DisplayOptionsPanel_cleanup(void);
25+
2426
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr);
2527

2628
#endif

0 commit comments

Comments
 (0)