mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-11-23 05:20:31 -05:00
frequency keypad opt (#2755)
* init * revert changes that caused by batch replace * revert changes that caused by batch replace * revert changes that caused by batch replace * revert submodu;e
This commit is contained in:
parent
375d1ad54e
commit
3f7b59f27e
2 changed files with 104 additions and 19 deletions
|
|
@ -275,29 +275,63 @@ FrequencyKeypadView::FrequencyKeypadView(
|
||||||
};
|
};
|
||||||
button.on_select = button_fn;
|
button.on_select = button_fn;
|
||||||
button.set_parent_rect({(n % 3) * button_w,
|
button.set_parent_rect({(n % 3) * button_w,
|
||||||
(n / 3) * button_h + 24,
|
(n / 3) * button_h + 25,
|
||||||
button_w, button_h});
|
button_w, button_h});
|
||||||
button.set_text(label);
|
button.set_text(label);
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
add_children({&button_save,
|
add_children({&button_save_ghz,
|
||||||
|
&button_save_khz,
|
||||||
|
&button_save_mhz,
|
||||||
&button_load,
|
&button_load,
|
||||||
&button_close});
|
&button_clear,
|
||||||
|
&button_done_ghz,
|
||||||
|
&button_done_mhz,
|
||||||
|
&button_done_khz});
|
||||||
|
|
||||||
button_save.on_select = [this, &nav](Button&) {
|
button_save_mhz.on_select = [this, &nav](Button&) {
|
||||||
nav.push<FrequencySaveView>(this->value());
|
nav.push<FrequencySaveView>(this->value(FrequencyUnit::MHZ)); // pass as mhz and handle unit convert logic there, cuz idk if pass others would loss something
|
||||||
};
|
};
|
||||||
|
button_save_ghz.on_select = [this, &nav](Button&) {
|
||||||
|
nav.push<FrequencySaveView>(this->value(FrequencyUnit::GHZ));
|
||||||
|
};
|
||||||
|
button_save_khz.on_select = [this, &nav](Button&) {
|
||||||
|
nav.push<FrequencySaveView>(this->value(FrequencyUnit::KHZ));
|
||||||
|
};
|
||||||
|
|
||||||
button_load.on_select = [this, &nav](Button&) {
|
button_load.on_select = [this, &nav](Button&) {
|
||||||
auto load_view = nav.push<FrequencyLoadView>();
|
auto load_view = nav.push<FrequencyLoadView>();
|
||||||
load_view->on_frequency_loaded = [this](rf::Frequency value) {
|
load_view->on_frequency_loaded = [this](rf::Frequency value) {
|
||||||
set_value(value);
|
set_value(value);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
button_clear.on_select = [this](Button&) {
|
||||||
|
mhz.clear();
|
||||||
|
submhz.clear();
|
||||||
|
clear_field_if_digits_entered = true;
|
||||||
|
if (state == State::DigitSubMHz) {
|
||||||
|
state = State::DigitMHz;
|
||||||
|
}
|
||||||
|
draw_input_hint();
|
||||||
|
update_text();
|
||||||
|
};
|
||||||
|
|
||||||
button_close.on_select = [this, &nav](Button&) {
|
button_done_ghz.on_select = [this, &nav](Button&) {
|
||||||
if (on_changed)
|
if (on_changed)
|
||||||
on_changed(this->value());
|
on_changed(this->value(FrequencyUnit::GHZ));
|
||||||
|
nav.pop();
|
||||||
|
};
|
||||||
|
|
||||||
|
button_done_mhz.on_select = [this, &nav](Button&) {
|
||||||
|
if (on_changed)
|
||||||
|
on_changed(this->value(FrequencyUnit::MHZ));
|
||||||
|
nav.pop();
|
||||||
|
};
|
||||||
|
|
||||||
|
button_done_khz.on_select = [this, &nav](Button&) {
|
||||||
|
if (on_changed)
|
||||||
|
on_changed(this->value(FrequencyUnit::KHZ));
|
||||||
nav.pop();
|
nav.pop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -305,11 +339,20 @@ FrequencyKeypadView::FrequencyKeypadView(
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrequencyKeypadView::focus() {
|
void FrequencyKeypadView::focus() {
|
||||||
button_close.focus();
|
button_done_mhz.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
rf::Frequency FrequencyKeypadView::value() const {
|
rf::Frequency FrequencyKeypadView::value(FrequencyUnit frequency_uni) const {
|
||||||
return mhz.as_int() * 1000000ULL + submhz.as_int() * submhz_base;
|
switch (frequency_uni) {
|
||||||
|
case FrequencyUnit::GHZ:
|
||||||
|
return mhz.as_int() * 1000000000ULL + submhz.as_int() * submhz_base * 1000;
|
||||||
|
case FrequencyUnit::MHZ:
|
||||||
|
return mhz.as_int() * 1000000ULL + submhz.as_int() * submhz_base;
|
||||||
|
case FrequencyUnit::KHZ:
|
||||||
|
return mhz.as_int() * 1000ULL + submhz.as_int() * submhz_base / 1000;
|
||||||
|
default:
|
||||||
|
return mhz.as_int() * 1000000ULL + submhz.as_int() * submhz_base;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrequencyKeypadView::set_value(const rf::Frequency new_value) {
|
void FrequencyKeypadView::set_value(const rf::Frequency new_value) {
|
||||||
|
|
@ -381,6 +424,25 @@ void FrequencyKeypadView::field_toggle() {
|
||||||
state = State::DigitMHz;
|
state = State::DigitMHz;
|
||||||
clear_field_if_digits_entered = true;
|
clear_field_if_digits_entered = true;
|
||||||
}
|
}
|
||||||
|
draw_input_hint();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FrequencyKeypadView::draw_input_hint() {
|
||||||
|
set_dirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FrequencyKeypadView::paint(Painter& painter) {
|
||||||
|
View::paint(painter);
|
||||||
|
|
||||||
|
const bool s = state == State::DigitMHz;
|
||||||
|
painter.draw_hline(
|
||||||
|
{0, 36},
|
||||||
|
8 * 4,
|
||||||
|
s ? Color::white() : Color::black());
|
||||||
|
painter.draw_hline(
|
||||||
|
{5 * 8, 36},
|
||||||
|
8 * 4,
|
||||||
|
s ? Color::black() : Color::white());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrequencyKeypadView::update_text() {
|
void FrequencyKeypadView::update_text() {
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,12 @@ extern options_db_t freqman_steps;
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
|
enum FrequencyUnit {
|
||||||
|
GHZ = 0,
|
||||||
|
MHZ,
|
||||||
|
KHZ,
|
||||||
|
};
|
||||||
|
|
||||||
class FrequencyField : public Widget {
|
class FrequencyField : public Widget {
|
||||||
public:
|
public:
|
||||||
std::function<void(rf::Frequency)> on_change{};
|
std::function<void(rf::Frequency)> on_change{};
|
||||||
|
|
@ -207,8 +213,9 @@ class FrequencyKeypadView : public View {
|
||||||
const rf::Frequency value);
|
const rf::Frequency value);
|
||||||
|
|
||||||
void focus() override;
|
void focus() override;
|
||||||
|
void paint(Painter& painter) override;
|
||||||
|
|
||||||
rf::Frequency value() const;
|
rf::Frequency value(FrequencyUnit frequency_uni) const;
|
||||||
void set_value(const rf::Frequency new_value);
|
void set_value(const rf::Frequency new_value);
|
||||||
bool on_encoder(const EncoderEvent delta) override;
|
bool on_encoder(const EncoderEvent delta) override;
|
||||||
bool on_keyboard(const KeyboardEvent key) override;
|
bool on_keyboard(const KeyboardEvent key) override;
|
||||||
|
|
@ -220,7 +227,6 @@ class FrequencyKeypadView : public View {
|
||||||
|
|
||||||
static constexpr int mhz_digits = 4;
|
static constexpr int mhz_digits = 4;
|
||||||
static constexpr int submhz_digits = 4;
|
static constexpr int submhz_digits = 4;
|
||||||
|
|
||||||
static constexpr int mhz_mod = pow(10, mhz_digits);
|
static constexpr int mhz_mod = pow(10, mhz_digits);
|
||||||
static constexpr int submhz_base = pow(10, 6 - submhz_digits);
|
static constexpr int submhz_base = pow(10, 6 - submhz_digits);
|
||||||
static constexpr int text_digits = mhz_digits + 1 + submhz_digits;
|
static constexpr int text_digits = mhz_digits + 1 + submhz_digits;
|
||||||
|
|
@ -230,15 +236,30 @@ class FrequencyKeypadView : public View {
|
||||||
|
|
||||||
std::array<Button, 12> buttons{};
|
std::array<Button, 12> buttons{};
|
||||||
|
|
||||||
Button button_save{
|
Button button_save_ghz{
|
||||||
{0, button_h * 5, 60, button_h},
|
{0, 14 * 16, 80 / 2 - 1, 2 * 16},
|
||||||
"Save"};
|
"GHz"};
|
||||||
|
Button button_save_khz{
|
||||||
|
{0 + 40 - 1, 14 * 16, 80 / 2, 2 * 16},
|
||||||
|
"kHz"};
|
||||||
|
Button button_save_mhz{
|
||||||
|
{0, 16 * 16, 80 - 1, 3 * 16},
|
||||||
|
"Save MHz"};
|
||||||
Button button_load{
|
Button button_load{
|
||||||
{60, button_h * 5, 60, button_h},
|
{80 + 1, 14 * 16, 80 - 2, 40},
|
||||||
"Load"};
|
"Load"};
|
||||||
Button button_close{
|
Button button_clear{
|
||||||
{128, button_h * 5, 112, button_h},
|
{80 + 1, 264, 80 - 2, 40},
|
||||||
"Done"};
|
"Clear"};
|
||||||
|
Button button_done_ghz{
|
||||||
|
{160 + 1, 14 * 16, 80 / 2 - 1, 2 * 16},
|
||||||
|
"GHz"};
|
||||||
|
Button button_done_khz{
|
||||||
|
{160 + 40, 14 * 16, 80 / 2 - 1, 2 * 16},
|
||||||
|
"kHz"};
|
||||||
|
Button button_done_mhz{
|
||||||
|
{160 + 1, 16 * 16, 80 - 2, 3 * 16},
|
||||||
|
"Done MHz"};
|
||||||
|
|
||||||
/* TODO: Template arg required in enum?! */
|
/* TODO: Template arg required in enum?! */
|
||||||
FieldString<mhz_digits> mhz{FieldString<4>::Justify::Right};
|
FieldString<mhz_digits> mhz{FieldString<4>::Justify::Right};
|
||||||
|
|
@ -254,6 +275,8 @@ class FrequencyKeypadView : public View {
|
||||||
|
|
||||||
void on_button(Button& button);
|
void on_button(Button& button);
|
||||||
|
|
||||||
|
void draw_input_hint();
|
||||||
|
|
||||||
void digit_add(const char c);
|
void digit_add(const char c);
|
||||||
void digit_delete();
|
void digit_delete();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue