mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-28 16:59:47 -05:00
Merged TxButton and Button & minor bug fix
This commit is contained in:
parent
d7568b820d
commit
911eb36210
@ -362,42 +362,42 @@ MicTXView::MicTXView(
|
||||
rx_lna = receiver_model.lna();
|
||||
field_rxlna.on_change = [this](int32_t v) {
|
||||
rx_lna = v;
|
||||
receiver_model.set_lna(v);
|
||||
if(rx_enabled)
|
||||
receiver_model.set_lna(v);
|
||||
};
|
||||
field_rxlna.set_value(rx_lna);
|
||||
|
||||
rx_vga = receiver_model.vga();
|
||||
field_rxvga.on_change = [this](int32_t v) {
|
||||
rx_vga = v;
|
||||
receiver_model.set_vga(v);
|
||||
if(rx_enabled)
|
||||
receiver_model.set_vga(v);
|
||||
};
|
||||
field_rxvga.set_value(rx_vga);
|
||||
|
||||
rx_amp = receiver_model.rf_amp();
|
||||
field_rxamp.on_change = [this](int32_t v) {
|
||||
rx_amp = v;
|
||||
receiver_model.set_rf_amp(rx_amp);
|
||||
if(rx_enabled)
|
||||
receiver_model.set_rf_amp(rx_amp);
|
||||
};
|
||||
field_rxamp.set_value(rx_amp);
|
||||
|
||||
tx_button.on_select = [this](TxButton&) {
|
||||
tx_button.on_select = [this](Button&) {
|
||||
if(ptt_enabled && !transmitting) {
|
||||
button_touch = true;
|
||||
set_tx(true);
|
||||
}
|
||||
};
|
||||
|
||||
tx_button.on_release = [this](TxButton&) {
|
||||
tx_button.on_touch_release = [this](Button&) {
|
||||
if(button_touch) {
|
||||
button_touch = false;
|
||||
set_tx(false);
|
||||
}
|
||||
};
|
||||
|
||||
tx_button.on_buttonpress = [this](TxButton&) {
|
||||
if(ptt_enabled && !transmitting) {
|
||||
set_tx(true);
|
||||
}
|
||||
tx_button.on_touch_press = [this](Button&) {
|
||||
button_touch = true;
|
||||
};
|
||||
|
||||
transmitter_model.set_sampling_rate(sampling_rate);
|
||||
|
@ -97,7 +97,7 @@ private:
|
||||
rf::Frequency tx_frequency { 0 };
|
||||
rf::Frequency rx_frequency { 0 };
|
||||
int32_t focused_ui { 2 };
|
||||
bool button_touch { true };
|
||||
bool button_touch { false };
|
||||
|
||||
|
||||
Labels labels {
|
||||
@ -267,9 +267,10 @@ private:
|
||||
' ',
|
||||
};
|
||||
|
||||
TxButton tx_button {
|
||||
Button tx_button {
|
||||
{ 10 * 8, 30 * 8, 10 * 8, 5 * 8 },
|
||||
"TX"
|
||||
"TX",
|
||||
true
|
||||
};
|
||||
|
||||
|
||||
|
@ -827,9 +827,11 @@ bool Checkbox::on_touch(const TouchEvent event) {
|
||||
|
||||
Button::Button(
|
||||
Rect parent_rect,
|
||||
std::string text
|
||||
std::string text,
|
||||
bool instant_exec
|
||||
) : Widget { parent_rect },
|
||||
text_ { text }
|
||||
text_ { text },
|
||||
instant_exec_ { instant_exec }
|
||||
{
|
||||
set_focusable(true);
|
||||
}
|
||||
@ -899,15 +901,24 @@ bool Button::on_touch(const TouchEvent event) {
|
||||
case TouchEvent::Type::Start:
|
||||
set_highlighted(true);
|
||||
set_dirty();
|
||||
if( on_touch_press) {
|
||||
on_touch_press(*this);
|
||||
}
|
||||
if( on_select && instant_exec_ ) {
|
||||
on_select(*this);
|
||||
}
|
||||
return true;
|
||||
|
||||
|
||||
case TouchEvent::Type::End:
|
||||
set_highlighted(false);
|
||||
set_dirty();
|
||||
if( on_select ) {
|
||||
if( on_select && !instant_exec_ ) {
|
||||
on_select(*this);
|
||||
}
|
||||
if( on_touch_release) {
|
||||
on_touch_release(*this);
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
@ -946,101 +957,6 @@ bool Button::on_touch(const TouchEvent event) {
|
||||
#endif
|
||||
}
|
||||
|
||||
/* TxButton ****************************************************************/
|
||||
|
||||
TxButton::TxButton(
|
||||
Rect parent_rect,
|
||||
std::string text
|
||||
) : Widget { parent_rect },
|
||||
text_ { text }
|
||||
{
|
||||
set_focusable(true);
|
||||
}
|
||||
|
||||
void TxButton::set_text(const std::string value) {
|
||||
text_ = value;
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
std::string TxButton::text() const {
|
||||
return text_;
|
||||
}
|
||||
|
||||
void TxButton::paint(Painter& painter) {
|
||||
Color bg, fg;
|
||||
const auto r = screen_rect();
|
||||
|
||||
if (has_focus() || highlighted()) {
|
||||
bg = style().foreground;
|
||||
fg = Color::black();
|
||||
} else {
|
||||
bg = Color::grey();
|
||||
fg = style().foreground;
|
||||
}
|
||||
|
||||
const Style paint_style = { style().font, bg, fg };
|
||||
|
||||
painter.draw_rectangle({r.location(), {r.size().width(), 1}}, Color::light_grey());
|
||||
painter.draw_rectangle({r.location().x(), r.location().y() + r.size().height() - 1, r.size().width(), 1}, Color::dark_grey());
|
||||
painter.draw_rectangle({r.location().x() + r.size().width() - 1, r.location().y(), 1, r.size().height()}, Color::dark_grey());
|
||||
|
||||
painter.fill_rectangle(
|
||||
{ r.location().x(), r.location().y() + 1, r.size().width() - 1, r.size().height() - 2 },
|
||||
paint_style.background
|
||||
);
|
||||
|
||||
const auto label_r = paint_style.font.size_of(text_);
|
||||
painter.draw_string(
|
||||
{ r.location().x() + (r.size().width() - label_r.width()) / 2, r.location().y() + (r.size().height() - label_r.height()) / 2 },
|
||||
paint_style,
|
||||
text_
|
||||
);
|
||||
}
|
||||
|
||||
void TxButton::on_focus() {
|
||||
if( on_highlight )
|
||||
on_highlight(*this);
|
||||
}
|
||||
|
||||
bool TxButton::on_key(const KeyEvent key) {
|
||||
if( key == KeyEvent::Select ) {
|
||||
if( on_buttonpress ) {
|
||||
on_buttonpress(*this);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if( on_dir ) {
|
||||
return on_dir(*this, key);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TxButton::on_touch(const TouchEvent event) {
|
||||
switch(event.type) {
|
||||
case TouchEvent::Type::Start:
|
||||
set_highlighted(true);
|
||||
set_dirty();
|
||||
if( on_select ) {
|
||||
on_select(*this);
|
||||
}
|
||||
return true;
|
||||
|
||||
|
||||
case TouchEvent::Type::End:
|
||||
set_highlighted(false);
|
||||
set_dirty();
|
||||
if( on_release ) {
|
||||
on_release(*this);
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* NewButton ****************************************************************/
|
||||
|
||||
NewButton::NewButton(
|
||||
|
@ -378,10 +378,18 @@ private:
|
||||
class Button : public Widget {
|
||||
public:
|
||||
std::function<void(Button&)> on_select { };
|
||||
std::function<void(Button&)> on_touch_release { }; // Executed when releasing touch, after on_select.
|
||||
std::function<void(Button&)> on_touch_press { }; // Executed when touching, before on_select.
|
||||
std::function<bool(Button&, KeyEvent)> on_dir { };
|
||||
std::function<void(Button&)> on_highlight { };
|
||||
|
||||
Button(Rect parent_rect, std::string text);
|
||||
Button(Rect parent_rect, std::string text, bool instant_exec); // instant_exec: Execute on_select when you touching instead of releasing
|
||||
Button(
|
||||
Rect parent_rect,
|
||||
std::string text
|
||||
) : Button { parent_rect, text, false }
|
||||
{
|
||||
}
|
||||
|
||||
Button(
|
||||
) : Button { { }, { } }
|
||||
@ -399,34 +407,7 @@ public:
|
||||
|
||||
private:
|
||||
std::string text_;
|
||||
};
|
||||
|
||||
class TxButton : public Widget {
|
||||
public:
|
||||
std::function<void(TxButton&)> on_select { }; // Touch only.
|
||||
std::function<void(TxButton&)> on_release { }; // Touch only. There's no way (or complicated) for detecting a button's release :(
|
||||
std::function<void(TxButton&)> on_buttonpress { };
|
||||
std::function<bool(TxButton&, KeyEvent)> on_dir { };
|
||||
std::function<void(TxButton&)> on_highlight { };
|
||||
|
||||
TxButton(Rect parent_rect, std::string text);
|
||||
|
||||
TxButton(
|
||||
) : TxButton { { }, { } }
|
||||
{
|
||||
}
|
||||
|
||||
void set_text(const std::string value);
|
||||
std::string text() const;
|
||||
|
||||
void paint(Painter& painter) override;
|
||||
|
||||
void on_focus() override;
|
||||
bool on_key(const KeyEvent key) override;
|
||||
bool on_touch(const TouchEvent event) override;
|
||||
|
||||
private:
|
||||
std::string text_;
|
||||
bool instant_exec_ { false };
|
||||
};
|
||||
|
||||
class NewButton : public Widget {
|
||||
|
Loading…
Reference in New Issue
Block a user