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

Conversation

ahmedaabouzied
Copy link

@ahmedaabouzied ahmedaabouzied commented Aug 16, 2021

  • Display controls to increment & decrement the numeric options.
  • Display control to select/deselect non-numeric options with the enter key.
  • This allows incrementing and decrementing values with the mouse.

Resolves: #737

Screenshot after applying the change:
Screenshot (11)

@BenBE BenBE added the enhancement Extension or improvement to existing feature label Aug 16, 2021
@BenBE BenBE added this to the 3.1.1 milestone Aug 16, 2021
@Explorer09
Copy link
Contributor

@ahmedaabouzied
Copy link
Author

I've updated the PR in response to @Explorer09 comments with the following changes:

  • Renames the (De)select button name to Select.
  • Makes the Increment button on the right of the Decrement button.
  • Shows two different function bars according to the type of item selected.
    • It will show a numeric function bar with Decrement and Increment buttons with numeric items.
    • It will show a boolean function bar with the Select button with boolean items.

boolean_htop
numeric_htop

@ahmedaabouzied
Copy link
Author

@BenBE I think my editor is messing up the indentation. Is there a specific linter I should run?

@BenBE
Copy link
Member

BenBE commented Aug 24, 2021

@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 STYLEGUIDE using astyle. Be sure to only include the lines near the code you edited.

@ahmedaabouzied ahmedaabouzied force-pushed the issue-737 branch 3 times, most recently from cc0978b to 2994d36 Compare August 24, 2021 16:32
@ahmedaabouzied
Copy link
Author

There is a rough command line mentioned in the STYLEGUIDE using astyle. Be sure to only include the lines near the code you edited.

@BenBE , I think just manually fixed the indentation issues here. Could you take another look?

@BenBE
Copy link
Member

BenBE commented Aug 24, 2021

There is a rough command line mentioned in the STYLEGUIDE using astyle. Be sure to only include the lines near the code you edited.

@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.

@ahmedaabouzied
Copy link
Author

Quick look shows still some issues left. Check for 3 spaces per level.

Ok, 3 spaces it is.

@BenBE
Copy link
Member

BenBE commented Aug 24, 2021

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);

@ahmedaabouzied
Copy link
Author

@BenBE Alright.

@ahmedaabouzied
Copy link
Author

ahmedaabouzied commented Aug 24, 2021

I resolved to format the file with asyle as stated in the /doc/styleguide.md file which messed things even further. This is not fun XD

@ahmedaabouzied
Copy link
Author

@BenBE , sorry for all that mess. I think now it's reasonably formatted.

Copy link
Member

@BenBE BenBE left a comment

Choose a reason for hiding this comment

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

What about merging the two commits of this PR?

@@ -90,7 +122,7 @@ 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);
FunctionBar* fuBar = FunctionBar_new(BooleanDisplayOptionsFunctions, BooleanDisplayOptionsKeys, BooleanDisplayOptionsEvents);
Copy link
Member

Choose a reason for hiding this comment

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

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*?

Copy link
Author

Choose a reason for hiding this comment

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

ok

Copy link
Author

Choose a reason for hiding this comment

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

Checkbox seems more reasonable @BenBE

Copy link
Author

Choose a reason for hiding this comment

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

Will update that

@ahmedaabouzied
Copy link
Author

@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 DisplayOptionsPanel_setFunctionBar() function. This will make it so that if that first item type is changed, the function bar will change with it.

Let me know if you have more comments.
Thanks.

@ahmedaabouzied ahmedaabouzied requested a review from BenBE August 28, 2021 19:11
@@ -29,13 +34,41 @@ static void DisplayOptionsPanel_delete(Object* object) {
free(this);
}

static void DisplayOptionsPanel_setFunctionBar(Panel* super, OptionItem* item) {
Copy link
Member

Choose a reason for hiding this comment

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

This leaks the memory of the previously selected FunctionBar.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch @BenBE , modified that. Sorry for the delayed responses btw.

@BenBE
Copy link
Member

BenBE commented Oct 15, 2021

Given there's #822 on the list of likely extensions, it's good planning to go the switch statement route directly.

@BenBE BenBE modified the milestones: 3.2.0, 3.1.2 Oct 17, 2021
Copy link
Member

@BenBE BenBE left a comment

Choose a reason for hiding this comment

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

Only one additional point that @cgzones didn't remark on in his latest review …

@BenBE
Copy link
Member

BenBE commented Nov 28, 2021

Hi @ahmedaabouzied, any updates with this PR? Need help with any of the issues raised?

@BenBE BenBE modified the milestones: 3.1.2, 3.2.0 Nov 28, 2021
@ahmedaabouzied
Copy link
Author

Hi @ahmedaabouzied, any updates with this PR? Need help with any of the issues raised?

Sorry @BenBE , I missed the notification there. I've applied the changes you requested above.

@cgzones
Copy link
Member

cgzones commented Dec 5, 2021

I think one can re-use the drawFunctionBar callback of the Panel class, which avoids the KEY_UP/DOWN interception:

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;

@fasterit fasterit modified the milestones: 3.2.0, 3.3.0 Feb 24, 2022
@macmbello
Copy link

#the manage the upskill od the main menu
we have to atleat give the meaning of the menu's bar

@BenBE BenBE modified the milestones: 3.3.0, 3.4.0 Dec 26, 2023
@BenBE
Copy link
Member

BenBE commented Jan 18, 2025

What's the status for this PR? Any open issues to resolve?

Comment on lines +42 to +49
case OPTION_ITEM_NUMBER:
super->currentBar = this->numericFuBar;
break;
case OPTION_ITEM_CHECK:
super->currentBar = this->checkboxFuBar;
break;
defaut:
assert(0); // Unknown option type
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

@BenBE BenBE modified the milestones: 3.4.0, 3.5.0 Jan 20, 2025
hishamhm added a commit that referenced this pull request Feb 19, 2025
as per @Explorer09's suggestion in #745.

Also makes it consistent with "- Nice" and "+ Nice" in
the main function bar!
hishamhm added a commit that referenced this pull request Feb 19, 2025
as per @Explorer09's suggestion in #745.

Also makes it consistent with "- Nice" and "+ Nice" in
the main function bar!
fasterit pushed a commit that referenced this pull request Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Extension or improvement to existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Numeric option items should have increment & decrement controls
6 participants