mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-01-13 05:13:38 +00:00
Frequman widget gets a non owning reference to the database instead of copying (#1175)
-Get rid of -Weffc++ pointer member warnings by restricting copy of FreqManUIList -Add null checks -Remove unused macro
This commit is contained in:
parent
909f37f89b
commit
e1c519d71e
@ -32,11 +32,11 @@
|
|||||||
#include "string_format.hpp"
|
#include "string_format.hpp"
|
||||||
#include "ui_widget.hpp"
|
#include "ui_widget.hpp"
|
||||||
|
|
||||||
#define FREQMAN_DESC_MAX_LEN 24 // This is the number of characters that can be drawn in front of "R: TEXT..." before taking a full screen line
|
#define FREQMAN_DESC_MAX_LEN 24 // This is the number of characters that can be drawn in front of "R: TEXT..." before taking a full screen line
|
||||||
#define FREQMAN_MAX_PER_FILE 60 // Maximum of entries we can read. This is a hardware limit
|
#define FREQMAN_MAX_PER_FILE 100 // Maximum of entries we can read. This is a hardware limit
|
||||||
// It was tested and lowered to leave a bit of space to the caller
|
// It was tested and lowered to leave a bit of space to the caller
|
||||||
#define FREQMAN_MAX_PER_FILE_STR "60" // STRING OF FREQMAN_MAX_PER_FILE
|
|
||||||
#define FREQMAN_READ_BUF_SIZE 96 // max freqman line size including desc is 90, +6 for a bit of space
|
#define FREQMAN_READ_BUF_SIZE 96 // max freqman line size including desc is 90, +6 for a bit of space
|
||||||
|
|
||||||
using namespace ui;
|
using namespace ui;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -52,7 +52,7 @@ enum freqman_error {
|
|||||||
ERROR_DUPLICATE
|
ERROR_DUPLICATE
|
||||||
};
|
};
|
||||||
|
|
||||||
enum freqman_entry_type {
|
enum freqman_entry_type : uint8_t {
|
||||||
SINGLE = 0, // f=
|
SINGLE = 0, // f=
|
||||||
RANGE, // a=,b=
|
RANGE, // a=,b=
|
||||||
HAMRADIO, // r=,t=
|
HAMRADIO, // r=,t=
|
||||||
|
@ -36,7 +36,7 @@ FreqManUIList::FreqManUIList(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FreqManUIList::set_highlighted_index(int index) {
|
void FreqManUIList::set_highlighted_index(int index) {
|
||||||
if ((unsigned)(current_index + index) >= freqlist_db.size())
|
if (freqlist_db == nullptr || (unsigned)(current_index + index) >= freqlist_db->size())
|
||||||
return;
|
return;
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
index = 0;
|
index = 0;
|
||||||
@ -45,10 +45,10 @@ void FreqManUIList::set_highlighted_index(int index) {
|
|||||||
}
|
}
|
||||||
if (index >= freqlist_nb_lines) {
|
if (index >= freqlist_nb_lines) {
|
||||||
index = freqlist_nb_lines - 1;
|
index = freqlist_nb_lines - 1;
|
||||||
if ((unsigned)(current_index + index) < freqlist_db.size())
|
if ((unsigned)(current_index + index) < freqlist_db->size())
|
||||||
current_index++;
|
current_index++;
|
||||||
else
|
else
|
||||||
current_index = freqlist_db.size() - freqlist_nb_lines - 1;
|
current_index = freqlist_db->size() - freqlist_nb_lines - 1;
|
||||||
}
|
}
|
||||||
highlighted_index = index;
|
highlighted_index = index;
|
||||||
}
|
}
|
||||||
@ -66,17 +66,17 @@ void FreqManUIList::paint(Painter& painter) {
|
|||||||
r_widget_screen,
|
r_widget_screen,
|
||||||
Color::black());
|
Color::black());
|
||||||
// only return after clearing the screen so previous entries are not shown anymore
|
// only return after clearing the screen so previous entries are not shown anymore
|
||||||
if (freqlist_db.size() == 0)
|
if (freqlist_db == nullptr || freqlist_db->size() == 0)
|
||||||
return;
|
return;
|
||||||
// coloration if file is too big
|
// coloration if file is too big
|
||||||
auto text_color = &Styles::white;
|
auto text_color = &Styles::white;
|
||||||
if (freqlist_db.size() > FREQMAN_MAX_PER_FILE)
|
if (freqlist_db->size() > FREQMAN_MAX_PER_FILE)
|
||||||
text_color = &Styles::yellow;
|
text_color = &Styles::yellow;
|
||||||
uint8_t nb_lines = 0;
|
uint8_t nb_lines = 0;
|
||||||
for (uint8_t it = current_index; it < freqlist_db.size(); it++) {
|
for (uint8_t it = current_index; it < freqlist_db->size(); it++) {
|
||||||
uint8_t line_height = (int)nb_lines * char_height;
|
uint8_t line_height = (int)nb_lines * char_height;
|
||||||
if (line_height < (r.height() - char_height)) { // line is within the widget
|
if (line_height < (r.height() - char_height)) { // line is within the widget
|
||||||
std::string description = freqman_item_string(freqlist_db[it], 30);
|
std::string description = freqman_item_string(freqlist_db->at(it), 30);
|
||||||
if (nb_lines == highlighted_index) {
|
if (nb_lines == highlighted_index) {
|
||||||
const Rect r_highlighted_freq{0, r.location().y() + (int)nb_lines * char_height, 240, char_height};
|
const Rect r_highlighted_freq{0, r.location().y() + (int)nb_lines * char_height, 240, char_height};
|
||||||
painter.fill_rectangle(
|
painter.fill_rectangle(
|
||||||
@ -107,7 +107,7 @@ void FreqManUIList::paint(Painter& painter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FreqManUIList::set_db(freqman_db& db) {
|
void FreqManUIList::set_db(freqman_db& db) {
|
||||||
freqlist_db = db;
|
freqlist_db = &db;
|
||||||
if (db.size() == 0) {
|
if (db.size() == 0) {
|
||||||
current_index = 0;
|
current_index = 0;
|
||||||
highlighted_index = 0;
|
highlighted_index = 0;
|
||||||
|
@ -49,6 +49,8 @@ class FreqManUIList : public Widget {
|
|||||||
FreqManUIList()
|
FreqManUIList()
|
||||||
: FreqManUIList{{}, {}} {
|
: FreqManUIList{{}, {}} {
|
||||||
}
|
}
|
||||||
|
FreqManUIList(const FreqManUIList& other) = delete;
|
||||||
|
FreqManUIList& operator=(const FreqManUIList& other) = delete;
|
||||||
|
|
||||||
void paint(Painter& painter) override;
|
void paint(Painter& painter) override;
|
||||||
void on_focus() override;
|
void on_focus() override;
|
||||||
@ -64,7 +66,7 @@ class FreqManUIList : public Widget {
|
|||||||
private:
|
private:
|
||||||
static constexpr int8_t char_height = 16;
|
static constexpr int8_t char_height = 16;
|
||||||
bool instant_exec_{false};
|
bool instant_exec_{false};
|
||||||
freqman_db freqlist_db{};
|
freqman_db* freqlist_db{nullptr};
|
||||||
int current_index{0};
|
int current_index{0};
|
||||||
int highlighted_index{0};
|
int highlighted_index{0};
|
||||||
int freqlist_nb_lines{0};
|
int freqlist_nb_lines{0};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user