@@ -120,15 +120,8 @@ namespace tsl {
120120 };
121121
122122 class Overlay ;
123- namespace elm { class Element ; }
124123
125124 namespace impl {
126-
127- extern std::vector<tsl::elm::Element*> g_deletedElements;
128-
129- static inline void reportDeletedElement (tsl::elm::Element *element) {
130- tsl::impl::g_deletedElements.push_back (element);
131- }
132125
133126 /* *
134127 * @brief Overlay launch parameters
@@ -1075,9 +1068,7 @@ namespace tsl {
10751068 class Element {
10761069 public:
10771070 Element () {}
1078- virtual ~Element () {
1079- tsl::impl::reportDeletedElement (this );
1080- }
1071+ virtual ~Element () {}
10811072
10821073 /* *
10831074 * @brief Handles focus requesting
@@ -1642,25 +1633,6 @@ namespace tsl {
16421633 }
16431634
16441635 virtual void draw (gfx::Renderer *renderer) override {
1645- if (this ->m_clearList ) {
1646- for (auto & item : this ->m_items )
1647- delete item;
1648-
1649- this ->m_items .clear ();
1650- this ->m_offset = 0 ;
1651- this ->m_focusedIndex = 0 ;
1652- this ->invalidate ();
1653- this ->m_clearList = false ;
1654- }
1655-
1656- for (auto &element : this ->m_itemsToAdd ) {
1657- element->invalidate ();
1658- this ->m_items .push_back (element);
1659- this ->invalidate ();
1660- this ->updateScrollOffset ();
1661- }
1662- this ->m_itemsToAdd .clear ();
1663-
16641636 renderer->enableScissoring (this ->getX (), this ->getY (), this ->getWidth (), this ->getHeight ());
16651637
16661638 for (auto &entry : this ->m_items ) {
@@ -1693,7 +1665,7 @@ namespace tsl {
16931665 }
16941666
16951667 /* *
1696- * @brief Adds a new item to the list before the next frame starts
1668+ * @brief Adds a new item to the list
16971669 *
16981670 * @param element Element to add
16991671 * @param height Height of the element. Don't set this parameter for libtesla to try and figure out the size based on the type
@@ -1705,26 +1677,30 @@ namespace tsl {
17051677
17061678 element->setParent (this );
17071679 element->invalidate ();
1708-
1709- this ->m_itemsToAdd . push_back (element );
1680+ this -> m_items . push_back (element);
1681+ this ->invalidate ( );
17101682 }
17111683
1712- }
1684+ if (this ->m_items .size () == 1 )
1685+ this ->requestFocus (nullptr , FocusDirection::None);
1686+ }
17131687
17141688 /* *
1715- * @brief Removes all children from the list later on
1689+ * @brief Removes all children from the list
17161690 * @warning When clearing a list, make sure none of the its children are focused. Call \ref Gui::removeFocus before.
17171691 */
17181692 virtual void clear () final {
1719- this ->m_clearList = true ;
1693+ for (auto & item : this ->m_items )
1694+ delete item;
1695+
1696+ this ->m_items .clear ();
1697+ this ->m_offset = 0 ;
1698+ this ->m_focusedIndex = 0 ;
17201699 }
17211700
17221701 virtual Element* requestFocus (Element *oldFocus, FocusDirection direction) override {
17231702 Element *newFocus = nullptr ;
17241703
1725- if (this ->m_clearList || this ->m_itemsToAdd .size () > 0 )
1726- return nullptr ;
1727-
17281704 if (direction == FocusDirection::None) {
17291705 for (u16 i = 0 ; i < this ->m_items .size (); i++) {
17301706 newFocus = this ->m_items [i]->requestFocus (oldFocus, direction);
@@ -1799,13 +1775,10 @@ namespace tsl {
17991775 u32 m_listHeight = 0 ;
18001776 u16 m_entriesShown = 5 ;
18011777
1802- bool m_clearList = false ;
1803- std::vector<Element *> m_itemsToAdd;
1804-
18051778 private:
18061779
18071780 virtual void updateScrollOffset () {
1808- this ->m_nextOffset = 0 ;
1781+ /* this->m_nextOffset = 0;
18091782 for (u16 i = 0; i < this->m_focusedIndex; i++)
18101783 this->m_nextOffset += this->m_items[i]->getHeight();
18111784
@@ -1815,7 +1788,7 @@ namespace tsl {
18151788 this->m_nextOffset = 0;
18161789
18171790 if (this->m_nextOffset > (this->m_listHeight - this->getHeight()) + 50)
1818- this ->m_nextOffset = (this ->m_listHeight - this ->getHeight () + 50 );
1791+ this->m_nextOffset = (this->m_listHeight - this->getHeight() + 50);*/
18191792 }
18201793 };
18211794
@@ -1893,9 +1866,8 @@ namespace tsl {
18931866 }
18941867
18951868 virtual bool onClick (u64 keys) {
1896- if (keys & KEY_A) {
1869+ if (keys & KEY_A)
18971870 this ->triggerClickAnimation ();
1898- }
18991871
19001872 return Element::onClick (keys);
19011873 }
@@ -2396,9 +2368,6 @@ namespace tsl {
23962368 * @param renderer
23972369 */
23982370 virtual void draw (gfx::Renderer *renderer) final {
2399- if (this ->getFocusedElement () == nullptr && this ->getTopElement () != nullptr )
2400- this ->requestFocus (this ->getTopElement (), tsl::FocusDirection::None);
2401-
24022371 if (this ->m_topElement != nullptr )
24032372 this ->m_topElement ->draw (renderer);
24042373 }
@@ -2624,8 +2593,6 @@ namespace tsl {
26242593
26252594 renderer.startFrame ();
26262595
2627- for (auto &deletedElement : tsl::impl::g_deletedElements)
2628- this ->getCurrentGui ()->removeFocus (deletedElement);
26292596
26302597 this ->animationLoop ();
26312598 this ->getCurrentGui ()->update ();
@@ -2655,19 +2622,16 @@ namespace tsl {
26552622
26562623 return ;
26572624 }
2658- else {
2659- currentFocus = topElement->requestFocus (nullptr , tsl::FocusDirection::None);
2660- }
2625+ else
2626+ currentFocus = topElement;
26612627 }
26622628
2663-
26642629 bool handled = false ;
26652630 elm::Element *parentElement = currentFocus;
2666-
2667- while (!handled && parentElement != nullptr ) {
2631+ do {
26682632 handled = parentElement->onClick (keysDown);
26692633 parentElement = parentElement->getParent ();
2670- }
2634+ } while (!handled && parentElement != nullptr );
26712635
26722636 parentElement = currentFocus;
26732637 do {
@@ -3122,10 +3086,7 @@ namespace tsl::cfg {
31223086 u16 FramebufferWidth = 0 ;
31233087 u16 FramebufferHeight = 0 ;
31243088 u64 launchCombo = KEY_L | KEY_DDOWN | KEY_RSTICK;
3125- }
31263089
3127- namespace tsl ::impl {
3128- std::vector<tsl::elm::Element*> g_deletedElements;
31293090}
31303091
31313092extern " C" {
0 commit comments