diff options
| author | JF002 <JF002@users.noreply.github.com> | 2020-10-04 10:21:22 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-04 10:21:22 (GMT) |
| commit | 39954bbd3afb592a0c3109e3479594183e8d0778 (patch) | |
| tree | 58efd04aa38b8dc7989c51fe3c9cdb9a3fb46a54 /src/displayapp/screens/DropDownDemo.cpp | |
| parent | 5adc97702c326d0252df6da75ce4ac244a4b3553 (diff) | |
| parent | 6c86d1d9d706706fcb6f214aba8259e61ed68755 (diff) | |
Merge pull request #68 from Avamander/patch-1
Rename folders to follow a consistent style
Diffstat (limited to 'src/displayapp/screens/DropDownDemo.cpp')
| -rw-r--r-- | src/displayapp/screens/DropDownDemo.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/displayapp/screens/DropDownDemo.cpp b/src/displayapp/screens/DropDownDemo.cpp new file mode 100644 index 0000000..735a0cc --- /dev/null +++ b/src/displayapp/screens/DropDownDemo.cpp @@ -0,0 +1,64 @@ +#include <libs/lvgl/lvgl.h> +#include <libraries/log/nrf_log.h> +#include "DropDownDemo.h" +#include "../DisplayApp.h" + +using namespace Pinetime::Applications::Screens; +extern lv_font_t jetbrains_mono_extrabold_compressed; +extern lv_font_t jetbrains_mono_bold_20; + +DropDownDemo::DropDownDemo(Pinetime::Applications::DisplayApp *app) : Screen(app) { + // Create the dropdown object, with many item, and fix its height + ddlist = lv_ddlist_create(lv_scr_act(), NULL); + lv_ddlist_set_options(ddlist, "Apple\n" + "Banana\n" + "Orange\n" + "Melon\n" + "Grape\n" + "Raspberry\n" + "A\n" + "B\n" + "C\n" + "D\n" + "E"); + lv_ddlist_set_fix_width(ddlist, 150); + lv_ddlist_set_draw_arrow(ddlist, true); + lv_ddlist_set_fix_height(ddlist, 150); + lv_obj_align(ddlist, NULL, LV_ALIGN_IN_TOP_MID, 0, 20); +} + +DropDownDemo::~DropDownDemo() { + // Reset the touchmode + app->SetTouchMode(DisplayApp::TouchModes::Gestures); + lv_obj_clean(lv_scr_act()); +} + +bool DropDownDemo::Refresh() { + auto* list = static_cast<lv_ddlist_ext_t *>(ddlist->ext_attr); + + // Switch touchmode to Polling if the dropdown is opened. This will allow to scroll inside the + // dropdown while it is opened. + // Disable the polling mode when the dropdown is closed to be able to handle the gestures. + if(list->opened) + app->SetTouchMode(DisplayApp::TouchModes::Polling); + else + app->SetTouchMode(DisplayApp::TouchModes::Gestures); + return running; +} + +bool DropDownDemo::OnButtonPushed() { + running = false; + return true; +} + +bool DropDownDemo::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + // If the dropdown is opened, notify Display app that it doesn't need to handle the event + // (this will prevent displayApp from going back to the menu or clock scree). + auto* list = static_cast<lv_ddlist_ext_t *>(ddlist->ext_attr); + if(list->opened) { + return true; + } else { + return false; + } +} + |
