Scrolling is now handled 100% by LVGL

This commit is contained in:
Raphael Coeffic
2022-06-11 15:38:08 +02:00
committed by Raphael Coeffic
parent 131e26cfa0
commit 12f51350ce
35 changed files with 38 additions and 85 deletions
@@ -602,8 +602,6 @@ void ModuleOptions::update()
grid.nextLine();
grid.spacer(PAGE_PADDING);
form->setInnerHeight(grid.getWindowHeight());
form->setHeight(form->getInnerHeight());
content->adjustHeight();
content->setWindowCentered();
@@ -918,12 +916,6 @@ void RxOptions::update()
grid.nextLine();
grid.spacer(PAGE_PADDING);
form->setInnerHeight(grid.getWindowHeight());
if (form->getInnerHeight() < LCD_H - 2*POPUP_HEADER_HEIGHT) {
form->setHeight(form->getInnerHeight());
} else {
form->setHeight(LCD_H - 2*POPUP_HEADER_HEIGHT);
}
content->adjustHeight();
content->setWindowCentered();
-1
View File
@@ -224,7 +224,6 @@ bool ColorEditor::onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t sta
y -= BAR_TOP_MARGIN;
auto value = _colorType->screenToValue(i, y);
if (value != _colorType->barInfo[i].value) {
slidingWindow = this;
_colorType->barInfo[i].value = value;
setRGB();
}
@@ -94,7 +94,6 @@ bool ColorEditorContent::onTouchSlide(coord_t x, coord_t y, coord_t startX, coor
if (touchState.event == TE_SLIDE_END) {
sliding = false;
colorPicking = false;
slidingWindow = nullptr;
invalidate();
} else if (sliding) {
x -= SCREEN_LEFT_MARGIN;
@@ -102,7 +101,6 @@ bool ColorEditorContent::onTouchSlide(coord_t x, coord_t y, coord_t startX, coor
x = min(x, MAX_HUE);
if (hue != x) {
hue = x;
slidingWindow = this; // KLK: (Hack IMHO) so we get the end slide message
setRGB();
}
} else if (colorPicking) {
@@ -237,13 +235,15 @@ ColorEditorPopup::ColorEditorPopup(Window *window, std::function<uint32_t ()> ge
#if defined(HARDWARE_TOUCH)
bool ColorEditorPopup::onTouchStart(coord_t x, coord_t y)
{
content->onTouchStart(x - content->rect.x + content->scrollPositionX, y - content->rect.y + content->scrollPositionY);
TRACE("ColorEditorPopup::onTouchStart");
// content->onTouchStart(x - content->rect.x + content->scrollPositionX, y - content->rect.y + content->scrollPositionY);
return true;
}
bool ColorEditorPopup::onTouchEnd(coord_t x, coord_t y)
{
content->onTouchEnd(x - content->rect.x + content->scrollPositionX, y - content->rect.y + content->scrollPositionY);
TRACE("ColorEditorPopup::onTouchEnd");
// content->onTouchEnd(x - content->rect.x + content->scrollPositionX, y - content->rect.y + content->scrollPositionY);
if (!Window::onTouchEnd(x, y) && closeWhenClickOutside) {
onKeyPress();
deleteLater();
-2
View File
@@ -112,7 +112,6 @@ void CurveDataEdit::update()
0, RIGHT);
}
setInnerWidth(curvePointsCount * boxWidth);
}
void CurveDataEdit::paint(BitmapBuffer * dc)
@@ -120,7 +119,6 @@ void CurveDataEdit::paint(BitmapBuffer * dc)
dc->clear(COLOR_THEME_SECONDARY3);
// dc->drawSolidHorizontalLine(0, rect.h / 3, getInnerWidth(), 0);
// dc->drawSolidHorizontalLine(0, 2 * rect.h / 3, getInnerWidth(), 0);
drawHorizontalScrollbar(dc);
}
CurveEdit::CurveEdit(Window * parent, const rect_t & rect, uint8_t index) :
@@ -127,7 +127,6 @@ class FailSafeBody : public FormGroup
});
grid.nextLine();
setInnerHeight(grid.getWindowHeight() + PAGE_PADDING);
}
protected:
+1 -1
View File
@@ -62,7 +62,7 @@ coord_t FilePreview::getBitmapHeight() const
void FilePreview::paint(BitmapBuffer *dc)
{
dc->setFormat(BMP_RGB565);
coord_t y = _drawCentered ? parent->getScrollPositionY() + 2 : 2;
coord_t y = /*_drawCentered ? parent->getScrollPositionY() + 2 :*/ 2;
coord_t h = _drawCentered ? MENU_BODY_HEIGHT - 4 : rect.h;
if (bitmap != nullptr) {
coord_t bitmapHeight = min<coord_t>(h, bitmap->height());
+6 -8
View File
@@ -42,7 +42,6 @@ ListBase::ListBase(Window *parent, const rect_t &rect, std::vector<std::string>
#if defined(HARDWARE_TOUCH)
duration10ms = 0;
#endif
setInnerHeight(names.size() * lineHeight);
if (_getValue != nullptr)
setSelected(_getValue());
else
@@ -58,7 +57,7 @@ void ListBase::setSelected(int selected)
if(selectionType == LISTBOX_SINGLE_SELECT) {
if (selected != this->selected) {
this->selected = selected;
setScrollPositionY(lineHeight * this->selected - lineHeight);
lv_obj_scroll_to_y(lvobj, lineHeight * this->selected - lineHeight, LV_ANIM_OFF);
if (_setValue != nullptr) {
_setValue(this->selected);
}
@@ -143,8 +142,7 @@ void ListBase::paint(BitmapBuffer *dc)
curY += lineHeight;
}
if (!(windowFlags & (FORM_NO_BORDER | FORM_FORWARD_FOCUS))) {
dc->drawSolidRect(0, getScrollPositionY(), rect.w, rect.h, 2,
COLOR_THEME_FOCUS);
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, COLOR_THEME_FOCUS);
}
}
@@ -195,10 +193,10 @@ void ListBase::paint(BitmapBuffer *dc)
bool ListBase::isLongPress()
{
unsigned int curTimer = getTicks();
return (slidingWindow == nullptr && duration10ms != 0 && curTimer - duration10ms > LONG_PRESS_10MS);
return // slidingWindow == nullptr &&
duration10ms != 0 && curTimer - duration10ms > LONG_PRESS_10MS;
}
void ListBase::checkEvents(void)
{
Window::checkEvents();
@@ -234,7 +232,6 @@ bool ListBase::onTouchStart(coord_t x, coord_t y)
duration10ms = getTicks();
}
captureWindow(this);
yDown = y;
return true; // stop the processing and say that i handled it
@@ -243,7 +240,8 @@ bool ListBase::onTouchStart(coord_t x, coord_t y)
bool ListBase::onTouchEnd(coord_t x, coord_t y)
{
if (!isEnabled()) return false;
if (slidingWindow || waslongpress)
if (// slidingWindow ||
waslongpress)
return false; // if we slide then this is not a selection
auto selected = yDown / lineHeight;
-1
View File
@@ -96,7 +96,6 @@ class ListBase : public FormField
inline void setNames(std::vector<std::string> names)
{
this->names.assign(names.begin(), names.end());
setInnerHeight(names.size() * lineHeight);
invalidate();
}
-1
View File
@@ -408,5 +408,4 @@ void ModelCurvesPage::build(FormWindow * window, int8_t focusIndex)
grid.nextLine();
#endif
window->setInnerHeight(grid.getWindowHeight());
}
@@ -229,5 +229,4 @@ void ModelFlightModesPage::build(FormWindow * window)
return trimsCheckTimer;
});
window->setInnerHeight(y + 40);
}
-2
View File
@@ -342,7 +342,6 @@ void GVarEditWindow::buildBody(FormWindow * window)
setProperties();
window->setInnerHeight(grid.getWindowHeight());
}
void ModelGVarsPage::rebuild(FormWindow * window)
@@ -380,5 +379,4 @@ void ModelGVarsPage::build(FormWindow * window)
grid.nextLine(button->height());
}
window->setInnerHeight(grid.getWindowHeight());
}
-8
View File
@@ -88,12 +88,4 @@ void ModelHeliPage::build(FormWindow* form)
GET_SET_DEFAULT(g_model.swashR.collectiveWeight));
auto obj = form->getLvObj();
lv_obj_update_layout(obj);
lv_coord_t h =
lv_obj_get_height(obj)
+ lv_obj_get_scroll_top(obj)
+ lv_obj_get_scroll_bottom(obj);
form->setInnerHeight(h);
}
-3
View File
@@ -175,7 +175,6 @@ class InputEditWindow : public Page
#if LCD_W > LCD_H
auto BODY_WIDTH = LCD_W - preview.width() - PAGE_PADDING;
body.setWidth(BODY_WIDTH);
body.setInnerWidth(BODY_WIDTH);
body.setLeft(preview.width() + PAGE_PADDING);
#else
body.setRect({0, INPUT_EDIT_CURVE_TOP + INPUT_EDIT_CURVE_HEIGHT, LCD_W,
@@ -377,7 +376,6 @@ class InputEditWindow : public Page
grid.nextLine();
#endif
window->setInnerHeight(grid.getWindowHeight());
}
};
@@ -644,7 +642,6 @@ void ModelInputsPage::build(FormWindow *window, int8_t focusIndex)
grid.nextLine();
window->setInnerHeight(grid.getWindowHeight());
}
// TODO port: avoid global s_currCh on ARM boards (as done here)...
@@ -447,5 +447,4 @@ void ModelLogicalSwitchesPage::build(FormWindow* window, int8_t focusIndex)
grid.nextLine();
window->setInnerHeight(grid.getWindowHeight());
}
@@ -150,7 +150,6 @@ class ScriptEditWindow : public Page {
grid.addWindow(gOutputs);
}
window->setInnerHeight(grid.getWindowHeight());
if (focusScript) { fc->setFocus(); }
}
@@ -298,7 +297,6 @@ void ModelMixerScriptsPage::build(FormWindow * window, int8_t focusIdx)
}
grid.nextLine();
window->setInnerHeight(grid.getWindowHeight());
}
void ModelMixerScriptsPage::editLine(FormWindow * window, uint8_t idx)
-2
View File
@@ -247,7 +247,6 @@ class MixEditWindow : public Page
edit->setSuffix("s");
grid.nextLine();
window->setInnerHeight(grid.getWindowHeight());
}
// TODO share this code with INPUT
@@ -575,7 +574,6 @@ void ModelMixesPage::build(FormWindow * window, int8_t focusMixIndex)
grid.nextLine();
window->setInnerHeight(grid.getWindowHeight());
}
void deleteMix(uint8_t idx)
-2
View File
@@ -191,7 +191,6 @@ class OutputEditWindow : public Page
GET_SET_DEFAULT(output->symetrical));
grid.nextLine();
window->setInnerHeight(grid.getWindowHeight());
}
};
@@ -384,7 +383,6 @@ void ModelOutputsPage::build(FormWindow *window, int8_t focusChannel)
grid.nextLine();
window->setInnerHeight(grid.getWindowHeight());
}
void ModelOutputsPage::editOutput(FormWindow *window, uint8_t channel)
-4
View File
@@ -189,7 +189,6 @@ class SelectTemplate : public TemplatePage
tb->setHeight(PAGE_LINE_HEIGHT * 2);
grid.spacer(tb->height() + 5);
}
body.setInnerHeight(grid.getWindowHeight());
}
f_closedir(&dir);
@@ -295,7 +294,6 @@ class SelectTemplateFolder : public TemplatePage
tfb->setHeight(PAGE_LINE_HEIGHT * 2);
grid.spacer(tfb->height() + 5);
}
body.setInnerHeight(grid.getWindowHeight());
#if not defined(LUA)
}
#endif
@@ -601,7 +599,6 @@ class ModelCategoryPageBody : public FormWindow
if (index % MODEL_CELLS_PER_LINE != 0) {
y += MODEL_SELECT_CELL_HEIGHT + MODEL_CELL_PADDING;
}
setInnerHeight(y);
if (category->empty()) {
setFocus();
@@ -783,7 +780,6 @@ class CategoryEditPage : public PageTab
grid.nextLine();
window->setInnerHeight(grid.getWindowHeight());
if(scrolltobot) {
lv_obj_scroll_to_y(window->getLvObj(), y + 40, LV_ANIM_OFF);
-2
View File
@@ -375,7 +375,5 @@ void ModelSetupPage::build(FormWindow * window)
grid.addWindow(new TrainerModuleWindow(window, {0, grid.getWindowHeight(), LCD_W, 0}));
}
window->setInnerHeight(grid.getWindowHeight());
}
@@ -416,7 +416,6 @@ class SensorEditWindow : public Page {
updateSensorParametersWindow();
grid.addWindow(sensorParametersWindow);
window->setInnerHeight(grid.getWindowHeight());
}
};
@@ -647,5 +646,4 @@ void ModelTelemetryPage::build(FormWindow * window, int8_t focusSensorIndex)
GET_SET_DEFAULT(g_model.varioData.centerSilent));
grid.nextLine();
window->setInnerHeight(grid.getWindowHeight());
}
@@ -517,5 +517,4 @@ void RadioHardwarePage::build(FormWindow * window)
new StaticText(window, grid.getLabelSlot());
#endif
window->setInnerHeight(grid.getWindowHeight());
}
@@ -474,7 +474,6 @@ void RadioSdManagerPage::build(FormWindow * window)
}
}
window->setInnerHeight(grid.getWindowHeight());
preview->setHeight(max(window->height(), grid.getWindowHeight()));
}
-1
View File
@@ -530,7 +530,6 @@ void RadioSetupPage::build(FormWindow * window)
grid.nextLine();
#endif
window->setInnerHeight(grid.getWindowHeight());
}
void RadioSetupPage::updateBacklightControls()
-1
View File
@@ -388,5 +388,4 @@ void RadioToolsPage::rebuild(FormWindow * window)
}
#endif
window->setInnerHeight(grid.getWindowHeight());
}
@@ -24,24 +24,21 @@
SelectFabCarousel::SelectFabCarousel(Window* parent) :
FormGroup(parent, {}, FORM_FORWARD_FOCUS | NO_SCROLLBAR)
{
setPageWidth(FAB_BUTTON_SIZE + SELECT_BUTTON_BORDER);
setHeight(FAB_BUTTON_SIZE + 2 * PAGE_LINE_HEIGHT + SELECT_BUTTON_BORDER / 2);
}
void SelectFabCarousel::setMaxButtons(uint8_t max)
{
maxButtons = max;
setWidth(maxButtons * pageWidth);
setWidth(maxButtons * (FAB_BUTTON_SIZE + SELECT_BUTTON_BORDER));
}
void SelectFabCarousel::addButton(uint8_t icon, const char* title,
std::function<uint8_t(void)> pressHandler)
{
coord_t y_pos = 0;
coord_t x_pos = pageWidth * buttons;
coord_t x_pos = (FAB_BUTTON_SIZE + SELECT_BUTTON_BORDER) * buttons;
buttons++;
new SelectFabButton(this, x_pos, y_pos, icon, title, pressHandler);
setInnerWidth(pageWidth * buttons);
}
@@ -751,5 +751,4 @@ void SpecialFunctionsPage::build(FormWindow *window, int8_t focusIndex)
grid.nextLine();
// window->setLastField();
window->setInnerHeight(grid.getWindowHeight());
}
-1
View File
@@ -68,7 +68,6 @@ TabsCarousel::TabsCarousel(Window* parent, TabsGroup* menu) :
void TabsCarousel::updateInnerWidth()
{
setInnerWidth(padding_left + MENU_HEADER_BUTTON_WIDTH * menu->tabs.size());
}
void TabsCarousel::paint(BitmapBuffer * dc)
-1
View File
@@ -39,7 +39,6 @@ AboutUs::AboutUs() :
MessageDialog(MainWindow::instance(), STR_ABOUT_US, "")
{
content->setRect({(LCD_W - ABOUT_WIDTH) / 2, 20, ABOUT_WIDTH, LCD_H - 40});
content->setInnerWidth(ABOUT_WIDTH);
messageWidget->setTextFlags(CENTERED | FONT(BOLD) | COLOR_THEME_SECONDARY1);
messageWidget->setTop(content->top() + 40);
+21 -9
View File
@@ -40,12 +40,17 @@ static void tile_view_deleted_cb(lv_event_t* e)
if (obj == target) { lv_obj_del(obj); }
}
static void tile_view_scroll(lv_event_t* e)
{
(void)e;
if (ViewMain::instance()) ViewMain::instance()->updateTopbarVisibility();
}
ViewMain * ViewMain::_instance = nullptr;
ViewMain::ViewMain():
Window(MainWindow::instance(), MainWindow::instance()->getRect(), NO_SCROLLBAR)
{
//setPageWidth(getParent()->width());
focusWindow = this;
setFocusHandler([&](bool focus) {
@@ -62,6 +67,7 @@ ViewMain::ViewMain():
lv_obj_add_flag(tile_view, LV_OBJ_FLAG_EVENT_BUBBLE);
lv_obj_set_user_data(tile_view, this);
lv_obj_add_event_cb(tile_view, tile_view_scroll, LV_EVENT_SCROLL, nullptr);
// create last to be on top
topbar = dynamic_cast<TopbarImpl*>(TopbarFactory::create(this));
@@ -105,7 +111,7 @@ rect_t ViewMain::getMainZone(rect_t zone, bool hasTopbar) const
unsigned ViewMain::getCurrentMainView() const
{
return lv_obj_get_scroll_x(tile_view) / LCD_W;
return lv_obj_get_scroll_x(tile_view) / width();
// return g_model.view;
}
@@ -151,17 +157,23 @@ static bool hasTopbar(unsigned view)
void ViewMain::updateTopbarVisibility()
{
// relative to left visible page
return;
if (!tile_view) return;
coord_t scrollPos = lv_obj_get_scroll_x(tile_view);
coord_t pageWidth = width();
if (!pageWidth) return;
int view = scrollPos / pageWidth;
// TODO: cap view ???
int leftScroll = getScrollPositionX() % pageWidth;
int leftScroll = scrollPos % width();
if (leftScroll == 0) {
setTopbarVisible(hasTopbar(g_model.view));
if (customScreens[g_model.view])
customScreens[g_model.view]->adjustLayout();
setTopbarVisible(hasTopbar(view));
if (customScreens[view])
customScreens[view]->adjustLayout();
}
else {
int leftIdx = getScrollPositionX() / pageWidth;
int leftIdx = scrollPos / pageWidth;
bool leftTopbar = hasTopbar(leftIdx);
bool rightTopbar = hasTopbar(leftIdx+1);
@@ -42,7 +42,6 @@ ViewMainMenu::ViewMainMenu(Window* parent) :
// Take over the screen
setWidth(parent->width());
setHeight(parent->height());
setLeft(parent->getScrollPositionX());
auto carousel = new SelectFabCarousel(this);
carousel->setMaxButtons(4);
@@ -100,7 +99,6 @@ ViewMainMenu::ViewMainMenu(Window* parent) :
resetMenu->addLine(STR_RESET_TIMER2, []() { timerReset(1); });
resetMenu->addLine(STR_RESET_TIMER3, []() { timerReset(2); });
resetMenu->addLine(STR_RESET_TELEMETRY, []() { telemetryReset(); });
resetMenu->setLeft(parent->getScrollPositionX());
return 0;
});
-1
View File
@@ -175,7 +175,6 @@ void Widget::setFullscreen(bool fullscreen)
// Set window opaque (inhibits redraw from windows bellow)
setWindowFlags(getWindowFlags() | OPAQUE);
setRect(parent->getRect());
setLeft(parent->getScrollPositionX());
this->fullscreen = true;
bringToTop();
}
@@ -138,7 +138,6 @@ class WidgetsContainerImpl : public WidgetsContainer
if (widgets[i]) {
auto zone = getZone(i);
widgets[i]->setRect(zone);
widgets[i]->setInnerHeight(zone.h);
}
}
}
+2 -2
View File
@@ -635,8 +635,8 @@ bool LuaWidget::onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t start
if (es) {
ViewMain* vm = ViewMain::instance();
es->event = EVT_TOUCH_SLIDE;
es->touchX = x + vm->getScrollPositionX();
es->touchY = y + vm->getScrollPositionY();
// es->touchX = x + vm->getScrollPositionX();
// es->touchY = y + vm->getScrollPositionY();
es->startX = startX;
es->startY = startY;
es->slideX += slideX;
+1 -1
View File
@@ -1403,7 +1403,7 @@ void opentxClose(uint8_t shutdown)
RTOS_WAIT_MS(100);
#if defined(COLORLCD)
MainWindow::instance()->deleteChildren();
MainWindow::instance()->clear();
// this is necessary as the custom screens are not deleted
// by using deleteCustomScreens(), but here through it's parent window
memset(customScreens, 0, sizeof(customScreens));