Skip to content

Add digits editing for numeric options#1935

Open
fasterit wants to merge 3 commits intohtop-dev:mainfrom
fasterit:numberitem-editor
Open

Add digits editing for numeric options#1935
fasterit wants to merge 3 commits intohtop-dev:mainfrom
fasterit:numberitem-editor

Conversation

@fasterit
Copy link
Copy Markdown
Member

Also add NumPad +/- keys for increment / decrement in numeric options

Assisted-by: Microsoft Copilot/Claude Sonnet 4.6

Also add NumPad +/- keys for increment / decrement in numeric options
@fasterit fasterit added the enhancement Extension or improvement to existing feature label Mar 29, 2026
Comment on lines +85 to +90
void NumberItem_startEditing(NumberItem* this);
void NumberItem_startEditingFromValue(NumberItem* this);
void NumberItem_cancelEditing(NumberItem* this);
bool NumberItem_applyEditing(NumberItem* this);
bool NumberItem_addChar(NumberItem* this, char c);
void NumberItem_deleteChar(NumberItem* this);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So many functions being added. I'm becoming skeptical of what the AI is changing here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Waldorf and Statler, are you doing the code reviews here?

this->editBuffer[0] = '\0';
return false;
}
newValue = (int) round(displayValue / pow(10, this->scale));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since this->scale is negative in this conditional, why not use multiplication (* pow(10, -this->scale)) for the scale instead of division? And what's the rationale for the rounding direction?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That scale nonsense isn't of my making, cf. 267014c.

On the div: Isn't your mantra to leave such tiny optimization to the compiler?

round gets the nearest integer, seems reasonable, not? I did not even think of alternatives. Just need to clamp the user, that types in 1.52334 for a x.x field.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note that the rounding mode may be surprising depending on what is (implicitly) set.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@BenBE The FP rounding mode is per-thread, and is not carried over to another executable image loaded by execve(2), so in other words, the rounding mode is in our control. However, I noticed a round(3) call here and the reason for the rounding direction is not given.

The context seems to be that, a binary floating point is used to parse a string with decimals, and then it tries to convert the floating point to a fixed point. This raises a question: why not parse to a fixed point directly?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

1.56 gets rounded to 1.6 in the "Update Interval" I consider that most correct. And it was the most easy solution, too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I though more on the lines of 1.45 vs 1.55, which depending on rounding mode may both be 1.5 (even/odd rounding vs. mathematically correct rounding) instead of 1.5 vs 1.6.

int len;
/* Format the initial edit buffer using scale for decimal display */
if (this->scale < 0) {
len = xSnprintf(tmp, sizeof(tmp), "%.*f", -this->scale, pow(10, this->scale) * this->savedValue);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Potential rounding error. It looks like AI didn't care about this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

len is max ten chars, where do you see an issue here?

Comment on lines +185 to +186
# define KEY_PADPLUS 583
# define KEY_PADMINUS 588
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why these numbers and where are they from?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Because that is what xterm compatible terminals send when you press + / - on the Numpad without Numlock active. If you have some Mac values for that, happy to add.

@fasterit fasterit force-pushed the numberitem-editor branch from 75b4a16 to a799669 Compare March 30, 2026 07:59
@BenBE BenBE added this to the 3.6.0 milestone Mar 30, 2026
Copy link
Copy Markdown
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.

Minor stylistic notes …

}
}
/* fallthrough */
/* FALLTHROUGH */
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unrelated change. I think the rest of the code all uses lowercase for this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think they should all be uppercase but fine to revert this one and may be we can change them all in one go if you lot agree.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

According to GCC documentation the match is made case-insensitive, thus both are fine.

Current distribution on main is:

$ grep -Ri 'fallthr'
DisplayOptionsPanel.c:         /* fallthrough */
OpenFilesScreen.c:         } /* FALLTHRU */
MetersPanel.c:         /* else fallthrough */
MetersPanel.c:         /* else fallthrough */
ScreensPanel.c:         /* FALLTHRU */
ScreensPanel.c:         /* FALLTHRU */
ColumnsPanel.c:         /* else fallthrough */
ColumnsPanel.c:         /* else fallthrough */

-Wimplicit-fallthrough=3 is basically an extension of -Wimplicit-fallthrough=2 with some stricter case matching; but both variants are covered.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To me it is more about the visual clue. I spot FALLTHRU much better than fallthrough.

this->editBuffer[0] = '\0';
return false;
}
newValue = (int) round(displayValue / pow(10, this->scale));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note that the rounding mode may be surprising depending on what is (implicitly) set.

@fasterit
Copy link
Copy Markdown
Member Author

Please squash on merge

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

3 participants