Skip to content

Commit

Permalink
Add increment and decrement controls for numeric display options
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmed Abouzied <[email protected]>
  • Loading branch information
ahmedaabouzied committed Aug 28, 2021
1 parent 3933302 commit 9716bff
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions DisplayOptionsPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ in the source distribution for its full text.
#include "ProvideCurses.h"


static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
static const char* const BooleanDisplayOptionsFunctions[] = {"Select ", "Done ", NULL};
static const char* const BooleanDisplayOptionsKeys[] = {"Enter", "F10", "Esc"};
static const int BooleanDisplayOptionsEvents[] = {KEY_ENTER, KEY_F(10), 27};
static const char* const NumericDisplayOptionsFunctions[] = {"Decrement ", "Increment ", "Done ", NULL};
static const char* const NumericDisplayOptionsKeys[] = {"-", "+", "F10", "Esc"};
static const int NumericDisplayOptionsEvents[] = {'-', '+', KEY_F(10), 27};

static void DisplayOptionsPanel_delete(Object* object) {
Panel* super = (Panel*) object;
Expand All @@ -29,13 +34,41 @@ static void DisplayOptionsPanel_delete(Object* object) {
free(this);
}

static void DisplayOptionsPanel_setFunctionBar(Panel* super, OptionItem* item) {
if (OptionItem_kind(item) == OPTION_ITEM_NUMBER) {
FunctionBar* fuBar = FunctionBar_new(NumericDisplayOptionsFunctions, NumericDisplayOptionsKeys, NumericDisplayOptionsEvents);
super->currentBar = fuBar;
} else {
FunctionBar* fuBar = FunctionBar_new(BooleanDisplayOptionsFunctions, BooleanDisplayOptionsKeys, BooleanDisplayOptionsEvents);
super->currentBar = fuBar;
}
FunctionBar_draw(super->currentBar);
}

static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;

HandlerResult result = IGNORED;
OptionItem* selected = (OptionItem*) Panel_getSelected(super);

switch (ch) {

case KEY_UP: {
int selected_index = Panel_getSelectedIndex(super);
if (selected_index > 1) {
OptionItem* next_to_select = (OptionItem*) Panel_get(super, selected_index - 1);
DisplayOptionsPanel_setFunctionBar(super, next_to_select);
}
break;
}
case KEY_DOWN: {
int selected_index = Panel_getSelectedIndex(super);
if (selected_index < Panel_size(super) - 1) {
OptionItem* next_to_select = (OptionItem*) Panel_get(super, selected_index + 1);
DisplayOptionsPanel_setFunctionBar(super, next_to_select);
}
break;
}
case '\n':
case '\r':
case KEY_ENTER:
Expand Down Expand Up @@ -90,8 +123,8 @@ const PanelClass DisplayOptionsPanel_class = {
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
DisplayOptionsPanel* this = AllocThis(DisplayOptionsPanel);
Panel* super = (Panel*) this;
FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL);
Panel_init(super, 1, 1, 1, 1, Class(OptionItem), true, fuBar);
FunctionBar* emptyFuBar = FunctionBar_new(NULL, NULL, NULL);
Panel_init(super, 1, 1, 1, 1, Class(OptionItem), true, emptyFuBar);

this->settings = settings;
this->scr = scr;
Expand Down Expand Up @@ -141,5 +174,9 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
#ifdef HAVE_LIBHWLOC
Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity)));
#endif

OptionItem* defaultSelected = (OptionItem*) Panel_getSelected(super);
DisplayOptionsPanel_setFunctionBar(super, defaultSelected);

return this;
}

0 comments on commit 9716bff

Please sign in to comment.