Skip to content

Commit

Permalink
auto scroll the name list (#2358)
Browse files Browse the repository at this point in the history
* auto scroll the name list

* script

* remove uneeded empty line in script

* script
  • Loading branch information
zxkmm authored Nov 14, 2024
1 parent c8f236a commit 6c83825
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
39 changes: 37 additions & 2 deletions firmware/application/apps/ui_about_simple.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "ui_about_simple.hpp"

#define ROLL_SPEED_FRAME_PER_LINE 60
// cuz frame rate of pp screen is probably 60, scroll per sec

namespace ui {

// TODO: Generate this automatically from github
Expand Down Expand Up @@ -87,10 +90,42 @@ AboutView::AboutView(NavigationView& nav) {
}
}

void AboutView::on_frame_sync() {
if (interacted) return;

if (frame_sync_count++ % ROLL_SPEED_FRAME_PER_LINE == 0) {
const auto current = menu_view.highlighted_index();
const auto count = menu_view.item_count();

if (current < count - 1) {
menu_view.set_highlighted(current + 1);
} else {
menu_view.set_highlighted(0);
// ^ to go back to the REAL top instead of make the 2 at the top to make the title disappeares
menu_view.set_highlighted(2); // the first line that has human name
}
}
}

void AboutView::focus() {
button_ok.focus();
menu_view.set_highlighted(2); // the first line that has human name
}

bool AboutView::on_touch(const TouchEvent) {
interacted = true;
return false;
}

bool AboutView::on_key(const KeyEvent) {
interacted = true;
return false;
}

bool AboutView::on_encoder(const EncoderEvent) {
interacted = true;
menu_view.focus();
// put focus on last text line to make it more obvious that list is scrollable
menu_view.set_highlighted(10);
return false;
}

} /* namespace ui */
13 changes: 13 additions & 0 deletions firmware/application/apps/ui_about_simple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class AboutView : public View {
std::string title() const override { return "About"; };

private:
virtual bool on_key(const KeyEvent event);
virtual bool on_encoder(const EncoderEvent event);
virtual bool on_touch(const TouchEvent event);

bool interacted{false};
uint16_t frame_sync_count{0};
void on_frame_sync();
MenuView menu_view{
{0, 0, 240, 264},
true};
Expand All @@ -22,6 +29,12 @@ class AboutView : public View {
{240 / 3, 270, 240 / 3, 24},
"OK",
};

MessageHandlerRegistration message_handler_frame_sync{
Message::ID::DisplayFrameSync,
[this](const Message* const) {
this->on_frame_sync();
}};
};
} // namespace ui

Expand Down
39 changes: 37 additions & 2 deletions firmware/tools/generate_ui-about-simple.cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

cppheader = """#include "ui_about_simple.hpp"
#define ROLL_SPEED_FRAME_PER_LINE 60
// cuz frame rate of pp screen is probably 60, scroll per sec
namespace ui {
// Information: a line starting with a '#' will be yellow coloured
Expand Down Expand Up @@ -69,10 +72,42 @@
}
}
void AboutView::on_frame_sync() {
if (interacted) return;
if (frame_sync_count++ % ROLL_SPEED_FRAME_PER_LINE == 0) {
const auto current = menu_view.highlighted_index();
const auto count = menu_view.item_count();
if (current < count - 1) {
menu_view.set_highlighted(current + 1);
} else {
menu_view.set_highlighted(0);
// ^ to go back to the REAL top instead of make the 2 at the top to make the title disappeares
menu_view.set_highlighted(2); // the first line that has human name
}
}
}
void AboutView::focus() {
button_ok.focus();
menu_view.set_highlighted(2); // the first line that has human name
}
bool AboutView::on_touch(const TouchEvent) {
interacted = true;
return false;
}
bool AboutView::on_key(const KeyEvent) {
interacted = true;
return false;
}
bool AboutView::on_encoder(const EncoderEvent) {
interacted = true;
menu_view.focus();
// put focus on last text line to make it more obvious that list is scrollable
menu_view.set_highlighted(10);
return false;
}
} /* namespace ui */
Expand Down

0 comments on commit 6c83825

Please sign in to comment.