-
-
Notifications
You must be signed in to change notification settings - Fork 49
feat: add graphical selection support for input items #411
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |
| #include "LcdMenu.h" | ||
| #include <utils/lcd_menu_utils.h> | ||
|
|
||
| #include <string.h> | ||
|
|
||
| class ItemInputCharset : public ItemInput { | ||
| private: | ||
| const char* charset; | ||
|
|
@@ -117,6 +119,14 @@ class ItemInputCharset : public ItemInput { | |
| */ | ||
| void abortCharEdit(MenuRenderer* renderer) { | ||
| charEdit = false; | ||
|
|
||
| if (getGraphicalValueSelectionRenderer(renderer) != NULL) { | ||
| renderer->viewShift = 0; | ||
| ItemInput::draw(renderer); | ||
| LOG(F("ItemInputCharset::abortCharEdit")); | ||
| return; | ||
| } | ||
|
forntoh marked this conversation as resolved.
|
||
|
|
||
| uint8_t cursorCol = renderer->getCursorCol(); | ||
| if (cursor < strlen(value)) { | ||
| renderer->draw(value[cursor]); | ||
|
|
@@ -167,6 +177,34 @@ class ItemInputCharset : public ItemInput { | |
| } | ||
|
|
||
| void drawChar(MenuRenderer* renderer) { | ||
| if (getGraphicalValueSelectionRenderer(renderer) != NULL) { | ||
| renderer->viewShift = 0; | ||
| uint8_t length = strlen(value); | ||
|
|
||
| // Update in place when cursor points to an existing character; when cursor | ||
| // is at the insertion position, render through a temporary preview buffer | ||
| // to avoid writing past the current string bounds. | ||
| if (cursor < length) { | ||
| char original = value[cursor]; | ||
| value[cursor] = charset[charsetPosition]; | ||
| ItemInput::draw(renderer); | ||
| value[cursor] = original; | ||
| } else { | ||
| char* preview = new char[length + 2]; | ||
| memcpy(preview, value, length); | ||
| preview[length] = charset[charsetPosition]; | ||
| preview[length + 1] = '\0'; | ||
|
|
||
| char* originalValue = value; | ||
| value = preview; | ||
| ItemInput::draw(renderer); | ||
| value = originalValue; | ||
|
|
||
| delete[] preview; | ||
| } | ||
| return; | ||
| } | ||
|
Comment on lines
179
to
+206
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider unifying the two graphical preview paths. The If you want to keep zero-allocation behavior for the common in-range case, that is fine, but a brief comment explaining why the two branches differ would aid readers. 🤖 Prompt for AI Agents |
||
|
|
||
| renderer->moveCursor(renderer->getCursorCol(), renderer->getCursorRow()); | ||
| renderer->draw(charset[charsetPosition]); | ||
| renderer->moveCursor(renderer->getCursorCol(), renderer->getCursorRow()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Second
clearValueSelection()afterdrawItemis redundant in the non-editing branch.When
isEditing()is false, the code already callsselectionRenderer->clearValueSelection()on line 166 beforedrawItem, and then unconditionally calls it again on line 170 right after. It's harmless, but on embedded targets with a more expensive implementation ofclearValueSelectionit would be wasted work.♻️ Optional cleanup
🤖 Prompt for AI Agents