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 Oct 30, 2021
1 parent 68c00b9 commit 6d7a5b9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
56 changes: 53 additions & 3 deletions DisplayOptionsPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,64 @@ in the source distribution for its full text.
#include "ProvideCurses.h"


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

static void DisplayOptionsPanel_delete(Object* object) {
Panel* super = (Panel*) object;
DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
FunctionBar_delete(this->numericFuBar);
FunctionBar_delete(this->checkboxFuBar);
Panel_done(super);
free(this);
}

static void DisplayOptionsPanel_setFunctionBar(DisplayOptionsPanel* this, OptionItem* item) {
Panel* super = (Panel*) this;
switch (OptionItem_kind(item)) {
case OPTION_ITEM_NUMBER: {
super->currentBar = this->numericFuBar;
break;
}
case OPTION_ITEM_CHECK: {
super->currentBar = this->checkboxFuBar;
break;
}
default: {
super->currentBar = this->checkboxFuBar;
break;
}
}
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(this, 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(this, next_to_select);
}
break;
}
case '\n':
case '\r':
case KEY_ENTER:
Expand Down Expand Up @@ -90,11 +132,15 @@ 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* checkboxFuBar = FunctionBar_new(CheckboxDisplayOptionsFunctions, CheckboxDisplayOptionsKeys, CheckboxDisplayOptionsEvents);
FunctionBar* numericFuBar = FunctionBar_new(NumericDisplayOptionsFunctions, NumericDisplayOptionsKeys, NumericDisplayOptionsEvents);
FunctionBar* emptyFuBar = FunctionBar_new(NULL, NULL, NULL);
Panel_init(super, 1, 1, 1, 1, Class(OptionItem), true, emptyFuBar);

this->settings = settings;
this->scr = scr;
this->numericFuBar = numericFuBar;
this->checkboxFuBar = checkboxFuBar;

Panel_setHeader(super, "Display options");
Panel_add(super, (Object*) CheckItem_newByRef("Tree view", &(settings->treeView)));
Expand Down Expand Up @@ -141,5 +187,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(this, defaultSelected);

return this;
}
2 changes: 2 additions & 0 deletions DisplayOptionsPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ typedef struct DisplayOptionsPanel_ {

Settings* settings;
ScreenManager* scr;
FunctionBar* numericFuBar;
FunctionBar* checkboxFuBar;
} DisplayOptionsPanel;

extern const PanelClass DisplayOptionsPanel_class;
Expand Down

0 comments on commit 6d7a5b9

Please sign in to comment.