Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add increment and decrement controls for numeric display options #745

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions DisplayOptionsPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,60 @@ 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;
defaut:
assert(0); // Unknown option type
Comment on lines +42 to +49
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case OPTION_ITEM_NUMBER:
super->currentBar = this->numericFuBar;
break;
case OPTION_ITEM_CHECK:
super->currentBar = this->checkboxFuBar;
break;
defaut:
assert(0); // Unknown option type
case OPTION_ITEM_NUMBER:
super->currentBar = this->numericFuBar;
break;
case OPTION_ITEM_CHECK:
super->currentBar = this->checkboxFuBar;
break;
defaut:
assert(0); // Unknown option type

}
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 +128,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 +183,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