mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-13 07:57:45 +00:00
Scanner persisted freq file, TextField for current item (#1403)
* Don't truncate string passed to Text widget * Focus TextField on touch like other fields * TextField for current, save last opened freq file
This commit is contained in:
@@ -366,16 +366,17 @@ void Text::paint(Painter& painter) {
|
||||
const auto rect = screen_rect();
|
||||
auto s = has_focus() ? style().invert() : style();
|
||||
auto max_len = (unsigned)rect.width() / s.font.char_width();
|
||||
auto text_view = std::string_view{text};
|
||||
|
||||
painter.fill_rectangle(rect, s.background);
|
||||
|
||||
if (text.length() > max_len)
|
||||
text.resize(max_len);
|
||||
if (text_view.length() > max_len)
|
||||
text_view = text_view.substr(0, max_len);
|
||||
|
||||
painter.draw_string(
|
||||
rect.location(),
|
||||
s,
|
||||
text);
|
||||
text_view);
|
||||
}
|
||||
|
||||
/* Labels ****************************************************************/
|
||||
@@ -1773,6 +1774,15 @@ bool TextField::on_encoder(EncoderEvent delta) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TextField::on_touch(TouchEvent event) {
|
||||
if (event.type == TouchEvent::Type::Start) {
|
||||
focus();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* NumberField ***********************************************************/
|
||||
|
||||
NumberField::NumberField(
|
||||
|
@@ -208,6 +208,10 @@ class Text : public Widget {
|
||||
void paint(Painter& painter) override;
|
||||
|
||||
protected:
|
||||
// NB: Don't truncate this string. The UI will only render
|
||||
// as many characters as will fit in its rectange.
|
||||
// Apps expect to be able to retrieve this string to avoid
|
||||
// needing to hold additional copies in memory.
|
||||
std::string text;
|
||||
};
|
||||
|
||||
@@ -703,6 +707,7 @@ class TextField : public Text {
|
||||
|
||||
bool on_key(KeyEvent key) override;
|
||||
bool on_encoder(EncoderEvent delta) override;
|
||||
bool on_touch(TouchEvent event) override;
|
||||
|
||||
private:
|
||||
using Text::set;
|
||||
|
Reference in New Issue
Block a user