theme editor: various fixes

This commit is contained in:
Raphael Coeffic
2022-06-11 15:38:08 +02:00
committed by Raphael Coeffic
parent 9aa1a672f4
commit cf7fa3faea
7 changed files with 47 additions and 48 deletions
+3 -1
View File
@@ -64,7 +64,9 @@ void FileCarosell::setSelected(int n)
void FileCarosell::paint(BitmapBuffer *dc)
{
if (selected == -1 || _fileNames.size() == 0) {
const char *message = selected == -1 && _fileNames.size() > 0 ? "Loading..." : "No theme image";
const char *message = selected == -1 && _fileNames.size() > 0
? "Loading..."
: "No theme image";
dc->drawText(width() / 2, height() / 2, message, FONT(L) + CENTERED);
}
}
+6 -1
View File
@@ -100,7 +100,7 @@ void FullScreenDialog::paint(BitmapBuffer * dc)
} else if (type == WARNING_TYPE_CONFIRM) {
LcdFlags flags = FONT(BOLD);
int w = getTextWidth(STR_OK, flags);
int w = getTextWidth(STR_OK, 0, flags);
dc->drawText(ALERT_MESSAGE_LEFT, ALERT_ACTION_TOP,
STR_OK, flags);
@@ -158,6 +158,11 @@ void FullScreenDialog::runForever()
#if defined(HARDWARE_TOUCH)
mainWin->setTouchEnabled(true);
#endif
// reset input devices to avoid
// RELEASED/CLICKED to be called in a loop
lv_indev_reset(nullptr, nullptr);
while (running) {
resetBacklightTimeout();
+6 -1
View File
@@ -81,13 +81,18 @@ void ListBase::setAutoEdit(bool enable)
}
}
void ListBase::setName(uint16_t idx, const std::string& name)
{
lv_table_set_cell_value(lvobj, idx, 0, name.c_str());
}
void ListBase::setNames(const std::vector<std::string>& names)
{
setRowCount(names.size());
uint16_t row = 0;
for (const auto& name: names) {
lv_table_set_cell_value(lvobj, row, 0, name.c_str());
setName(row, name);
row++;
}
}
+1
View File
@@ -44,6 +44,7 @@ class ListBase : public TableField
bool getAutoEdit() const { return autoEdit; }
void setAutoEdit(bool enable);
void setName(uint16_t idx, const std::string& name);
void setNames(const std::vector<std::string>& names);
void setLineHeight(uint8_t height);
+23 -36
View File
@@ -457,45 +457,32 @@ void ThemeSetupPage::displayThemeMenu(Window *window, ThemePersistance *tp)
// you cant edit the default theme
if (listBox->getSelected() != 0) {
menu->addLine(STR_EDIT,
[=] () {
auto theme = tp->getThemeByIndex(currentTheme);
if (theme == nullptr) return;
menu->addLine(STR_EDIT, [=]() {
auto themeIdx = listBox->getSelected();
if (themeIdx < 0) return;
auto theme = tp->getThemeByIndex(themeIdx);
if (theme == nullptr) return;
new ThemeEditPage(*theme, [=](ThemeFile &theme) {
theme.serialize();
new ThemeEditPage(*theme,
[=](ThemeFile &theme) {
auto curTheme = tp->getThemeByIndex(currentTheme);
if (curTheme != nullptr) {
curTheme->setName(theme.getName());
curTheme->setAuthor(theme.getAuthor());
curTheme->setInfo(theme.getInfo());
// if the theme info currently displayed
// were changed, update the UI
if (themeIdx == currentTheme) {
setAuthor(&theme);
nameText->setText(theme.getName());
listBox->setName(currentTheme, theme.getName());
}
// update the colors that were edited
int n = 0;
for (auto color : theme.getColorList()) {
curTheme->setColorByIndex(n, color.colorValue);
n++;
}
// if the active theme changed, re-apply it
if (themeIdx == tp->getThemeIndex()) theme.applyTheme();
themeColorPreview->setColorList(theme.getColorList());
// save it to disk so it will come back the next time.
curTheme->serialize();
// if the active theme was edited then activate and update
// the UI
if (listBox->getSelected() == tp->getThemeIndex()) {
tp->applyTheme(listBox->getSelected());
setAuthor(&theme);
nameText->setText(theme.getName());
nameText->setTextFlags(COLOR_THEME_PRIMARY1);
authorText->setTextFlags(COLOR_THEME_PRIMARY1);
}
// the list of theme names might have changed
listBox->setNames(tp->getNames());
}
});
// update cached theme data
auto tp_theme = tp->getThemeByIndex(themeIdx);
if (!tp_theme) return;
*tp_theme = theme;
});
});
}
+1 -1
View File
@@ -254,7 +254,7 @@ bool ThemeFile::readNextLine(FIL &file, char *line, int maxlen)
if (f_gets(line, maxlen, &file) != NULL) {
int curlen = strlen(line) - 1;
if (line[curlen] == '\n') { // remove unwanted chars if file was edited using windows
if (line[curlen - 1] == '\r') {
if (curlen > 0 && line[curlen - 1] == '\r') {
line[curlen - 1] = 0;
} else {
line[curlen] = 0;
+7 -8
View File
@@ -56,7 +56,9 @@ class ThemeFile
}
ThemeFile(std::string themePath);
ThemeFile(const ThemeFile &theme)
ThemeFile(const ThemeFile &theme) :
colorList(theme.colorList),
_imageFileNames(theme._imageFileNames)
{
path = theme.path;
strncpy(name, theme.name, NAME_LENGTH);
@@ -65,13 +67,10 @@ class ThemeFile
author[AUTHOR_LENGTH] = '\0';
strncpy(info, theme.info, INFO_LENGTH);
info[INFO_LENGTH] = '\0';
colorList.assign(theme.colorList.begin(), theme.colorList.end());
}
virtual ~ThemeFile()
{
}
virtual ~ThemeFile() {}
ThemeFile& operator= (const ThemeFile& theme);
ThemeFile& operator= (const ThemeFile& theme);
void serialize();
@@ -168,8 +167,8 @@ class ThemePersistance
void applyTheme(int index)
{
if (index >= 0 && index < (int) themes.size()) {
auto theme = themes[index];
if (index >= 0 && index < (int)themes.size()) {
auto theme = themes[index];
theme->applyTheme();
}
}