mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-05-02 06:46:21 -04:00
Added RFM69 helper
LGE tool: new frames Text entry string length bugfix
This commit is contained in:
parent
dd35bda197
commit
b1e72c788b
18 changed files with 417 additions and 130 deletions
|
@ -36,7 +36,7 @@ void AlphanumView::paint(Painter&) {
|
|||
|
||||
AlphanumView::AlphanumView(
|
||||
NavigationView& nav,
|
||||
std::string * str,
|
||||
std::string& str,
|
||||
size_t max_length
|
||||
) : TextEntryView(nav, str, max_length)
|
||||
{
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace ui {
|
|||
|
||||
class AlphanumView : public TextEntryView {
|
||||
public:
|
||||
AlphanumView(NavigationView& nav, std::string * str, size_t max_length);
|
||||
AlphanumView(NavigationView& nav, std::string& str, size_t max_length);
|
||||
|
||||
AlphanumView(const AlphanumView&) = delete;
|
||||
AlphanumView(AlphanumView&&) = delete;
|
||||
|
|
|
@ -29,10 +29,10 @@ using namespace portapack;
|
|||
|
||||
namespace ui {
|
||||
|
||||
void text_prompt(NavigationView& nav, std::string * str, const size_t max_length, const std::function<void(std::string *)> on_done) {
|
||||
void text_prompt(NavigationView& nav, std::string& str, const size_t max_length, const std::function<void(std::string&)> on_done) {
|
||||
//if (persistent_memory::ui_config_textentry() == 0) {
|
||||
auto te_view = nav.push<AlphanumView>(str, max_length);
|
||||
te_view->on_changed = [on_done](std::string * value) {
|
||||
te_view->on_changed = [on_done](std::string& value) {
|
||||
if (on_done)
|
||||
on_done(value);
|
||||
};
|
||||
|
@ -46,38 +46,40 @@ void text_prompt(NavigationView& nav, std::string * str, const size_t max_length
|
|||
}
|
||||
|
||||
void TextEntryView::update_text() {
|
||||
if (_cursor_pos <= 28)
|
||||
text_input.set(' ' + *_str + std::string(_max_length - _str->length(), ' '));
|
||||
if (cursor_pos < 30)
|
||||
text_input.set(_str + std::string(_max_length - _str.length(), ' '));
|
||||
else
|
||||
text_input.set('<' + _str->substr(_cursor_pos - 28, 28));
|
||||
text_input.set('<' + _str.substr(cursor_pos - 29, 29));
|
||||
|
||||
draw_cursor();
|
||||
}
|
||||
|
||||
void TextEntryView::char_delete() {
|
||||
if (!_cursor_pos) return;
|
||||
if (!cursor_pos) return;
|
||||
|
||||
_cursor_pos--;
|
||||
_str->replace(_cursor_pos, 1, 1, 0);
|
||||
cursor_pos--;
|
||||
_str.resize(cursor_pos);
|
||||
}
|
||||
|
||||
void TextEntryView::char_add(const char c) {
|
||||
if (_cursor_pos >= _max_length) return;
|
||||
if (cursor_pos >= _max_length) return;
|
||||
|
||||
_str->replace(_cursor_pos, 1, 1, c);
|
||||
_cursor_pos++;
|
||||
_str += c;
|
||||
cursor_pos++;
|
||||
}
|
||||
|
||||
void TextEntryView::draw_cursor() {
|
||||
Point draw_pos;
|
||||
|
||||
draw_pos = { text_input.screen_rect().location().x() + 8 + std::min((Coord)_cursor_pos, (Coord)28) * 8,
|
||||
draw_pos = { text_input.screen_rect().location().x() + std::min((Coord)cursor_pos, (Coord)28) * 8,
|
||||
text_input.screen_rect().location().y() + 16 };
|
||||
|
||||
// Erase previous
|
||||
display.fill_rectangle(
|
||||
{ { text_input.screen_rect().location().x(), draw_pos.y() }, { text_input.screen_rect().size().width(), 4 } },
|
||||
Color::black()
|
||||
);
|
||||
// Draw new
|
||||
display.fill_rectangle(
|
||||
{ draw_pos, { 8, 4 } },
|
||||
Color::white()
|
||||
|
@ -90,17 +92,19 @@ void TextEntryView::focus() {
|
|||
|
||||
TextEntryView::TextEntryView(
|
||||
NavigationView& nav,
|
||||
std::string * str,
|
||||
std::string& str,
|
||||
size_t max_length
|
||||
) : _str(str),
|
||||
_max_length(max_length)
|
||||
{
|
||||
|
||||
// Trim from right
|
||||
_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();
|
||||
//_str->erase(std::find_if(_str->rbegin(), _str->rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), _str->end());
|
||||
if (_str.length() > _max_length)
|
||||
_str.resize(_max_length);
|
||||
_str.reserve(_max_length);
|
||||
|
||||
_str->reserve(_max_length);
|
||||
cursor_pos = _str.length();
|
||||
|
||||
add_children({
|
||||
&text_input,
|
||||
|
@ -108,7 +112,7 @@ TextEntryView::TextEntryView(
|
|||
});
|
||||
|
||||
button_ok.on_select = [this, &nav](Button&) {
|
||||
_str->substr(0, _cursor_pos);
|
||||
_str.resize(cursor_pos);
|
||||
if (on_changed)
|
||||
on_changed(_str);
|
||||
nav.pop();
|
||||
|
|
|
@ -30,13 +30,13 @@ namespace ui {
|
|||
|
||||
class TextEntryView : public View {
|
||||
public:
|
||||
std::function<void(std::string*)> on_changed { };
|
||||
std::function<void(std::string&)> on_changed { };
|
||||
|
||||
void focus() override;
|
||||
std::string title() const override { return "Text entry"; };
|
||||
|
||||
protected:
|
||||
TextEntryView(NavigationView& nav, std::string * str, size_t max_length);
|
||||
TextEntryView(NavigationView& nav, std::string& str, size_t max_length);
|
||||
|
||||
TextEntryView(const TextEntryView&) = delete;
|
||||
TextEntryView(TextEntryView&&) = delete;
|
||||
|
@ -48,9 +48,9 @@ protected:
|
|||
void draw_cursor();
|
||||
void update_text();
|
||||
|
||||
std::string * _str;
|
||||
std::string& _str;
|
||||
size_t _max_length;
|
||||
uint32_t _cursor_pos { 0 };
|
||||
uint32_t cursor_pos { 0 };
|
||||
|
||||
Text text_input {
|
||||
{ 0, 0, 240, 16 }
|
||||
|
@ -62,7 +62,7 @@ protected:
|
|||
};
|
||||
};
|
||||
|
||||
void text_prompt(NavigationView& nav, std::string * str, size_t max_length, const std::function<void(std::string*)> on_done = nullptr);
|
||||
void text_prompt(NavigationView& nav, std::string& str, size_t max_length, const std::function<void(std::string&)> on_done = nullptr);
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue