Skip to content

Commit 2f5fb7d

Browse files
committed
initServices, exitServices and handleInput never got called
1 parent 7617d94 commit 2f5fb7d

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

include/tesla.hpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ namespace tsl {
7474

7575
}
7676

77+
namespace style {
78+
constexpr u32 ListItemDefaultHeight = 72;
79+
}
80+
7781
// Declarations
7882
enum class FocusDirection {
7983
None,
@@ -920,7 +924,12 @@ namespace tsl {
920924
}
921925
}
922926

923-
virtual void addItem(Element *element, u16 height) final {
927+
virtual void addItem(Element *element, u16 height = 0) final {
928+
if (height == 0) {
929+
if (dynamic_cast<ListItem*>(element) != nullptr)
930+
height = tsl::style::ListItemDefaultHeight;
931+
}
932+
924933
if (element != nullptr && height > 0) {
925934
element->setParent(this);
926935
this->m_items.push_back({ element, height });
@@ -1016,12 +1025,11 @@ namespace tsl {
10161025
delete this->m_topElement;
10171026
}
10181027

1019-
virtual void initServices() {}
1020-
virtual void exitServices() {}
1021-
10221028
virtual elm::Element* createUI() = 0;
10231029
virtual void update() {}
1024-
virtual void onInput(u64 keysDown, u64 keysHeld, JoystickPosition leftJoyStick, JoystickPosition rightJoyStick, touchPosition touchInput) {}
1030+
virtual bool handleInput(u64 keysDown, u64 keysHeld, touchPosition touchInput, JoystickPosition leftJoyStick, JoystickPosition rightJoyStick) {
1031+
return false;
1032+
}
10251033

10261034
virtual void draw(gfx::Renderer *renderer) final {
10271035
if (this->m_topElement != nullptr)
@@ -1080,8 +1088,11 @@ namespace tsl {
10801088
template <typename Gui>
10811089
class Overlay<Gui, std::enable_if_t<std::is_base_of_v<tsl::Gui, Gui>>> : private hlp::OverlayBase {
10821090
public:
1083-
virtual void onShow() {} // Called before overlay wants to change from invisible to visible state
1084-
virtual void onHide() {} // Called before overlay wants to change from visible to invisible state
1091+
virtual void initServices() {} // Called at the start to initialize all services necessary for this Overlay
1092+
virtual void exitServices() {} // Callet at the end to clean up all services previously initialized
1093+
1094+
virtual void onShow() {} // Called before overlay wants to change from invisible to visible state
1095+
virtual void onHide() {} // Called before overlay wants to change from visible to invisible state
10851096

10861097
virtual std::unique_ptr<tsl::Gui>& getCurrentGui() final {
10871098
return this->m_guiStack[this->m_guiStack.size() - 1];
@@ -1235,6 +1246,8 @@ namespace tsl {
12351246
parentElement = parentElement->getParent();
12361247
} while (!handled && parentElement != nullptr);
12371248

1249+
handled = handled | currentGui->handleInput(keysDown, keysHeld, touchPos, joyStickPosLeft, joyStickPosRight);
1250+
12381251
if (!handled) {
12391252
if (keysDown & KEY_UP)
12401253
currentGui->requestFocus(currentFocus->getParent(), FocusDirection::Up);
@@ -1457,6 +1470,7 @@ namespace tsl {
14571470

14581471

14591472
auto& overlay = Overlay::get();
1473+
overlay.initServices();
14601474
overlay.initScreen();
14611475
overlay.loadDefaultGui();
14621476

@@ -1514,6 +1528,7 @@ namespace tsl {
15141528
threadClose(&powerButtonDetectorThread);
15151529

15161530
overlay.exitScreen();
1531+
overlay.exitServices();
15171532

15181533
return 0;
15191534
}

0 commit comments

Comments
 (0)