mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-04-23 04:51:29 +00:00
High frequency load/save bugfix
Editing widgets hidden if freqman category is empty Textentry now trims strings up to cursor
This commit is contained in:
parent
08391bba4f
commit
c922a56b6d
@ -70,7 +70,7 @@ bool load_freqman_file(std::string& file_stem, freqman_db &db) {
|
|||||||
|
|
||||||
// Read frequency
|
// Read frequency
|
||||||
pos += 2;
|
pos += 2;
|
||||||
value = strtol(pos, nullptr, 10);
|
value = strtoll(pos, nullptr, 10);
|
||||||
|
|
||||||
// Read description until , or LF
|
// Read description until , or LF
|
||||||
pos = strstr(file_data, "d=");
|
pos = strstr(file_data, "d=");
|
||||||
@ -99,12 +99,14 @@ bool load_freqman_file(std::string& file_stem, freqman_db &db) {
|
|||||||
bool save_freqman_file(std::string& file_stem, freqman_db &db) {
|
bool save_freqman_file(std::string& file_stem, freqman_db &db) {
|
||||||
File freqman_file;
|
File freqman_file;
|
||||||
std::string item_string;
|
std::string item_string;
|
||||||
|
rf::Frequency f;
|
||||||
|
|
||||||
if (!create_freqman_file(file_stem, freqman_file))
|
if (!create_freqman_file(file_stem, freqman_file))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (size_t n = 0; n < db.entries.size(); n++) {
|
for (size_t n = 0; n < db.entries.size(); n++) {
|
||||||
item_string = "f=" + to_string_dec_uint(db.entries[n].value);
|
f = db.entries[n].value;
|
||||||
|
item_string = "f=" + to_string_dec_uint(f / 1000) + to_string_dec_uint(f % 1000UL, 3, '0'); // Please forgive me
|
||||||
|
|
||||||
if (db.entries[n].description.size())
|
if (db.entries[n].description.size())
|
||||||
item_string += ",d=" + db.entries[n].description;
|
item_string += ",d=" + db.entries[n].description;
|
||||||
|
@ -106,13 +106,11 @@ void FreqManBaseView::change_category(int32_t category_id) {
|
|||||||
|
|
||||||
void FreqManBaseView::refresh_list() {
|
void FreqManBaseView::refresh_list() {
|
||||||
if (!database.entries.size()) {
|
if (!database.entries.size()) {
|
||||||
menu_view.hidden(true);
|
if (on_refresh_widgets)
|
||||||
text_empty.hidden(false);
|
on_refresh_widgets(true);
|
||||||
display.fill_rectangle(menu_view.screen_rect(), Color::black());
|
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
menu_view.hidden(false);
|
if (on_refresh_widgets)
|
||||||
text_empty.hidden(true);
|
on_refresh_widgets(false);
|
||||||
|
|
||||||
menu_view.clear();
|
menu_view.clear();
|
||||||
|
|
||||||
@ -142,8 +140,8 @@ void FrequencySaveView::on_save_name() {
|
|||||||
|
|
||||||
void FrequencySaveView::on_save_timestamp() {
|
void FrequencySaveView::on_save_timestamp() {
|
||||||
database.entries.push_back({ value_, "", str_timestamp });
|
database.entries.push_back({ value_, "", str_timestamp });
|
||||||
nav_.pop();
|
|
||||||
save_freqman_file(file_list[current_category_id], database);
|
save_freqman_file(file_list[current_category_id], database);
|
||||||
|
nav_.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrequencySaveView::on_tick_second() {
|
void FrequencySaveView::on_tick_second() {
|
||||||
@ -197,21 +195,34 @@ FrequencySaveView::FrequencySaveView(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FrequencyLoadView::refresh_widgets(const bool v) {
|
||||||
|
menu_view.hidden(v);
|
||||||
|
text_empty.hidden(!v);
|
||||||
|
//display.fill_rectangle(menu_view.screen_rect(), Color::black());
|
||||||
|
set_dirty();
|
||||||
|
}
|
||||||
|
|
||||||
FrequencyLoadView::FrequencyLoadView(
|
FrequencyLoadView::FrequencyLoadView(
|
||||||
NavigationView& nav
|
NavigationView& nav
|
||||||
) : FreqManBaseView(nav, options_category)
|
) : FreqManBaseView(nav, options_category)
|
||||||
{
|
{
|
||||||
|
on_refresh_widgets = [this](bool v) {
|
||||||
|
refresh_widgets(v);
|
||||||
|
};
|
||||||
|
|
||||||
add_children({
|
add_children({
|
||||||
&menu_view,
|
&menu_view,
|
||||||
&text_empty
|
&text_empty
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Resize menu view to fill screen
|
||||||
|
menu_view.set_parent_rect({ 0, 3 * 8, 240, 29 * 8 });
|
||||||
|
|
||||||
// Just to allow exit on left
|
// Just to allow exit on left
|
||||||
menu_view.on_left = [&nav, this]() {
|
menu_view.on_left = [&nav, this]() {
|
||||||
nav.pop();
|
nav.pop();
|
||||||
};
|
};
|
||||||
|
|
||||||
text_empty.hidden(true);
|
|
||||||
change_category(0);
|
change_category(0);
|
||||||
refresh_list();
|
refresh_list();
|
||||||
|
|
||||||
@ -251,6 +262,16 @@ void FrequencyManagerView::on_delete() {
|
|||||||
refresh_list();
|
refresh_list();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FrequencyManagerView::refresh_widgets(const bool v) {
|
||||||
|
button_edit_freq.hidden(v);
|
||||||
|
button_edit_desc.hidden(v);
|
||||||
|
button_delete.hidden(v);
|
||||||
|
menu_view.hidden(v);
|
||||||
|
text_empty.hidden(!v);
|
||||||
|
//display.fill_rectangle(menu_view.screen_rect(), Color::black());
|
||||||
|
set_dirty();
|
||||||
|
}
|
||||||
|
|
||||||
FrequencyManagerView::~FrequencyManagerView() {
|
FrequencyManagerView::~FrequencyManagerView() {
|
||||||
//save_freqman_file(file_list[current_category_id], database);
|
//save_freqman_file(file_list[current_category_id], database);
|
||||||
}
|
}
|
||||||
@ -259,6 +280,10 @@ FrequencyManagerView::FrequencyManagerView(
|
|||||||
NavigationView& nav
|
NavigationView& nav
|
||||||
) : FreqManBaseView(nav, options_category)
|
) : FreqManBaseView(nav, options_category)
|
||||||
{
|
{
|
||||||
|
on_refresh_widgets = [this](bool v) {
|
||||||
|
refresh_widgets(v);
|
||||||
|
};
|
||||||
|
|
||||||
add_children({
|
add_children({
|
||||||
&labels,
|
&labels,
|
||||||
&button_new_category,
|
&button_new_category,
|
||||||
@ -274,7 +299,6 @@ FrequencyManagerView::FrequencyManagerView(
|
|||||||
nav.pop();
|
nav.pop();
|
||||||
};
|
};
|
||||||
|
|
||||||
text_empty.hidden(true);
|
|
||||||
change_category(0);
|
change_category(0);
|
||||||
refresh_list();
|
refresh_list();
|
||||||
|
|
||||||
@ -283,6 +307,7 @@ FrequencyManagerView::FrequencyManagerView(
|
|||||||
};
|
};
|
||||||
|
|
||||||
button_new_category.on_select = [this, &nav](Button&) {
|
button_new_category.on_select = [this, &nav](Button&) {
|
||||||
|
desc_buffer = "";
|
||||||
on_new_category(nav);
|
on_new_category(nav);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ protected:
|
|||||||
options_t categories { };
|
options_t categories { };
|
||||||
std::function<void(int32_t category_id)> on_change_category { nullptr };
|
std::function<void(int32_t category_id)> on_change_category { nullptr };
|
||||||
std::function<void(void)> on_select_frequency { nullptr };
|
std::function<void(void)> on_select_frequency { nullptr };
|
||||||
|
std::function<void(bool)> on_refresh_widgets { nullptr };
|
||||||
std::vector<std::string> file_list { };
|
std::vector<std::string> file_list { };
|
||||||
int32_t current_category_id { 0 };
|
int32_t current_category_id { 0 };
|
||||||
|
|
||||||
@ -133,6 +134,7 @@ public:
|
|||||||
FrequencyLoadView(NavigationView& nav);
|
FrequencyLoadView(NavigationView& nav);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void refresh_widgets(const bool v);
|
||||||
};
|
};
|
||||||
|
|
||||||
class FrequencyManagerView : public FreqManBaseView {
|
class FrequencyManagerView : public FreqManBaseView {
|
||||||
@ -143,6 +145,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::string desc_buffer { };
|
std::string desc_buffer { };
|
||||||
|
|
||||||
|
void refresh_widgets(const bool v);
|
||||||
void on_edit_freq(rf::Frequency f);
|
void on_edit_freq(rf::Frequency f);
|
||||||
void on_edit_desc(NavigationView& nav);
|
void on_edit_desc(NavigationView& nav);
|
||||||
void on_new_category(NavigationView& nav);
|
void on_new_category(NavigationView& nav);
|
||||||
|
@ -100,7 +100,7 @@ TextEntryView::TextEntryView(
|
|||||||
_str->erase(std::find_if(_str->rbegin(), _str->rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), _str->end());
|
_str->erase(std::find_if(_str->rbegin(), _str->rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), _str->end());
|
||||||
_cursor_pos = _str->length();
|
_cursor_pos = _str->length();
|
||||||
|
|
||||||
_str->resize(_max_length, 0);
|
_str->reserve(_max_length);
|
||||||
|
|
||||||
add_children({
|
add_children({
|
||||||
&text_input,
|
&text_input,
|
||||||
@ -108,6 +108,7 @@ TextEntryView::TextEntryView(
|
|||||||
});
|
});
|
||||||
|
|
||||||
button_ok.on_select = [this, &nav](Button&) {
|
button_ok.on_select = [this, &nav](Button&) {
|
||||||
|
_str->substr(0, _cursor_pos);
|
||||||
if (on_changed)
|
if (on_changed)
|
||||||
on_changed(_str);
|
on_changed(_str);
|
||||||
nav.pop();
|
nav.pop();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user