Skip to content

Commit

Permalink
Rework handling of 'full screen' widget mode selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Mitchell committed Feb 23, 2024
1 parent d78dca1 commit 9e913f1
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 26 deletions.
2 changes: 2 additions & 0 deletions radio/src/gui/colorlcd/layouts/layout_factory_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class Layout: public LayoutBase

bool isLayout() override { return true; }

bool isAppMode() { return decorationSettings == DECORATION_NONE && zoneCount == 1; }

protected:
const LayoutFactory * factory = nullptr;
std::unique_ptr<ViewMainDecoration> decoration;
Expand Down
27 changes: 26 additions & 1 deletion radio/src/gui/colorlcd/layouts/topbar_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,30 @@
#include "topbar_impl.h"
#include "opentx.h"
#include "theme.h"
#include "view_main.h"

constexpr uint32_t TOPBAR_REFRESH = 1000 / 10; // 10 Hz

class TopBarEdgeTx : public HeaderIcon
{
public:
TopBarEdgeTx(Window* parent) : HeaderIcon(parent, ICON_EDGETX)
{
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_CLICKABLE);
}

void onClicked() override
{
ViewMain::instance()->openMenu();
}
};

TopBar::TopBar(Window * parent) :
TopBarBase(parent, {0, 0, LCD_W, MENU_HEADER_HEIGHT}, &g_model.topbarData)
{
etx_solid_bg(lvobj, COLOR_THEME_SECONDARY1_INDEX);

headerIcon = new HeaderIcon(this, ICON_EDGETX);
headerIcon = new TopBarEdgeTx(parent);
}

unsigned int TopBar::getZonesCount() const
Expand Down Expand Up @@ -80,6 +95,16 @@ coord_t TopBar::getVisibleHeight(float visible) const // 0.0 -> 1.0
return (coord_t)h;
}

void TopBar::showEdgeTxButton()
{
headerIcon->show();
}

void TopBar::hideEdgeTxButton()
{
headerIcon->hide();
}

void TopBar::checkEvents()
{
uint32_t now = RTOS_GET_MS();
Expand Down
2 changes: 2 additions & 0 deletions radio/src/gui/colorlcd/layouts/topbar_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class TopBar: public TopBarBase

void setVisible(float visible);
coord_t getVisibleHeight(float visible) const; // 0.0 -> 1.0
void showEdgeTxButton();
void hideEdgeTxButton();

void checkEvents() override;

Expand Down
6 changes: 3 additions & 3 deletions radio/src/gui/colorlcd/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ void HeaderDateTime::setColor(uint32_t color)
lv_obj_set_style_text_color(time, makeLvColor(color), LV_PART_MAIN);
}

HeaderIcon::HeaderIcon(Window* parent, EdgeTxIcon icon)
HeaderIcon::HeaderIcon(Window* parent, EdgeTxIcon icon) :
StaticIcon(parent, 0, 0, ICON_TOPLEFT_BG, COLOR_THEME_FOCUS)
{
auto bg = new StaticIcon(parent, 0, 0, ICON_TOPLEFT_BG, COLOR_THEME_FOCUS);
(new StaticIcon(parent, 0, 0, icon, COLOR_THEME_PRIMARY2))->center(bg->width(), bg->height());
(new StaticIcon(this, 0, 0, icon, COLOR_THEME_PRIMARY2))->center(width(), height());
}

UsbSDConnected::UsbSDConnected() :
Expand Down
3 changes: 2 additions & 1 deletion radio/src/gui/colorlcd/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "opentx.h"
#include "bitmaps.h"
#include "static.h"

class BitmapBuffer;

Expand Down Expand Up @@ -59,7 +60,7 @@ class HeaderDateTime
int8_t lastMinute = -1;
};

