libopenui latest updates
This commit is contained in:
@@ -5,7 +5,6 @@ set(LIBOPENUI_SRC
|
||||
window.cpp
|
||||
form.cpp
|
||||
button.cpp
|
||||
fab_icon_button.cpp
|
||||
static.cpp
|
||||
checkbox.cpp
|
||||
slider.cpp
|
||||
@@ -18,10 +17,8 @@ set(LIBOPENUI_SRC
|
||||
textedit.cpp
|
||||
coloredit.cpp
|
||||
progress.cpp
|
||||
page.cpp
|
||||
dialog.cpp
|
||||
message_dialog.cpp
|
||||
tabsgroup.cpp
|
||||
)
|
||||
|
||||
if(HARDWARE_TOUCH)
|
||||
|
||||
+2
-2
@@ -34,8 +34,8 @@ Dialog::Dialog(std::string title, const rect_t rect):
|
||||
void Dialog::paint(BitmapBuffer * dc)
|
||||
{
|
||||
dc->drawRect(0, 0, width() - 1, height() - 1, 1, SOLID, DEFAULT_COLOR);
|
||||
dc->drawSolidFilledRect(1, 1, width() - 3, PAGE_LINE_HEIGHT, TITLE_BGCOLOR);
|
||||
dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, title.c_str(), MENU_TITLE_COLOR);
|
||||
dc->drawSolidFilledRect(1, 1, width() - 3, PAGE_LINE_HEIGHT, FOCUS_BGCOLOR);
|
||||
dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, title.c_str(), FOCUS_COLOR);
|
||||
dc->drawSolidFilledRect(1, PAGE_LINE_HEIGHT + 1, width() - 3, height() - PAGE_LINE_HEIGHT - 3, DEFAULT_BGCOLOR);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Source:
|
||||
* https://github.com/opentx/libopenui
|
||||
*
|
||||
* This file is a part of libopenui library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "libopenui_config.h"
|
||||
#include "fab_icon_button.h"
|
||||
#include "font.h"
|
||||
#include "theme.h"
|
||||
|
||||
const uint8_t __alpha_button_on[] {
|
||||
#include "alpha_button_on.lbm"
|
||||
};
|
||||
Bitmap ALPHA_BUTTON_ON(BMP_ARGB4444, (const uint16_t*)__alpha_button_on);
|
||||
|
||||
const uint8_t __alpha_button_off[] {
|
||||
#include "alpha_button_off.lbm"
|
||||
};
|
||||
Bitmap ALPHA_BUTTON_OFF(BMP_ARGB4444, (const uint16_t*)__alpha_button_off);
|
||||
|
||||
|
||||
FabIconButton::FabIconButton(Window * parent, coord_t x, coord_t y, uint8_t icon, std::function<uint8_t(void)> pressHandler, uint8_t flags):
|
||||
Button(parent, { x - 34, y - 34, 68, 68 }, pressHandler, flags),
|
||||
icon(icon)
|
||||
{
|
||||
}
|
||||
|
||||
void FabIconButton::paint(BitmapBuffer * dc)
|
||||
{
|
||||
dc->drawBitmap(0, 0, checked() ? &ALPHA_BUTTON_ON : &ALPHA_BUTTON_OFF);
|
||||
const BitmapBuffer * mask = theme->getIconMask(icon);
|
||||
if (mask) {
|
||||
dc->drawMask((68 - mask->getWidth()) / 2, (68 - mask->getHeight()) / 2, mask, DEFAULT_BGCOLOR);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Source:
|
||||
* https://github.com/opentx/libopenui
|
||||
*
|
||||
* This file is a part of libopenui library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _FAB_ICON_BUTTON_H_
|
||||
#define _FAB_ICON_BUTTON_H_
|
||||
|
||||
#include "button.h"
|
||||
|
||||
class FabIconButton: public Button {
|
||||
public:
|
||||
FabIconButton(Window * parent, coord_t x, coord_t y, uint8_t icon, std::function<uint8_t(void)> pressHandler, uint8_t flags=0);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() override
|
||||
{
|
||||
return "FabIconButton(" + std::to_string(icon) + ")";
|
||||
}
|
||||
#endif
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
protected:
|
||||
uint8_t icon;
|
||||
};
|
||||
|
||||
#endif
|
||||
+3
-25
@@ -127,32 +127,10 @@ enum FontSizeIndex
|
||||
#define FOCUS_COLOR COLOR(FOCUS_COLOR_INDEX)
|
||||
#define FOCUS_BGCOLOR COLOR(FOCUS_BGCOLOR_INDEX)
|
||||
#define DISABLE_COLOR COLOR(DISABLE_COLOR_INDEX)
|
||||
#define HIGHLIGHT_COLOR COLOR(HIGHLIGHT_COLOR_INDEX)
|
||||
#define CHECKBOX_COLOR COLOR(CHECKBOX_COLOR_INDEX)
|
||||
#define MENU_COLOR COLOR(MENU_COLOR_INDEX)
|
||||
#define MENU_BGCOLOR COLOR(MENU_BGCOLOR_INDEX)
|
||||
#define CUSTOM_COLOR COLOR(CUSTOM_COLOR_INDEX)
|
||||
|
||||
//#define TEXT_STATUSBAR_COLOR COLOR(TEXT_STATUSBAR_COLOR_INDEX)
|
||||
//#define LINE_COLOR COLOR(LINE_COLOR_INDEX)
|
||||
//#define HEADER_SEPARATOR_COLOR COLOR(HEADER_SEPARATOR_COLOR_INDEX)
|
||||
//#define MENU_TITLE_BGCOLOR COLOR(MENU_TITLE_BGCOLOR_INDEX)
|
||||
//#define MENU_TITLE_COLOR COLOR(MENU_TITLE_COLOR_INDEX)
|
||||
//#define MENU_TITLE_DISABLE_COLOR COLOR(MENU_TITLE_DISABLE_COLOR_INDEX)
|
||||
//#define HEADER_COLOR COLOR(HEADER_COLOR_INDEX)
|
||||
//#define ALARM_COLOR COLOR(ALARM_COLOR_INDEX)
|
||||
//#define WARNING_COLOR COLOR(WARNING_COLOR_INDEX)
|
||||
//#define TEXT_DISABLE_COLOR COLOR(TEXT_DISABLE_COLOR_INDEX)
|
||||
//#define CURVE_COLOR COLOR(CURVE_COLOR_INDEX)
|
||||
//#define CURVE_CURSOR_COLOR COLOR(CURVE_CURSOR_COLOR_INDEX)
|
||||
//#define TITLE_BGCOLOR COLOR(TITLE_BGCOLOR_INDEX)
|
||||
//#define TRIM_BGCOLOR COLOR(TRIM_BGCOLOR_INDEX)
|
||||
//#define TRIM_SHADOW_COLOR COLOR(TRIM_SHADOW_COLOR_INDEX)
|
||||
//#define HEADER_BGCOLOR COLOR(HEADER_BGCOLOR_INDEX)
|
||||
//#define HEADER_ICON_BGCOLOR COLOR(HEADER_ICON_BGCOLOR_INDEX)
|
||||
//#define HEADER_CURRENT_BGCOLOR COLOR(HEADER_CURRENT_BGCOLOR_INDEX)
|
||||
//#define MAINVIEW_PANES_COLOR COLOR(MAINVIEW_PANES_COLOR_INDEX)
|
||||
//#define MAINVIEW_GRAPHICS_COLOR COLOR(MAINVIEW_GRAPHICS_COLOR_INDEX)
|
||||
//#define OVERLAY_COLOR COLOR(OVERLAY_COLOR_INDEX)
|
||||
//#define BARGRAPH1_COLOR COLOR(BARGRAPH1_COLOR_INDEX)
|
||||
//#define BARGRAPH2_COLOR COLOR(BARGRAPH2_COLOR_INDEX)
|
||||
//#define BARGRAPH_BGCOLOR COLOR(BARGRAPH_BGCOLOR_INDEX)
|
||||
|
||||
#endif
|
||||
|
||||
+2
-2
@@ -72,10 +72,10 @@ bool MenuWindow::onTouchEnd(coord_t x, coord_t y)
|
||||
void MenuWindow::paint(BitmapBuffer * dc)
|
||||
{
|
||||
int width = (innerHeight > height() ? 195 : 200);
|
||||
dc->clear(HEADER_BGCOLOR);
|
||||
dc->clear(MENU_BGCOLOR);
|
||||
for (unsigned i = 0; i < lines.size(); i++) {
|
||||
auto & line = lines[i];
|
||||
LcdFlags flags = (selectedIndex == (int) i ? WARNING_COLOR : MENU_TITLE_COLOR);
|
||||
LcdFlags flags = (selectedIndex == (int) i ? HIGHLIGHT_COLOR : MENU_COLOR);
|
||||
if (line.drawLine) {
|
||||
line.drawLine(dc, 0, i * lineHeight /*+ (lineHeight - 20) / 2*/, flags);
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,8 +23,8 @@
|
||||
void MenuToolbarButton::paint(BitmapBuffer * dc)
|
||||
{
|
||||
if (checked()) {
|
||||
dc->drawSolidFilledRect(MENUS_TOOLBAR_BUTTON_PADDING, MENUS_TOOLBAR_BUTTON_PADDING, MENUS_TOOLBAR_BUTTON_WIDTH - 2 * MENUS_TOOLBAR_BUTTON_PADDING, MENUS_TOOLBAR_BUTTON_WIDTH - 2 * MENUS_TOOLBAR_BUTTON_PADDING, HEADER_BGCOLOR);
|
||||
dc->drawSizedText(rect.w / 2, (rect.h - getFontHeight(flags)) / 2 + 1, &picto, 1, CENTERED | MENU_TITLE_COLOR);
|
||||
dc->drawSolidFilledRect(MENUS_TOOLBAR_BUTTON_PADDING, MENUS_TOOLBAR_BUTTON_PADDING, MENUS_TOOLBAR_BUTTON_WIDTH - 2 * MENUS_TOOLBAR_BUTTON_PADDING, MENUS_TOOLBAR_BUTTON_WIDTH - 2 * MENUS_TOOLBAR_BUTTON_PADDING, FOCUS_BGCOLOR);
|
||||
dc->drawSizedText(rect.w / 2, (rect.h - getFontHeight(flags)) / 2 + 1, &picto, 1, CENTERED | FOCUS_COLOR);
|
||||
}
|
||||
else {
|
||||
dc->drawSizedText(rect.w / 2, (rect.h - getFontHeight(flags)) / 2 + 1, &picto, 1, CENTERED | DEFAULT_COLOR);
|
||||
|
||||
-95
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Source:
|
||||
* https://github.com/opentx/libopenui
|
||||
*
|
||||
* This file is a part of libopenui library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "page.h"
|
||||
#include "mainwindow.h"
|
||||
#include "keyboard_base.h"
|
||||
#include "theme.h"
|
||||
#include "opentx.h"
|
||||
|
||||
PageHeader::PageHeader(Page * parent, uint8_t icon):
|
||||
Window(parent, { 0, 0, LCD_W, MENU_HEADER_HEIGHT }, OPAQUE),
|
||||
icon(icon)
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
, back(this, { 0, 0, MENU_HEADER_BUTTON_WIDTH, MENU_HEADER_BUTTON_WIDTH }, ICON_BACK,
|
||||
[=]() -> uint8_t {
|
||||
parent->deleteLater();
|
||||
return 0;
|
||||
}, BUTTON_NOFOCUS)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
void PageHeader::paint(BitmapBuffer * dc)
|
||||
{
|
||||
theme->drawPageHeader(dc, this);
|
||||
}
|
||||
|
||||
Page::Page(unsigned icon):
|
||||
Window(&mainWindow, {0, 0, LCD_W, LCD_H}, OPAQUE),
|
||||
header(this, icon),
|
||||
body(this, { 0, MENU_HEADER_HEIGHT, LCD_W, LCD_H - MENU_HEADER_HEIGHT }),
|
||||
previousFocus(focusWindow)
|
||||
{
|
||||
setFocus();
|
||||
}
|
||||
|
||||
Page::~Page()
|
||||
{
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
Keyboard::hide();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Page::deleteLater()
|
||||
{
|
||||
if (previousFocus) {
|
||||
previousFocus->setFocus();
|
||||
}
|
||||
|
||||
Window::deleteLater();
|
||||
}
|
||||
|
||||
void Page::paint(BitmapBuffer * dc)
|
||||
{
|
||||
dc->clear(DEFAULT_BGCOLOR);
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void Page::onEvent(event_t event)
|
||||
{
|
||||
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
|
||||
|
||||
if (event == EVT_KEY_LONG(KEY_EXIT) || event == EVT_KEY_BREAK(KEY_EXIT)) {
|
||||
killEvents(event);
|
||||
deleteLater();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
bool Page::onTouchEnd(coord_t x, coord_t y)
|
||||
{
|
||||
if (Window::onTouchEnd(x, y))
|
||||
return true;
|
||||
|
||||
Keyboard::hide();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
-89
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Source:
|
||||
* https://github.com/opentx/libopenui
|
||||
*
|
||||
* This file is a part of libopenui library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _PAGE_H_
|
||||
#define _PAGE_H_
|
||||
|
||||
#include "window.h"
|
||||
#include "button.h"
|
||||
|
||||
class Page;
|
||||
|
||||
class PageHeader: public Window {
|
||||
public:
|
||||
PageHeader(Page * parent, uint8_t icon);
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
uint8_t getIcon() const
|
||||
{
|
||||
return icon;
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t icon;
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
IconButton back;
|
||||
#endif
|
||||
};
|
||||
|
||||
class Page: public Window {
|
||||
public:
|
||||
explicit Page(unsigned icon);
|
||||
|
||||
~Page() override;
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() override
|
||||
{
|
||||
return "Page";
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void onEvent(event_t event) override;
|
||||
#endif
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
bool onTouchStart(coord_t x, coord_t y) override
|
||||
{
|
||||
Window::onTouchStart(x, y);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool onTouchEnd(coord_t x, coord_t y) override;
|
||||
|
||||
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
|
||||
|
||||
void deleteLater();
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
protected:
|
||||
PageHeader header;
|
||||
FormWindow body;
|
||||
Window * previousFocus;
|
||||
};
|
||||
|
||||
#endif // _PAGE_H_
|
||||
-186
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Source:
|
||||
* https://github.com/opentx/libopenui
|
||||
*
|
||||
* This file is a part of libopenui library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "tabsgroup.h"
|
||||
#include "mainwindow.h"
|
||||
#include "view_main.h"
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
#include "keyboard_base.h"
|
||||
#endif
|
||||
|
||||
#include "opentx.h" // TODO for constants...
|
||||
|
||||
TabsGroupHeader::TabsGroupHeader(TabsGroup * parent, uint8_t icon):
|
||||
Window(parent, { 0, 0, LCD_W, MENU_BODY_TOP }, OPAQUE),
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
back(this, { 0, 0, MENU_HEADER_BUTTON_WIDTH, MENU_HEADER_BUTTON_WIDTH }, ICON_BACK,
|
||||
[=]() -> uint8_t {
|
||||
parent->deleteLater();
|
||||
return 1;
|
||||
}, BUTTON_NOFOCUS),
|
||||
#endif
|
||||
icon(icon),
|
||||
carousel(this, parent)
|
||||
{
|
||||
}
|
||||
|
||||
void TabsGroupHeader::paint(BitmapBuffer * dc)
|
||||
{
|
||||
static_cast<ThemeBase *>(theme)->drawMenuBackground(dc, icon, title);
|
||||
}
|
||||
|
||||
TabsCarousel::TabsCarousel(Window * parent, TabsGroup * menu):
|
||||
Window(parent, { MENU_HEADER_BUTTONS_LEFT, 0, LCD_W - MENU_HEADER_BUTTONS_LEFT, MENU_HEADER_HEIGHT + 10 }, TRANSPARENT),
|
||||
menu(menu)
|
||||
{
|
||||
}
|
||||
|
||||
void TabsCarousel::updateInnerWidth()
|
||||
{
|
||||
setInnerWidth(padding_left + MENU_HEADER_BUTTON_WIDTH * menu->tabs.size());
|
||||
}
|
||||
|
||||
void TabsCarousel::paint(BitmapBuffer * dc)
|
||||
{
|
||||
static_cast<ThemeBase *>(theme)->drawMenuHeader(dc, menu->tabs, currentIndex);
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
bool TabsCarousel::onTouchEnd(coord_t x, coord_t y)
|
||||
{
|
||||
unsigned index = (x - padding_left) / MENU_HEADER_BUTTON_WIDTH;
|
||||
menu->setCurrentTab(index);
|
||||
setCurrentIndex(index);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
TabsGroup::TabsGroup(uint8_t icon):
|
||||
Window(&mainWindow, { 0, 0, LCD_W, LCD_H }, OPAQUE),
|
||||
header(this, icon),
|
||||
body(this, { 0, MENU_BODY_TOP, LCD_W, MENU_BODY_HEIGHT })
|
||||
{
|
||||
}
|
||||
|
||||
TabsGroup::~TabsGroup()
|
||||
{
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
Keyboard::hide();
|
||||
#endif
|
||||
|
||||
for (auto tab: tabs) {
|
||||
delete tab;
|
||||
}
|
||||
|
||||
body.deleteChildren();
|
||||
}
|
||||
|
||||
void TabsGroup::addTab(PageTab * page)
|
||||
{
|
||||
tabs.push_back(page);
|
||||
if (!currentTab) {
|
||||
setCurrentTab(0);
|
||||
}
|
||||
header.carousel.updateInnerWidth();
|
||||
}
|
||||
|
||||
void TabsGroup::removeTab(unsigned index)
|
||||
{
|
||||
if (currentTab == tabs[index]) {
|
||||
setCurrentTab(max<unsigned>(0, index - 1));
|
||||
}
|
||||
tabs.erase(tabs.begin() + index);
|
||||
header.carousel.updateInnerWidth();
|
||||
}
|
||||
|
||||
void TabsGroup::removeAllTabs()
|
||||
{
|
||||
for (auto * tab: tabs) {
|
||||
delete tab;
|
||||
}
|
||||
tabs.clear();
|
||||
currentTab = nullptr;
|
||||
header.carousel.updateInnerWidth();
|
||||
}
|
||||
|
||||
void TabsGroup::setVisibleTab(PageTab * tab)
|
||||
{
|
||||
if (tab != currentTab) {
|
||||
setFocus();
|
||||
FormField::clearCurrentField();
|
||||
body.clear();
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
Keyboard::hide();
|
||||
#endif
|
||||
currentTab = tab;
|
||||
tab->build(&body);
|
||||
header.setTitle(tab->title.c_str());
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void TabsGroup::checkEvents()
|
||||
{
|
||||
Window::checkEvents();
|
||||
if (currentTab) {
|
||||
currentTab->checkEvents();
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void TabsGroup::onEvent(event_t event)
|
||||
{
|
||||
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
|
||||
|
||||
if (event == EVT_KEY_BREAK(KEY_PGDN)) {
|
||||
uint8_t current = header.carousel.getCurrentIndex() + 1;
|
||||
setCurrentTab(current >= tabs.size() ? 0 : current);
|
||||
}
|
||||
else if (event == EVT_KEY_LONG(KEY_PGDN)) {
|
||||
killEvents(event);
|
||||
uint8_t current = header.carousel.getCurrentIndex();
|
||||
setCurrentTab(current == 0 ? tabs.size() - 1 : current - 1);
|
||||
}
|
||||
else if (event == EVT_KEY_LONG(KEY_EXIT) || event == EVT_KEY_BREAK(KEY_EXIT)) {
|
||||
killEvents(event);
|
||||
ViewMain::instance->setFocus();
|
||||
deleteLater();
|
||||
}
|
||||
else if (parent) {
|
||||
parent->onEvent(event);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void TabsGroup::paint(BitmapBuffer * dc)
|
||||
{
|
||||
dc->clear(DEFAULT_BGCOLOR);
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
bool TabsGroup::onTouchEnd(coord_t x, coord_t y)
|
||||
{
|
||||
if (Window::onTouchEnd(x, y))
|
||||
return true;
|
||||
|
||||
Keyboard::hide();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
-191
@@ -1,191 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Source:
|
||||
* https://github.com/opentx/libopenui
|
||||
*
|
||||
* This file is a part of libopenui library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _TABSGROUP_H_
|
||||
#define _TABSGROUP_H_
|
||||
|
||||
#include <vector>
|
||||
#include "button.h"
|
||||
#include "form.h"
|
||||
|
||||
class TabsGroup;
|
||||
|
||||
class PageTab {
|
||||
friend class TabsCarousel;
|
||||
friend class TabsGroup;
|
||||
|
||||
public:
|
||||
PageTab(std::string title, unsigned icon):
|
||||
title(std::move(title)),
|
||||
icon(icon)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~PageTab() = default;
|
||||
|
||||
virtual void build(FormWindow * window) = 0;
|
||||
|
||||
virtual void checkEvents()
|
||||
{
|
||||
}
|
||||
|
||||
void destroy()
|
||||
{
|
||||
if (onPageDestroyed) {
|
||||
onPageDestroyed();
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
void setOnPageDestroyedHandler(std::function<void()> handler)
|
||||
{
|
||||
onPageDestroyed = std::move(handler);
|
||||
}
|
||||
|
||||
void setTitle(std::string value)
|
||||
{
|
||||
title = std::move(value);
|
||||
}
|
||||
|
||||
unsigned getIcon() const
|
||||
{
|
||||
return icon;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string title;
|
||||
unsigned icon;
|
||||
std::function<void()> onPageDestroyed;
|
||||
};
|
||||
|
||||
class TabsCarousel: public Window {
|
||||
public:
|
||||
TabsCarousel(Window * parent, TabsGroup * menu);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() override
|
||||
{
|
||||
return "TabsCarousel";
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void setCurrentIndex(uint8_t index)
|
||||
{
|
||||
currentIndex = index;
|
||||
}
|
||||
|
||||
inline uint8_t getCurrentIndex()
|
||||
{
|
||||
return currentIndex;
|
||||
}
|
||||
|
||||
void updateInnerWidth();
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
bool onTouchEnd(coord_t x, coord_t y) override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
constexpr static uint8_t padding_left = 3;
|
||||
TabsGroup * menu;
|
||||
uint8_t currentIndex = 0;
|
||||
};
|
||||
|
||||
class TabsGroupHeader: public Window {
|
||||
friend class TabsGroup;
|
||||
|
||||
public:
|
||||
TabsGroupHeader(TabsGroup * menu, uint8_t icon);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() override
|
||||
{
|
||||
return "TabsGroupHeader";
|
||||
}
|
||||
#endif
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
void setTitle(const char * value)
|
||||
{
|
||||
title = value;
|
||||
}
|
||||
|
||||
protected:
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
IconButton back;
|
||||
#endif
|
||||
uint8_t icon;
|
||||
TabsCarousel carousel;
|
||||
const char * title = nullptr;
|
||||
};
|
||||
|
||||
class TabsGroup: public Window {
|
||||
friend class TabsCarousel;
|
||||
|
||||
public:
|
||||
explicit TabsGroup(uint8_t icon);
|
||||
|
||||
~TabsGroup() override;
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() override
|
||||
{
|
||||
return "TabsGroup";
|
||||
}
|
||||
#endif
|
||||
|
||||
void addTab(PageTab * page);
|
||||
|
||||
void removeTab(unsigned index);
|
||||
|
||||
void removeAllTabs();
|
||||
|
||||
void setCurrentTab(unsigned index)
|
||||
{
|
||||
if (index < tabs.size()) {
|
||||
header.carousel.setCurrentIndex(index);
|
||||
setVisibleTab(tabs[index]);
|
||||
}
|
||||
}
|
||||
|
||||
void checkEvents() override;
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void onEvent(event_t event) override;
|
||||
#endif
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
bool onTouchEnd(coord_t x, coord_t y) override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
TabsGroupHeader header;
|
||||
FormWindow body;
|
||||
std::vector<PageTab *> tabs;
|
||||
PageTab * currentTab = nullptr;
|
||||
|
||||
void setVisibleTab(PageTab * tab);
|
||||
};
|
||||
|
||||
#endif
|
||||
-1
@@ -42,7 +42,6 @@ class Theme {
|
||||
virtual void drawCheckBox(BitmapBuffer * dc, bool checked, coord_t x, coord_t y, bool focus = false) const = 0;
|
||||
virtual void drawChoice(BitmapBuffer * dc, ChoiceBase * choice, const char * str) const = 0;
|
||||
virtual void drawSlider(BitmapBuffer * dc, int vmin, int vmax, int value, const rect_t & rect, bool edit, bool focus) const = 0;
|
||||
virtual void drawPageHeader(BitmapBuffer * dc, const PageHeader * page) const = 0;
|
||||
virtual const BitmapBuffer * getIcon(uint8_t index, IconState state) const = 0;
|
||||
virtual const BitmapBuffer * getIconMask(uint8_t index) const = 0;
|
||||
};
|
||||
|
||||
+1
-1
@@ -262,7 +262,7 @@ void Window::checkEvents()
|
||||
}
|
||||
|
||||
if (this == focusWindow) {
|
||||
event_t event = getEvent(false);
|
||||
event_t event = getWindowEvent();
|
||||
if (event) {
|
||||
TRACE_WINDOWS("Event 0x%x received ...", event);
|
||||
this->onEvent(event);
|
||||
|
||||
Reference in New Issue
Block a user