Skip to content

Commit

Permalink
Update ItemBack class to inherit from BaseItemZeroWidget (#252)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
	- Enhanced `ItemBack` functionality with improved command handling.
	- Introduced a new method for processing the `BACK` command.

- **Refactor**
- Updated class inheritance for better alignment with base
functionality.
	- Simplified header file structure with the use of `#pragma once`.

- **Chores**
- Modified Wokwi CI workflow to allow for continued execution despite
errors.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
forntoh authored Oct 25, 2024
2 parents 77fbe10 + a490e6a commit 02f7235
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/wokwi_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ jobs:

- name: Running ${{ env.TEST_FILE }} on Wokwi
uses: wokwi/wokwi-ci-action@v1
continue-on-error: true
with:
token: ${{ secrets.WOKWI_CLI_TOKEN }}
scenario: ${{ env.TEST_FILE }}
Expand Down
39 changes: 17 additions & 22 deletions src/ItemBack.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#ifndef ItemBack_H
#define ItemBack_H
#pragma once

#include "BaseItemZeroWidget.h"
#include "LcdMenu.h"
#include "MenuItem.h"

/**
* @class ItemBack
Expand All @@ -12,34 +11,30 @@
* navigates back to the previous screen in the menu system.
*
* @details
* This class inherits from the MenuItem class and overrides the
* process method to handle the ENTER command by changing the screen.
*
* @note The default text for this item is "..".
* This class inherits from the BaseItemZeroWidget class and overrides the
* handleCommit method to handle the ENTER command by navigating back to the previous screen.
*/
class ItemBack : public MenuItem {
class ItemBack : public BaseItemZeroWidget {
public:
/**
* Construct a new ItemBack object.
* @param text The text of the item.
*/
ItemBack(const char* text = "..") : MenuItem(text) {}
ItemBack(const char* text) : BaseItemZeroWidget(text) {}

protected:
bool process(LcdMenu* menu, const unsigned char command) override {
switch (command) {
case ENTER:
changeScreen(menu);
return true;
default:
return false;
}
}
void changeScreen(LcdMenu* menu) {
void handleCommit(LcdMenu* menu) override {
menu->process(BACK);
}
};

#define ITEM_BACK(...) (new ItemBack(__VA_ARGS__))

#endif
/**
* @brief Create a new back item.
*
* @param text The text to display for the item (default is "..").
* @return MenuItem* The created item. Caller takes ownership of the returned pointer.
*
* @example
* auto item = ITEM_BACK("Back");
*/
inline MenuItem* ITEM_BACK(const char* text = "..") { return new ItemBack(text); }

0 comments on commit 02f7235

Please sign in to comment.