class HeaderIcon
class HeaderIcon : public StaticIcon
{
public:
HeaderIcon(Window *parent, EdgeTxIcon icon);
Expand Down
60 changes: 46 additions & 14 deletions radio/src/gui/colorlcd/view_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ void ViewMain::updateTopbarVisibility()
int leftScroll = scrollPos % width();
if (leftScroll == 0) {
int view = scrollPos / pageWidth;
setTopbarVisible(hasTopbar(view));
setTopbarVisible(::hasTopbar(view));
if (customScreens[view]) customScreens[view]->adjustLayout();
} else {
int leftIdx = scrollPos / pageWidth;
bool leftTopbar = hasTopbar(leftIdx);
bool rightTopbar = hasTopbar(leftIdx + 1);
bool leftTopbar = ::hasTopbar(leftIdx);
bool rightTopbar = ::hasTopbar(leftIdx + 1);

if (leftTopbar != rightTopbar) {
float ratio = (float)leftScroll / (float)pageWidth;
Expand Down Expand Up @@ -351,28 +351,60 @@ void ViewMain::ws_timer(lv_timer_t* t)
view->enableWidgetSelect(false);
}

void ViewMain::longPress()
{
if (isAppMode()) {
int view = getCurrentMainView();
customScreens[view]->getWidget(0)->setFullscreen(true);
} else {
enableWidgetSelect(true);
}
}

void ViewMain::long_pressed(lv_event_t* e)
{
auto obj = lv_event_get_target(e);
auto view = (ViewMain*)lv_obj_get_user_data(obj);
if (!view) return;
// kill subsequent CLICKED event
lv_obj_clear_state(obj, LV_STATE_PRESSED);
lv_indev_wait_release(lv_indev_get_act());

if (view->enableWidgetSelect(true)) {
// kill subsequent CLICKED event
lv_obj_clear_state(obj, LV_STATE_PRESSED);
lv_indev_wait_release(lv_indev_get_act());
}
auto view = (ViewMain*)lv_obj_get_user_data(obj);
if (view) view->longPress();
}

void ViewMain::show(bool visible)
{
isVisible = visible;
coord_t scrollPos = lv_obj_get_scroll_x(tile_view);
coord_t pageWidth = width();
int view = scrollPos / pageWidth;
setTopbarVisible(visible && hasTopbar(view));
int view = getCurrentMainView();
setTopbarVisible(visible && ::hasTopbar(view));
if (visible)
topbar->showEdgeTxButton();
else
topbar->hideEdgeTxButton();
if (customScreens[view]) {
customScreens[view]->show(visible);
customScreens[view]->showWidgets(visible);
}
}

bool ViewMain::isAppMode()
{
int view = getCurrentMainView();
return ((Layout*)customScreens[view])->isAppMode();
}

bool ViewMain::hasTopbar()
{
int view = getCurrentMainView();
return ::hasTopbar(view);
}

void ViewMain::showTopBarEdgeTxButton()
{
topbar->showEdgeTxButton();
}

void ViewMain::hideTopBarEdgeTxButton()
{
topbar->hideEdgeTxButton();
}
8 changes: 7 additions & 1 deletion radio/src/gui/colorlcd/view_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ class ViewMain : public NavWindow

void onClicked() override;
void onCancel() override;
void openMenu();
void longPress();

void show(bool visible = true) override;
void showTopBarEdgeTxButton();
void hideTopBarEdgeTxButton();

bool hasTopbar();
bool isAppMode();

protected:
static ViewMain* _instance;
Expand All @@ -93,7 +100,6 @@ class ViewMain : public NavWindow
// Set topbar visibility [0.0 -> 1.0]
void setTopbarVisible(float visible);

void openMenu();
void refreshWidgetSelectTimer();

static void long_pressed(lv_event_t* e);
Expand Down
8 changes: 6 additions & 2 deletions radio/src/gui/colorlcd/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ Widget::Widget(const WidgetFactory* factory, Window* parent, const rect_t& rect,

void Widget::openMenu()
{
if (fsAllowed && ViewMain::instance()->isAppMode())
{
setFullscreen(true);
return;
}

if (getOptions() || fsAllowed) {
// Widgets are placed on a full screen window which is underneath the main
// view menu bar Find the parent of this so that when the popup loads it
Expand Down Expand Up @@ -141,8 +147,6 @@ void Widget::setFullscreen(bool enable)
update();
}

void Widget::disableFullscreen() { fsAllowed = false; }

void Widget::onLongPress()
{
if (!fullscreen) ButtonBase::onLongPress();
Expand Down
4 changes: 0 additions & 4 deletions radio/src/gui/colorlcd/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ class Widget : public ButtonBase
// Set/unset fullscreen mode
void setFullscreen(bool enable);

// Disable setting fullscreen mode
void disableFullscreen();
bool isFullscreenAllowed() { return fsAllowed; }

// Called when the widget options have changed
virtual void update();

Expand Down
2 changes: 2 additions & 0 deletions radio/src/gui/colorlcd/widgets_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ SetupWidgetsPage::SetupWidgetsPage(uint8_t customScreenIdx) :
auto viewMain = ViewMain::instance();
savedView = viewMain->getCurrentMainView();
viewMain->setCurrentMainView(customScreenIdx);
if (!viewMain->hasTopbar()) viewMain->hideTopBarEdgeTxButton();
}

SetupWidgetsPageSlot* firstSlot = nullptr;
Expand Down Expand Up @@ -146,6 +147,7 @@ void SetupWidgetsPage::deleteLater(bool detach, bool trash)
if (screen) {
auto viewMain = ViewMain::instance();
viewMain->setCurrentMainView(savedView);
viewMain->showTopBarEdgeTxButton();
}
Window::deleteLater(detach, trash);
new ScreenMenu(customScreenIdx + 1);
Expand Down

0 comments on commit 9e913f1

Please sign in to comment.