2020-08-20 21:09:45 +02:00
|
|
|
#include "DropDownDemo.h"
|
2020-11-15 16:49:36 +01:00
|
|
|
#include <lvgl/lvgl.h>
|
|
|
|
#include <libraries/log/nrf_log.h>
|
2020-08-20 21:09:45 +02:00
|
|
|
#include "../DisplayApp.h"
|
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
DropDownDemo::DropDownDemo(Pinetime::Applications::DisplayApp* app) : Screen(app) {
|
2020-08-20 21:09:45 +02:00
|
|
|
// Create the dropdown object, with many item, and fix its height
|
2020-10-04 13:53:11 +02:00
|
|
|
ddlist = lv_ddlist_create(lv_scr_act(), nullptr);
|
2021-04-18 19:28:14 +02:00
|
|
|
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");
|
2020-08-20 21:09:45 +02:00
|
|
|
lv_ddlist_set_fix_width(ddlist, 150);
|
|
|
|
lv_ddlist_set_draw_arrow(ddlist, true);
|
|
|
|
lv_ddlist_set_fix_height(ddlist, 150);
|
2020-10-04 13:53:11 +02:00
|
|
|
lv_obj_align(ddlist, nullptr, LV_ALIGN_IN_TOP_MID, 0, 20);
|
2020-08-20 21:09:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DropDownDemo::~DropDownDemo() {
|
|
|
|
// Reset the touchmode
|
|
|
|
app->SetTouchMode(DisplayApp::TouchModes::Gestures);
|
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DropDownDemo::Refresh() {
|
2021-04-18 19:28:14 +02:00
|
|
|
auto* list = static_cast<lv_ddlist_ext_t*>(ddlist->ext_attr);
|
2020-08-20 21:09:45 +02:00
|
|
|
|
|
|
|
// 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.
|
2021-04-18 19:28:14 +02:00
|
|
|
if (list->opened)
|
2020-08-20 21:09:45 +02:00
|
|
|
app->SetTouchMode(DisplayApp::TouchModes::Polling);
|
|
|
|
else
|
|
|
|
app->SetTouchMode(DisplayApp::TouchModes::Gestures);
|
|
|
|
return running;
|
|
|
|
}
|
|
|
|
|
|
|
|
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).
|
2021-04-18 19:28:14 +02:00
|
|
|
auto* list = static_cast<lv_ddlist_ext_t*>(ddlist->ext_attr);
|
|
|
|
if (list->opened) {
|
2020-08-20 21:09:45 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|