@@ -74,6 +74,10 @@ namespace tsl {
74
74
75
75
}
76
76
77
+ namespace style {
78
+ constexpr u32 ListItemDefaultHeight = 72 ;
79
+ }
80
+
77
81
// Declarations
78
82
enum class FocusDirection {
79
83
None,
@@ -920,7 +924,12 @@ namespace tsl {
920
924
}
921
925
}
922
926
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
+
924
933
if (element != nullptr && height > 0 ) {
925
934
element->setParent (this );
926
935
this ->m_items .push_back ({ element, height });
@@ -1016,12 +1025,11 @@ namespace tsl {
1016
1025
delete this ->m_topElement ;
1017
1026
}
1018
1027
1019
- virtual void initServices () {}
1020
- virtual void exitServices () {}
1021
-
1022
1028
virtual elm::Element* createUI () = 0;
1023
1029
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
+ }
1025
1033
1026
1034
virtual void draw (gfx::Renderer *renderer) final {
1027
1035
if (this ->m_topElement != nullptr )
@@ -1080,8 +1088,11 @@ namespace tsl {
1080
1088
template <typename Gui>
1081
1089
class Overlay <Gui, std::enable_if_t <std::is_base_of_v<tsl::Gui, Gui>>> : private hlp::OverlayBase {
1082
1090
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
1085
1096
1086
1097
virtual std::unique_ptr<tsl::Gui>& getCurrentGui () final {
1087
1098
return this ->m_guiStack [this ->m_guiStack .size () - 1 ];
@@ -1235,6 +1246,8 @@ namespace tsl {
1235
1246
parentElement = parentElement->getParent ();
1236
1247
} while (!handled && parentElement != nullptr );
1237
1248
1249
+ handled = handled | currentGui->handleInput (keysDown, keysHeld, touchPos, joyStickPosLeft, joyStickPosRight);
1250
+
1238
1251
if (!handled) {
1239
1252
if (keysDown & KEY_UP)
1240
1253
currentGui->requestFocus (currentFocus->getParent (), FocusDirection::Up);
@@ -1457,6 +1470,7 @@ namespace tsl {
1457
1470
1458
1471
1459
1472
auto & overlay = Overlay::get ();
1473
+ overlay.initServices ();
1460
1474
overlay.initScreen ();
1461
1475
overlay.loadDefaultGui ();
1462
1476
@@ -1514,6 +1528,7 @@ namespace tsl {
1514
1528
threadClose (&powerButtonDetectorThread);
1515
1529
1516
1530
overlay.exitScreen ();
1531
+ overlay.exitServices ();
1517
1532
1518
1533
return 0 ;
1519
1534
}
0 commit comments