Skip to content

Commit 6285216

Browse files
committed
Refactoring
1 parent e29addf commit 6285216

File tree

9 files changed

+18
-16
lines changed

9 files changed

+18
-16
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "M5TreeView",
2+
"name": "M5Stack_TreeView",
33
"description": "TreeView Menu UI for M5Stack",
44
"keywords": "treeview, m5stack, esp32",
55
"authors": {

src/MenuItem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const GFXfont* MenuItem::gfxFont = NULL;
2727
MenuItem* MenuItem::focusItem = NULL;
2828
M5ButtonDrawer MenuItem::_btnDrawer;
2929

30-
MenuItem::MenuItem(const String& titleStr, int tg, std::function<void(MenuItem*)> cb)
30+
MenuItem::MenuItem(const String& titleStr, int tg, TCallBackEnter cb)
3131
: title(titleStr)
3232
, callback(cb)
3333
, tag(tg)
@@ -38,7 +38,7 @@ MenuItem::MenuItem(const String& titleStr, int tg, std::function<void(MenuItem*)
3838
, _parentItem(NULL)
3939
{}
4040

41-
MenuItem::MenuItem(const String& titleStr, int tg, std::function<void(MenuItem*)> cb, const std::vector<MenuItem*> &sub)
41+
MenuItem::MenuItem(const String& titleStr, int tg, TCallBackEnter cb, const std::vector<MenuItem*> &sub)
4242
: MenuItem(titleStr, tg, cb)
4343
{
4444
setItems(sub);

src/MenuItem.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
class MenuItem {
1212
protected:
1313
public:
14+
using TCallBackEnter = std::function<void(MenuItem*)>;
15+
1416
static Rect16 clientRect;
1517
static uint16_t itemHeight;
1618
static uint16_t itemWidth;
@@ -36,11 +38,11 @@ class MenuItem {
3638

3739
MenuItem() : MenuItem("", 0, NULL) {}
3840
MenuItem(const String& title, const std::vector<MenuItem*> &sub) : MenuItem(title, 0, sub) {}
39-
MenuItem(const String& title, std::function<void(MenuItem*)> cb) : MenuItem(title, 0, cb) {}
40-
MenuItem(const String& title, std::function<void(MenuItem*)> cb, const std::vector<MenuItem*> &sub) : MenuItem(title, 0, cb, sub) {}
41+
MenuItem(const String& title, TCallBackEnter cb) : MenuItem(title, 0, cb) {}
42+
MenuItem(const String& title, TCallBackEnter cb, const std::vector<MenuItem*> &sub) : MenuItem(title, 0, cb, sub) {}
4143
MenuItem(const String& title, int tg , const std::vector<MenuItem*> &sub) : MenuItem(title, tg, NULL, sub ) {}
42-
MenuItem(const String& title, int tg = 0, std::function<void(MenuItem*)> cb = NULL);
43-
MenuItem(const String& title, int tg , std::function<void(MenuItem*)> cb, const std::vector<MenuItem*> &sub);
44+
MenuItem(const String& title, int tg = 0, TCallBackEnter cb = NULL);
45+
MenuItem(const String& title, int tg , TCallBackEnter cb, const std::vector<MenuItem*> &sub);
4446
virtual ~MenuItem() {};
4547

4648
void addItem(MenuItem* item);
@@ -70,7 +72,7 @@ class MenuItem {
7072

7173
std::vector<MenuItem*> Items;
7274
String title;
73-
std::function<void(MenuItem*)> callback = 0;
75+
TCallBackEnter callback = 0;
7476
Rect16 destRect; // destinationPoint
7577
Rect16 rect; // displayPoint
7678
int tag = 0;

src/MenuItemFS.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class MenuItemFS : public MenuItem {
99
String path;
1010
bool isDir;
1111

12-
MenuItemFS(const String& title, std::function<void(MenuItem*)>cb = NULL)
12+
MenuItemFS(const String& title, TCallBackEnter cb = NULL)
1313
: MenuItem(title, cb), path(), isDir(true) {};
1414

1515
MenuItemFS(const String& title, const std::vector<MenuItem*> &items)

src/MenuItemNumeric.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ class MenuItemNumeric : public MenuItem {
99
int maximum = 1;
1010
int value = 0;
1111

12-
MenuItemNumeric(const String& title, int min, int max, int value, int tg = 0, std::function<void(MenuItem*)> cb = 0)
12+
MenuItemNumeric(const String& title, int min, int max, int value, int tg = 0, TCallBackEnter cb = 0)
1313
: MenuItem(title, tg, cb), minimum(min), maximum(max), value(value) {};
1414

15-
MenuItemNumeric(const String& title, int min, int max, int value, std::function<void(MenuItem*)> cb)
15+
MenuItemNumeric(const String& title, int min, int max, int value, TCallBackEnter cb)
1616
: MenuItem(title, cb), minimum(min), maximum(max), value(value) {};
1717

1818
virtual void onAfterDraw();

src/MenuItemSD.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class MenuItemSD : public MenuItemFS
77
{
88
public:
9-
MenuItemSD(const String& title, std::function<void(MenuItem*)>cb = NULL)
9+
MenuItemSD(const String& title, TCallBackEnter cb = NULL)
1010
: MenuItemFS(title, cb) {};
1111

1212
MenuItemSD(const String& title, const std::vector<MenuItem*> &items)

src/MenuItemSPIFFS.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class MenuItemSPIFFS : public MenuItemFS
77
{
88
public:
9-
MenuItemSPIFFS(const String& title, std::function<void(MenuItem*)>cb = NULL)
9+
MenuItemSPIFFS(const String& title, TCallBackEnter cb = NULL)
1010
: MenuItemFS(title, cb) {};
1111

1212
MenuItemSPIFFS(const String& title, const std::vector<MenuItem*> &items)

src/MenuItemToggle.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ class MenuItemToggle : public MenuItem {
77
public:
88
bool value = false;
99

10-
MenuItemToggle(const String& title, bool value = false, int tg = 0, std::function<void(MenuItem*)> cb = 0)
10+
MenuItemToggle(const String& title, bool value = false, int tg = 0, TCallBackEnter cb = 0)
1111
: MenuItem(title, tg, cb), value(value) {};
1212

13-
MenuItemToggle(const String& title, int value, std::function<void(MenuItem*)> cb)
13+
MenuItemToggle(const String& title, int value, TCallBackEnter cb)
1414
: MenuItem(title, cb), value(value) {};
1515

1616
virtual void onAfterDraw();

src/MenuItemWiFiClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class MenuItemWiFiClient : public MenuItem {
99
public:
10-
MenuItemWiFiClient(const String& title, std::function<void(MenuItem*)>cb = 0)
10+
MenuItemWiFiClient(const String& title, TCallBackEnter cb = 0)
1111
: MenuItem(title, cb) {};
1212

1313
virtual void onEnter();

0 commit comments

Comments
 (0)