Add increment and decrement controls for numeric display options#745
Add increment and decrement controls for numeric display options#745ahmedaabouzied wants to merge 1 commit intohtop-dev:mainfrom
Conversation
f2f71b1 to
e83c20a
Compare
|
|
I've updated the PR in response to @Explorer09 comments with the following changes:
|
|
@BenBE I think my editor is messing up the indentation. Is there a specific linter I should run? |
There is a rough command line mentioned in the |
cc0978b to
2994d36
Compare
@BenBE , I think just manually fixed the indentation issues here. Could you take another look? |
Quick look shows still some issues left. Check for 3 spaces per level. |
2994d36 to
1873434
Compare
Ok, 3 spaces it is. |
|
Another small adjustment: $ git diff --cached
diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c
index 42489077..176b017e 100644
--- a/DisplayOptionsPanel.c
+++ b/DisplayOptionsPanel.c
@@ -27,8 +27,6 @@ static const char* const NumericDisplayOptionsFunctions[] = {"Decrement ", "Incr
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;
DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
@@ -54,15 +52,15 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
switch (ch) {
- case KEY_UP:{
+ 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:{
+ }
+ 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); |
1873434 to
8153d84
Compare
|
@BenBE Alright. |
8153d84 to
e1bf90f
Compare
|
I resolved to format the file with |
e1bf90f to
ec93881
Compare
|
@BenBE , sorry for all that mess. I think now it's reasonably formatted. |
BenBE
left a comment
There was a problem hiding this comment.
What about merging the two commits of this PR?
DisplayOptionsPanel.c
Outdated
| DisplayOptionsPanel* this = AllocThis(DisplayOptionsPanel); | ||
| Panel* super = (Panel*) this; | ||
| FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL); | ||
| FunctionBar* fuBar = FunctionBar_new(BooleanDisplayOptionsFunctions, BooleanDisplayOptionsKeys, BooleanDisplayOptionsEvents); |
There was a problem hiding this comment.
What about creating the Panel without a Function Bar at first and just set it based on the default-selected item just before returning? Avoids having this statement go out of sync when the first item changes.
Also maybe rename Boolean* to Checkbox*?
ec93881 to
9716bff
Compare
|
@BenBE , now initially the Panel is initiated with an empty function bar, then the right function bar is set based on the default selected item using the Let me know if you have more comments. |
DisplayOptionsPanel.c
Outdated
| free(this); | ||
| } | ||
|
|
||
| static void DisplayOptionsPanel_setFunctionBar(Panel* super, OptionItem* item) { |
There was a problem hiding this comment.
This leaks the memory of the previously selected FunctionBar.
There was a problem hiding this comment.
Good catch @BenBE , modified that. Sorry for the delayed responses btw.
|
Given there's #822 on the list of likely extensions, it's good planning to go the |
76d88df to
e87ed80
Compare
6d7a5b9 to
e1d6f9a
Compare
|
Hi @ahmedaabouzied, any updates with this PR? Need help with any of the issues raised? |
Signed-off-by: Ahmed Abouzied <email@aabouzied.com>
e1d6f9a to
a90a327
Compare
Sorry @BenBE , I missed the notification there. I've applied the changes you requested above. |
|
I think one can re-use the diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c
index 8212120..0e3ac03 100644
--- a/DisplayOptionsPanel.c
+++ b/DisplayOptionsPanel.c
@@ -20,11 +20,18 @@ 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);
}
@@ -79,22 +86,46 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
return result;
}
+static void DisplayOptionsPanel_drawFunctionBar(Panel* super, ATTR_UNUSED bool hideFunctionBar) {
+ DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
+
+ int selected_index = Panel_getSelectedIndex(super);
+ OptionItem* item = (OptionItem*) Panel_get(super, selected_index);
+
+ switch (OptionItem_kind(item)) {
+ case OPTION_ITEM_NUMBER:
+ super->currentBar = this->numericFuBar;
+ break;
+ case OPTION_ITEM_CHECK:
+ super->currentBar = this->checkboxFuBar;
+ break;
+ default:
+ assert(0); // Unknown option type
+ }
+ FunctionBar_draw(super->currentBar);
+}
+
const PanelClass DisplayOptionsPanel_class = {
.super = {
.extends = Class(Panel),
.delete = DisplayOptionsPanel_delete
},
- .eventHandler = DisplayOptionsPanel_eventHandler
+ .eventHandler = DisplayOptionsPanel_eventHandler,
+ .drawFunctionBar = DisplayOptionsPanel_drawFunctionBar
};
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)));
diff --git a/DisplayOptionsPanel.h b/DisplayOptionsPanel.h
index 5e87a63..899cf3c 100644
--- a/DisplayOptionsPanel.h
+++ b/DisplayOptionsPanel.h
@@ -17,6 +17,8 @@ typedef struct DisplayOptionsPanel_ {
Settings* settings;
ScreenManager* scr;
+ FunctionBar* numericFuBar;
+ FunctionBar* checkboxFuBar;
} DisplayOptionsPanel;
extern const PanelClass DisplayOptionsPanel_class; |
|
#the manage the upskill od the main menu |
|
What's the status for this PR? Any open issues to resolve? |
| case OPTION_ITEM_NUMBER: | ||
| super->currentBar = this->numericFuBar; | ||
| break; | ||
| case OPTION_ITEM_CHECK: | ||
| super->currentBar = this->checkboxFuBar; | ||
| break; | ||
| defaut: | ||
| assert(0); // Unknown option type |
There was a problem hiding this comment.
| 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 |
as per @Explorer09's suggestion in #745. Also makes it consistent with "- Nice" and "+ Nice" in the main function bar!
as per @Explorer09's suggestion in #745. Also makes it consistent with "- Nice" and "+ Nice" in the main function bar!


Resolves: #737
Screenshot after applying the change:
