Skip to content

Commit 76d88df

Browse files
Add increment and decrement controls for numeric display options
Signed-off-by: Ahmed Abouzied <email@aabouzied.com>
1 parent 68c00b9 commit 76d88df

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

DisplayOptionsPanel.c

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,56 @@ in the source distribution for its full text.
2020
#include "ProvideCurses.h"
2121

2222

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

2530
static void DisplayOptionsPanel_delete(Object* object) {
2631
Panel* super = (Panel*) object;
2732
DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
33+
FunctionBar_delete(this->numericFuBar);
34+
FunctionBar_delete(this->checkboxFuBar);
2835
Panel_done(super);
2936
free(this);
3037
}
3138

39+
static void DisplayOptionsPanel_setFunctionBar(DisplayOptionsPanel* this, OptionItem* item) {
40+
Panel* super = (Panel*) this;
41+
if (OptionItem_kind(item) == OPTION_ITEM_NUMBER) {
42+
super->currentBar = this->numericFuBar;
43+
} else {
44+
super->currentBar = this->checkboxFuBar;
45+
}
46+
FunctionBar_draw(super->currentBar);
47+
}
48+
3249
static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
3350
DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
3451

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

3855
switch (ch) {
56+
57+
case KEY_UP: {
58+
int selected_index = Panel_getSelectedIndex(super);
59+
if (selected_index > 1) {
60+
OptionItem* next_to_select = (OptionItem*) Panel_get(super, selected_index - 1);
61+
DisplayOptionsPanel_setFunctionBar(this, next_to_select);
62+
}
63+
break;
64+
}
65+
case KEY_DOWN: {
66+
int selected_index = Panel_getSelectedIndex(super);
67+
if (selected_index < Panel_size(super) - 1) {
68+
OptionItem* next_to_select = (OptionItem*) Panel_get(super, selected_index + 1);
69+
DisplayOptionsPanel_setFunctionBar(this, next_to_select);
70+
}
71+
break;
72+
}
3973
case '\n':
4074
case '\r':
4175
case KEY_ENTER:
@@ -90,11 +124,15 @@ const PanelClass DisplayOptionsPanel_class = {
90124
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
91125
DisplayOptionsPanel* this = AllocThis(DisplayOptionsPanel);
92126
Panel* super = (Panel*) this;
93-
FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL);
94-
Panel_init(super, 1, 1, 1, 1, Class(OptionItem), true, fuBar);
127+
FunctionBar* numericFuBar = FunctionBar_new(CheckboxDisplayOptionsFunctions, CheckboxDisplayOptionsKeys, CheckboxDisplayOptionsEvents);
128+
FunctionBar* selectFuBar = FunctionBar_new(NumericDisplayOptionsFunctions, NumericDisplayOptionsKeys, NumericDisplayOptionsEvents);
129+
FunctionBar* emptyFuBar = FunctionBar_new(NULL, NULL, NULL);
130+
Panel_init(super, 1, 1, 1, 1, Class(OptionItem), true, emptyFuBar);
95131

96132
this->settings = settings;
97133
this->scr = scr;
134+
this->numericFuBar = numericFuBar;
135+
this->checkboxFuBar = selectFuBar;
98136

99137
Panel_setHeader(super, "Display options");
100138
Panel_add(super, (Object*) CheckItem_newByRef("Tree view", &(settings->treeView)));
@@ -141,5 +179,9 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
141179
#ifdef HAVE_LIBHWLOC
142180
Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity)));
143181
#endif
182+
183+
OptionItem* defaultSelected = (OptionItem*) Panel_getSelected(super);
184+
DisplayOptionsPanel_setFunctionBar(this, defaultSelected);
185+
144186
return this;
145187
}

DisplayOptionsPanel.h

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

1818
Settings* settings;
1919
ScreenManager* scr;
20+
FunctionBar *numericFuBar;
21+
FunctionBar *checkboxFuBar;
2022
} DisplayOptionsPanel;
2123

2224
extern const PanelClass DisplayOptionsPanel_class;

0 commit comments

Comments
 (0)