WiP: use tileview in ViewMain
This commit is contained in:
committed by
Raphael Coeffic
parent
b23cb30884
commit
81366e5ae6
@@ -93,9 +93,8 @@ void loadDefaultLayout()
|
||||
// - Timer
|
||||
// - ???
|
||||
//
|
||||
if (screen) {
|
||||
screen->attach(ViewMain::instance());
|
||||
}
|
||||
if (!screen) return;
|
||||
viewMain->addMainView(screen, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,9 +118,10 @@ void loadCustomScreens()
|
||||
}
|
||||
|
||||
// layout is ok, let's add it
|
||||
screen->attach(viewMain);
|
||||
viewMain->setMainViewsCount(i + 1);
|
||||
screen->setLeft(viewMain->getMainViewLeftPos(i));
|
||||
viewMain->addMainView(screen, i);
|
||||
// screen->attach(viewMain);
|
||||
// viewMain->setMainViewsCount(i + 1);
|
||||
// screen->setLeft(viewMain->getMainViewLeftPos(i));
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
@@ -213,8 +213,7 @@ class SetupWidgetsPage: public FormWindow
|
||||
auto screen = customScreens[customScreenIdx];
|
||||
if (screen) {
|
||||
auto viewMain = ViewMain::instance();
|
||||
screen->attach(viewMain);
|
||||
screen->setRect(getRect());
|
||||
viewMain->addMainView(screen, customScreenIdx);
|
||||
viewMain->setCurrentMainView(savedView);
|
||||
}
|
||||
FormWindow::deleteLater(detach, trash);
|
||||
@@ -388,7 +387,7 @@ void ScreenAddPage::build(FormWindow * window)
|
||||
const LayoutFactory * factory = defaultLayout;
|
||||
if (factory) {
|
||||
TRACE("ScreenAddPage: add screen: factory = %p", factory);
|
||||
screen = factory->create(&screenData.layoutData);
|
||||
screen = factory->create(ViewMain::instance(), &screenData.layoutData);
|
||||
|
||||
strncpy(screenData.LayoutId, factory->getId(), sizeof(screenData.LayoutId));
|
||||
TRACE("ScreenAddPage: add screen: LayoutId = %s", screenData.LayoutId);
|
||||
@@ -399,8 +398,8 @@ void ScreenAddPage::build(FormWindow * window)
|
||||
tab->setTitle(title);
|
||||
tab->setIcon(ICON_THEME_VIEW1 + newIdx);
|
||||
|
||||
auto viewMain = ViewMain::instance();
|
||||
viewMain->setMainViewsCount(viewMain->getMainViewsCount() + 1);
|
||||
// auto viewMain = ViewMain::instance();
|
||||
// viewMain->setMainViewsCount(viewMain->getMainViewsCount() + 1);
|
||||
|
||||
// remove current tab first
|
||||
menu->setCurrentTab(0);
|
||||
|
||||
@@ -42,6 +42,16 @@ ViewMain::ViewMain():
|
||||
TRACE("[ViewMain] Focus %s",
|
||||
focus ? "gained" : "lost");
|
||||
});
|
||||
|
||||
tile_view = lv_tileview_create(lvobj);
|
||||
lv_obj_set_pos(tile_view, rect.x, rect.y);
|
||||
lv_obj_set_size(tile_view, rect.w, rect.h);
|
||||
lv_obj_set_scrollbar_mode(tile_view, LV_SCROLLBAR_MODE_OFF);
|
||||
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_SCROLL_ELASTIC);
|
||||
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_EVENT_BUBBLE);
|
||||
lv_obj_set_user_data(tile_view, this);
|
||||
|
||||
lv_obj_move_foreground(topbar->getLvObj());
|
||||
}
|
||||
|
||||
ViewMain::~ViewMain()
|
||||
@@ -49,6 +59,17 @@ ViewMain::~ViewMain()
|
||||
_instance = nullptr;
|
||||
}
|
||||
|
||||
void ViewMain::addMainView(Window* view, uint32_t viewId)
|
||||
{
|
||||
auto tile = lv_tileview_add_tile(tile_view, viewId, 0, LV_DIR_LEFT | LV_DIR_RIGHT);
|
||||
lv_obj_set_user_data(tile, view);
|
||||
|
||||
view->setLeft(lv_obj_get_x(tile));
|
||||
view->setTop(lv_obj_get_y(tile));
|
||||
|
||||
TRACE("addMainView(0x%p, %d)", view, viewId);
|
||||
}
|
||||
|
||||
void ViewMain::setTopbarVisible(float visible)
|
||||
{
|
||||
topbar->setVisible(visible);
|
||||
@@ -56,23 +77,7 @@ void ViewMain::setTopbarVisible(float visible)
|
||||
|
||||
unsigned ViewMain::getMainViewsCount() const
|
||||
{
|
||||
return views;
|
||||
}
|
||||
|
||||
void ViewMain::setMainViewsCount(unsigned views)
|
||||
{
|
||||
if (views > MAX_CUSTOM_SCREENS)
|
||||
views = MAX_CUSTOM_SCREENS;
|
||||
|
||||
// update number of views
|
||||
this->views = views;
|
||||
|
||||
// adjust current screen if needed
|
||||
if (g_model.view >= views) {
|
||||
setCurrentMainView(views - 1);
|
||||
}
|
||||
|
||||
setInnerWidth(getParent()->width() * views);
|
||||
return lv_obj_get_child_cnt(tile_view);
|
||||
}
|
||||
|
||||
coord_t ViewMain::getMainViewLeftPos(unsigned view) const
|
||||
@@ -94,12 +99,9 @@ unsigned ViewMain::getCurrentMainView() const
|
||||
return g_model.view;
|
||||
}
|
||||
|
||||
void ViewMain::setCurrentMainView(unsigned view)
|
||||
void ViewMain::setCurrentMainView(unsigned viewId)
|
||||
{
|
||||
if (view < getMainViewsCount()) {
|
||||
setScrollPositionX(view * pageWidth);
|
||||
TRACE("### switched to view #%u", g_model.view);
|
||||
}
|
||||
lv_obj_set_tile_id(tile_view, viewId, 0, LV_ANIM_OFF);
|
||||
}
|
||||
|
||||
void ViewMain::nextMainView()
|
||||
@@ -173,6 +175,7 @@ void ViewMain::updateTopbarVisibility()
|
||||
|
||||
void ViewMain::setScrollPositionX(coord_t value)
|
||||
{
|
||||
// TODO
|
||||
Window::setScrollPositionX(value);
|
||||
topbar->setLeft(getScrollPositionX());
|
||||
|
||||
@@ -186,6 +189,7 @@ void ViewMain::setScrollPositionX(coord_t value)
|
||||
|
||||
void ViewMain::setScrollPositionY(coord_t value)
|
||||
{
|
||||
// TODO
|
||||
// this one is not used yet, but could
|
||||
// usefull to place the screens upwards
|
||||
Window::setScrollPositionY(value);
|
||||
@@ -196,49 +200,6 @@ void ViewMain::setScrollPositionY(coord_t value)
|
||||
|
||||
//#define DEBUG_SLIDE
|
||||
|
||||
bool ViewMain::onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY)
|
||||
{
|
||||
// prevent screen sliding over the next one (one screen at a time)
|
||||
if (slidingWindow == this) {
|
||||
if (prevSlideState != touchState.event) {
|
||||
if (touchState.event == TE_SLIDE_END) {
|
||||
startSlidePage = getCurrentMainView();
|
||||
#if defined(DEBUG_SLIDE)
|
||||
TRACE("### startSlidePage = %d ###", startSlidePage);
|
||||
#endif
|
||||
}
|
||||
prevSlideState = touchState.event;
|
||||
}
|
||||
else if (prevSlideState == TE_SLIDE_END){
|
||||
|
||||
// let's check what would be the next position
|
||||
auto nextPos = (getScrollPositionX() - slideX);
|
||||
|
||||
// if we would get over more than one page counting from slide-start
|
||||
if (abs(nextPos - getMainViewLeftPos(startSlidePage)) > pageWidth) {
|
||||
|
||||
#if defined(DEBUG_SLIDE)
|
||||
TRACE("### kill the move ###");
|
||||
#endif
|
||||
// kill the movement and let "snap-to-view" finish the job
|
||||
prevSlideState = TE_NONE;
|
||||
touchState.event = TE_NONE;
|
||||
touchState.lastDeltaX = 0;
|
||||
touchState.lastDeltaY = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(DEBUG_SLIDE)
|
||||
TRACE("%sWindow[scrollX=%d, scrollY=%d]->onTouchSlide[x=%d, y=%d, startX=%d, startY=%d, slideX=%d, slideY=%d]",
|
||||
touchState.event == TE_SLIDE_END && slidingWindow ? "###" : "",
|
||||
getScrollPositionX(), getScrollPositionY(),
|
||||
x, y, startX, startY, slideX, slideY);
|
||||
#endif
|
||||
|
||||
return Window::onTouchSlide(x, y, startX, startY, slideX, slideY);
|
||||
}
|
||||
|
||||
bool ViewMain::onTouchEnd(coord_t x, coord_t y)
|
||||
{
|
||||
|
||||
@@ -53,6 +53,8 @@ class ViewMain: public Window
|
||||
}
|
||||
#endif
|
||||
|
||||
void addMainView(Window* view, uint32_t viewId);
|
||||
|
||||
void updateTopbarVisibility();
|
||||
|
||||
// Get the available space in the middle of the screen
|
||||
@@ -60,8 +62,6 @@ class ViewMain: public Window
|
||||
rect_t getMainZone(rect_t zone, bool hasTopbar) const;
|
||||
|
||||
unsigned getMainViewsCount() const;
|
||||
void setMainViewsCount(unsigned views);
|
||||
|
||||
coord_t getMainViewLeftPos(unsigned view) const;
|
||||
|
||||
unsigned getCurrentMainView() const;
|
||||
@@ -80,6 +80,7 @@ class ViewMain: public Window
|
||||
static ViewMain * _instance;
|
||||
|
||||
unsigned views = 0;
|
||||
lv_obj_t* tile_view = nullptr;
|
||||
TopbarImpl* topbar = nullptr;
|
||||
|
||||
// Widget setup requires special permissions ;-)
|
||||
@@ -96,7 +97,6 @@ class ViewMain: public Window
|
||||
unsigned char prevSlideState = 0;
|
||||
unsigned int startSlidePage = 0;
|
||||
|
||||
bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY) override;
|
||||
bool onTouchEnd(coord_t x, coord_t y) override;
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user