Skip to content

Commit

Permalink
DisplayOptions: "Dec"/"Inc" operations in the function bar
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hishamhm authored and BenBE committed Feb 20, 2025
1 parent b2e86aa commit 3b7aa07
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions DisplayOptionsPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ in the source distribution for its full text.

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

static const char* const DisplayOptionsDecIncFunctions[] = {"Dec ", "Inc ", " ", "Done ", NULL};
static const char* const DisplayOptionsDecIncKeys[] = {"- ", "+ ", " ", "F10", NULL};
static const int DisplayOptionsDecIncEvents[] = {'-', '+', ERR, KEY_F(10)};

static void DisplayOptionsPanel_delete(Object* object) {
Panel* super = (Panel*) object;
DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
FunctionBar_delete(this->decIncBar);
Panel_done(super);
free(this);
}
Expand Down Expand Up @@ -73,6 +78,28 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
result = HANDLED;
}
break;
case KEY_UP:
case KEY_DOWN:
case KEY_NPAGE:
case KEY_PPAGE:
case KEY_HOME:
case KEY_END:
{
OptionItem* previous = selected;
Panel_onKey(super, ch);
selected = (OptionItem*) Panel_getSelected(super);
if (previous != selected) {
result = HANDLED;
}
}
/* fallthrough */
case EVENT_SET_SELECTED:
if (OptionItem_kind(selected) == OPTION_ITEM_NUMBER) {
super->currentBar = this->decIncBar;
} else {
Panel_setDefaultBar(super);
}
break;
}

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

this->decIncBar = FunctionBar_new(DisplayOptionsDecIncFunctions, DisplayOptionsDecIncKeys, DisplayOptionsDecIncEvents);
this->settings = settings;
this->scr = scr;

Expand Down
2 changes: 2 additions & 0 deletions DisplayOptionsPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

#include "FunctionBar.h"
#include "Panel.h"
#include "ScreenManager.h"
#include "Settings.h"
Expand All @@ -17,6 +18,7 @@ typedef struct DisplayOptionsPanel_ {

Settings* settings;
ScreenManager* scr;
FunctionBar* decIncBar;
} DisplayOptionsPanel;

extern const PanelClass DisplayOptionsPanel_class;
Expand Down

0 comments on commit 3b7aa07

Please sign in to comment.