Skip to content

Commit 045d0fd

Browse files
fix by downgrading libtesla...
1 parent 33afd77 commit 045d0fd

File tree

7 files changed

+75
-105
lines changed

7 files changed

+75
-105
lines changed

.vscode/c_cpp_properties.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"defines": [
1313
"SWITCH",
1414
"__SWITCH__",
15-
"DEBUG"
15+
"DEBUG",
16+
"VERSION=\"1.3.3.7\""
1617
],
1718
"compilerPath": "/opt/devkitpro/devkitA64/bin/aarch64-none-elf-g++",
1819
"cStandard": "c11",

libs/include/tesla.hpp

Lines changed: 21 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -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

31313092
extern "C" {

source/gui_error.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,22 @@ ErrorGui::ErrorGui(Result rc) {
2828
}
2929

3030
tsl::elm::Element *ErrorGui::createUI() {
31-
auto rootFrame = new tsl::elm::OverlayFrame("ovl-tune \u266B", VERSION);
31+
auto rootFrame = new tsl::elm::OverlayFrame("ShareNX \uE134", VERSION);
3232

3333
auto *custom = new tsl::elm::CustomDrawer([&](tsl::gfx::Renderer *drawer, u16 x, u16 y, u16 w, u16 h) {
34-
drawer->drawString("\uE150", false, (w - 90) / 2, 300, 90, 0xffff);
35-
drawer->drawString(this->m_msg, false, 55, 380, 25, 0xffff);
36-
if (this->m_result)
34+
static s32 msg_width = 0;
35+
if (msg_width == 0) {
36+
auto [width ,height] = drawer->drawString(this->m_msg, false, 0, 0, 25, tsl::style::color::ColorTransparent);
37+
msg_width = width;
38+
}
39+
drawer->drawString("\uE150", false, x + ((w - 90) / 2), 300, 90, 0xffff);
40+
drawer->drawString(this->m_msg, false, x + ((w - msg_width) / 2), 380, 25, 0xffff);
41+
if (this->m_result) {
3742
drawer->drawString(this->m_result, false, 120, 430, 25, 0xffff);
43+
}
3844
});
3945

4046
rootFrame->setContent(custom);
4147

4248
return rootFrame;
4349
}
44-
45-
bool ErrorGui::handleInput(u64, u64, touchPosition, JoystickPosition, JoystickPosition) {
46-
return false;
47-
}

source/gui_error.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,4 @@ class ErrorGui : public tsl::Gui {
2929
ErrorGui(Result rc);
3030

3131
virtual tsl::elm::Element *createUI() override;
32-
virtual bool handleInput(u64, u64, touchPosition, JoystickPosition, JoystickPosition) override;
3332
};

source/gui_main.cpp

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,50 +20,36 @@
2020
#include <string>
2121

2222
#include "gui_error.hpp"
23-
#include "image_item.hpp"
2423
#include "upload.hpp"
2524

2625
MainGui::MainGui(const CapsAlbumFileId &file_id, const u8 *rgba_buffer)
27-
: fileId(file_id), buffer(rgba_buffer) {}
26+
: fileId(file_id) {
27+
img = new ImageItem(file_id, rgba_buffer);
28+
}
2829

2930
MainGui::~MainGui() {}
3031

3132
tsl::elm::Element *MainGui::createUI() {
32-
auto rootFrame = new tsl::elm::OverlayFrame("ShareNX", "v1.0.1");
33-
34-
std::snprintf(this->appId, 0x11, "%016lX", this->fileId.application_id);
35-
36-
std::snprintf(this->date, 0x20, "%4d:%02d:%02d %02d:%02d:%02d",
37-
this->fileId.datetime.year,
38-
this->fileId.datetime.month,
39-
this->fileId.datetime.day,
40-
this->fileId.datetime.hour,
41-
this->fileId.datetime.minute,
42-
this->fileId.datetime.second);
33+
auto rootFrame = new tsl::elm::OverlayFrame("ShareNX \uE134", VERSION);
4334

4435
auto *list = new tsl::elm::List(2);
4536

46-
list->addItem(new ImageItem(this->buffer));
37+
list->addItem(this->img);
4738

4839
auto *button = new tsl::elm::ListItem("Upload");
4940
button->setClickListener([&](u64 keys) {
5041
if (keys && KEY_A && !this->uploaded) {
5142
this->url = web::UploadImage(this->fileId);
5243
this->uploaded = true;
53-
list->addItemPostponed(new tsl::elm::ListItem(url));
44+
list->addItem(new tsl::elm::ListItem(url));
5445
return true;
5546
}
5647
return false;
5748
});
5849
list->addItem(button);
59-
list->addItem(new tsl::elm::ListItem(this->appId));
60-
list->addItem(new tsl::elm::ListItem(this->date));
6150

6251
rootFrame->setContent(list);
6352

6453
return rootFrame;
6554
}
6655

67-
bool MainGui::handleInput(u64, u64, touchPosition, JoystickPosition, JoystickPosition) {
68-
return false;
69-
}

source/gui_main.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,20 @@
1818
#pragma once
1919
#include <tesla.hpp>
2020

21+
#include "image_item.hpp"
22+
2123
class MainGui : public tsl::Gui {
2224
private:
23-
char appId[0x11];
24-
char date[0x20];
25+
ImageItem *img;
2526
std::string url;
2627
bool uploaded = false;
2728
CapsAlbumFileId fileId;
28-
const u8 *buffer;
2929

3030
public:
31-
MainGui(const CapsAlbumFileId& fileId, const u8 *rgba_buffer);
31+
MainGui(const CapsAlbumFileId &fileId, const u8 *rgba_buffer);
3232
~MainGui();
3333

3434
virtual tsl::elm::Element *createUI() override;
3535

3636
virtual void update() override {}
37-
38-
virtual bool handleInput(u64 down, u64 held, touchPosition pos, JoystickPosition left, JoystickPosition right) override;
3937
};

source/image_item.hpp

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,50 @@ constexpr size_t IMG_SIZE = THUMB_WIDTH * THUMB_HEIGHT * 4;
88

99
class ImageItem : public tsl::elm::ListItem {
1010
private:
11+
CapsAlbumFileId fileId;
1112
const u8 *buffer;
1213
s32 img_x, img_y;
14+
char appId[0x11];
15+
char date[0x20];
16+
std::string url;
1317

1418
public:
15-
ImageItem(const u8 *image)
16-
: ListItem(""), buffer(image), img_x(), img_y() {}
19+
ImageItem(const CapsAlbumFileId &file_id, const u8 *image)
20+
: ListItem(""), fileId(file_id), buffer(image), img_x(), img_y(), url() {
21+
22+
std::snprintf(this->appId, 0x11, "%016lX", this->fileId.application_id);
23+
24+
std::snprintf(this->date, 0x20, "%4d:%02d:%02d %02d:%02d:%02d",
25+
this->fileId.datetime.year,
26+
this->fileId.datetime.month,
27+
this->fileId.datetime.day,
28+
this->fileId.datetime.hour,
29+
this->fileId.datetime.minute,
30+
this->fileId.datetime.second);
31+
}
1732

1833
virtual void draw(tsl::gfx::Renderer *renderer) override {
19-
if (this->img_x == 0 || this->img_y == 0) {
20-
this->img_x = this->getX() + ((this->getWidth() - THUMB_WIDTH) / 2);
21-
this->img_y = this->getY() + ((this->getHeight() - THUMB_HEIGHT) / 2);
22-
}
23-
renderer->drawRect(this->img_x, this->img_y, THUMB_WIDTH, THUMB_HEIGHT, 0xf000);
24-
renderer->drawBitmap(this->img_x, this->img_y, THUMB_WIDTH, THUMB_HEIGHT, this->buffer);
34+
u32 img_x = this->getX() + ((this->getWidth() - THUMB_WIDTH) / 2);
35+
renderer->drawRect(img_x, this->getY(), THUMB_WIDTH, THUMB_HEIGHT, 0xf000);
36+
renderer->drawBitmap(img_x, this->getY(), THUMB_WIDTH, THUMB_HEIGHT, this->buffer);
37+
38+
renderer->drawString(this->appId, false, this->getX() + 15, this->getY() + THUMB_HEIGHT + 25, 20, tsl::style::color::ColorText);
39+
renderer->drawString(this->date, false, this->getX() + 15, this->getY() + THUMB_HEIGHT + 55, 20, tsl::style::color::ColorText);
40+
41+
if (!url.empty())
42+
renderer->drawString(this->url.c_str(), false, this->getX() + 15, this->getY() + THUMB_HEIGHT + 85, 20, tsl::style::color::ColorText);
2543
}
2644

2745
virtual void layout(u16 parentX, u16 parentY, u16 parentWidth, u16 parentHeight) override {
28-
this->setBoundaries(this->getX(), this->getY(), this->getWidth(), THUMB_HEIGHT + 150);
46+
this->setBoundaries(this->getX(), this->getY(), this->getWidth(), THUMB_HEIGHT + 100);
2947
}
3048

3149
virtual tsl::elm::Element *requestFocus(tsl::elm::Element *, tsl::FocusDirection) {
3250
return nullptr;
3351
}
52+
53+
public:
54+
void setUrl(const std::string& url) {
55+
this->url = url;
56+
}
3457
};

0 commit comments

Comments
 (0)