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