Added SelectFabCarousel to implement a button carousel.

This commit is contained in:
Raphael Coeffic
2021-05-06 12:55:59 +02:00
committed by Raphael Coeffic
parent 8ff852a560
commit de86bdcc97
6 changed files with 154 additions and 54 deletions
+1
View File
@@ -22,6 +22,7 @@ set(GUI_SRC
page.cpp
fab_button.cpp
select_fab_button.cpp
select_fab_carousel.cpp
topbar.cpp
layout.cpp
widget.cpp
+2 -2
View File
@@ -30,10 +30,10 @@ SelectFabButton::SelectFabButton(FormGroup* parent, coord_t x, coord_t y,
title(title)
{
// Add some space on either side on the button
setWidth(width() + SELECT_BUTTON_BORDER);
setWidth(FAB_BUTTON_SIZE + SELECT_BUTTON_BORDER);
// 2 Lines extra for the text + half border
setHeight(height() + 2 * PAGE_LINE_HEIGHT + SELECT_BUTTON_BORDER / 2);
setHeight(FAB_BUTTON_SIZE + 2 * PAGE_LINE_HEIGHT + SELECT_BUTTON_BORDER / 2);
// if (height() < (width() / 2) * 3) {
// setHeight((width() / 2) * 3);
@@ -0,0 +1,49 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "select_fab_carousel.h"
SelectFabCarousel::SelectFabCarousel(Window* parent):
FormGroup(parent, {}, OPAQUE | 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);
}
void SelectFabCarousel::addButton(uint8_t icon, const char* title,
std::function<uint8_t(void)> pressHandler)
{
coord_t y_pos = 0;//SELECT_BUTTON_BORDER;
coord_t x_pos = pageWidth * buttons;// + SELECT_BUTTON_BORDER / 2;
buttons++;
auto button = new SelectFabButton(this, x_pos, y_pos, icon, title, pressHandler);
setInnerWidth(pageWidth * buttons);
// y_pos += button->width() + SELECT_BUTTON_BORDER;
// setHeight(y_pos);
// setInnerHeight(y_pos);
}
@@ -0,0 +1,40 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "select_fab_button.h"
class SelectFabCarousel : public FormGroup
{
public:
explicit SelectFabCarousel(Window* parent);
// Maximum visible buttons (-> width of the carousel)
void setMaxButtons(uint8_t max);
// Add a new button to the carousel
void addButton(uint8_t icon, const char* title,
std::function<uint8_t(void)> pressHandler);
protected:
uint8_t maxButtons = 0;
uint8_t buttons = 0;
};
+28 -51
View File
@@ -28,17 +28,23 @@
#include "menu_screen.h"
#include "view_channels.h"
#include "view_statistics.h"
#include "select_fab_button.h"
#include "select_fab_carousel.h"
// TODO:
// -> make SelectFabCarousel()
// -> contains only the scrolling area
// -> ViewMainMenu takes fullscreen
// -> SelectFabCarousel() has ViewMainMenu() as parent
ViewMainMenu::ViewMainMenu(Window* parent) :
FormGroup(parent->getFullScreenWindow(),
{},
OPAQUE | FORM_FORWARD_FOCUS | NO_SCROLLBAR)
Window(parent->getFullScreenWindow(), {})
{
Layer::push(this);
setWidth(parent->width());
setHeight(parent->height());
coord_t y_pos = SELECT_BUTTON_BORDER;
coord_t x_pos = SELECT_BUTTON_BORDER / 2;
auto carousel = new SelectFabCarousel(this);
carousel->setMaxButtons(4);
// Disabled Title
//
@@ -47,57 +53,37 @@ ViewMainMenu::ViewMainMenu(Window* parent) :
// "Tasks", 0, FOCUS_COLOR | FONT(XL) | CENTERED);
// pos += title->height() + PAGE_LINE_SPACING;
auto button = new SelectFabButton(this, x_pos, y_pos, ICON_RADIO_TOOLS, "Model\nSettings",
[=]() -> uint8_t {
carousel->addButton(ICON_RADIO_TOOLS, "Model\nSettings", [=]() -> uint8_t {
deleteLater();
new ModelMenu();
return 0;
});
x_pos += button->width() + SELECT_BUTTON_BORDER / 2;
setPageWidth(x_pos);
setWidth(pageWidth * 4);
x_pos += SELECT_BUTTON_BORDER / 2;
button = new SelectFabButton(this, x_pos, y_pos, ICON_MODEL, "Select\nModel",
[=]() -> uint8_t {
carousel->addButton(ICON_MODEL, "Select\nModel", [=]() -> uint8_t {
deleteLater();
new ModelSelectMenu();
return 0;
});
x_pos += pageWidth;
button = new SelectFabButton(this, x_pos, y_pos, ICON_RADIO, "Radio\nSettings",
[=]() -> uint8_t {
carousel->addButton(ICON_RADIO, "Radio\nSettings", [=]() -> uint8_t {
deleteLater();
new RadioMenu();
return 0;
});
x_pos += pageWidth;
button = new SelectFabButton(this, x_pos, y_pos, ICON_THEME, "Screens\nSetup",
[=]() -> uint8_t {
carousel->addButton(ICON_THEME, "Screens\nSetup", [=]() -> uint8_t {
deleteLater();
new ScreenMenu();
return 0;
});
x_pos += pageWidth;
button = new SelectFabButton(this, x_pos, y_pos, ICON_MONITOR, "Channel\nMonitor",
[=]() -> uint8_t {
carousel->addButton(ICON_MONITOR, "Channel\nMonitor", [=]() -> uint8_t {
deleteLater();
new ChannelsViewMenu();
return 0;
});
x_pos += pageWidth;
button = new SelectFabButton(this, x_pos, y_pos, ICON_MODEL_TELEMETRY, "Reset\nTelemetry",
[=]() -> uint8_t {
carousel->addButton(ICON_MODEL_TELEMETRY, "Reset\nTelemetry", [=]() -> uint8_t {
deleteLater();
Menu* resetMenu = new Menu(parent);
resetMenu->addLine(STR_RESET_FLIGHT, []() { flightReset(); });
@@ -108,42 +94,33 @@ ViewMainMenu::ViewMainMenu(Window* parent) :
return 0;
});
x_pos += pageWidth;
button = new SelectFabButton(this, x_pos, y_pos, ICON_STATS, "Statistics",
[=]() -> uint8_t {
carousel->addButton(ICON_STATS, "Statistics", [=]() -> uint8_t {
deleteLater();
new StatisticsViewPageGroup();
return 0;
});
x_pos += pageWidth;
button = new SelectFabButton(this, x_pos, y_pos, ICON_OPENTX, "About\nOpenTx",
[=]() -> uint8_t {
carousel->addButton(ICON_OPENTX, "About\nOpenTx", [=]() -> uint8_t {
deleteLater();
//TODO: new AboutUs();
return 0;
});
x_pos += pageWidth;
setInnerWidth(x_pos + SELECT_BUTTON_BORDER / 2);
carousel->setWindowCentered();
carouselRect = carousel->getRect();
y_pos += button->height() + SELECT_BUTTON_BORDER;
setHeight(y_pos);
setInnerHeight(y_pos);
setWindowCentered();
setFocus();
carousel->setCloseHandler([=]() { deleteLater(); });
carousel->setFocus();
}
void ViewMainMenu::paint(BitmapBuffer* dc)
{
dc->drawFilledRect(0, 0, getInnerWidth(), height(), SOLID, OVERLAY_COLOR, OPACITY(5));
dc->drawFilledRect(carouselRect.x, carouselRect.y, carouselRect.w,
carouselRect.h, SOLID, OVERLAY_COLOR, OPACITY(5));
}
void ViewMainMenu::deleteLater(bool detach, bool trash)
{
Layer::pop(this);
FormGroup::deleteLater(detach, trash);
Window::deleteLater(detach, trash);
}
+34 -1
View File
@@ -22,10 +22,43 @@
#include "form.h"
class ViewMainMenu: FormGroup
class ViewMainMenu: public Window
{
public:
ViewMainMenu(Window * parent);
void paint(BitmapBuffer * dc) override;
void deleteLater(bool detach=true, bool trash=true) override;
#if defined(HARDWARE_TOUCH)
bool onTouchStart(coord_t /*x*/, coord_t /*y*/) override { return true; }
bool onTouchEnd(coord_t x, coord_t y) override
{
if (!Window::onTouchEnd(x, y)) {
onKeyPress();
deleteLater();
}
return true;
}
bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY,
coord_t slideX, coord_t slideY) override
{
Window::onTouchSlide(x, y, startX, startY, slideX, slideY);
return true;
}
#endif
#if defined(HARDWARE_KEYS)
void onEvent(event_t event) override
{
switch (event) {
case EVT_KEY_BREAK(KEY_EXIT):
killEvents(event);
parent->deleteLater();
return;
}
Window::onEvent(event);
}
#endif
protected:
rect_t carouselRect;
};