More code moved to the theme

This commit is contained in:
Bertrand Songis
2019-10-04 11:45:31 +02:00
parent 0199a7d6d5
commit 17cff9546f
11 changed files with 182 additions and 62 deletions
+1
View File
@@ -20,6 +20,7 @@ set(LIBOPENUI_SRC
progress.cpp
page.cpp
dialog.cpp
message_dialog.cpp
tabsgroup.cpp
)
+20 -21
View File
@@ -19,14 +19,11 @@
#include "choice.h"
#include "menu.h"
#include "theme.h"
const uint8_t LBM_DROPDOWN[] = {
#include "mask_dropdown.lbm"
};
Choice::Choice(Window * parent, const rect_t &rect, const char * values, int16_t vmin, int16_t vmax,
Choice::Choice(Window * parent, const rect_t & rect, const char * values, int16_t vmin, int16_t vmax,
std::function<int16_t()> getValue, std::function<void(int16_t)> setValue, LcdFlags flags) :
FormField(parent, rect),
ChoiceBase(parent, rect),
values(values),
vmin(vmin),
vmax(vmax),
@@ -39,21 +36,23 @@ Choice::Choice(Window * parent, const rect_t &rect, const char * values, int16_t
void Choice::paint(BitmapBuffer * dc)
{
FormField::paint(dc);
LcdFlags textColor;
if (editMode)
textColor = TEXT_INVERTED_COLOR;
else if (hasFocus())
textColor = TEXT_INVERTED_BGCOLOR;
else
textColor = 0;
if (textHandler)
dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, textHandler(getValue()).c_str(), textColor);
else
dc->drawTextAtIndex(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, values, getValue() - vmin, flags | textColor);
dc->drawBitmapPattern(rect.w - 14, (rect.h - 5) / 2, LBM_DROPDOWN, textColor);
theme->drawChoice(dc, this, textHandler ? textHandler(getValue()).c_str() : TEXT_AT_INDEX(values, getValue() - vmin).c_str());
//
//
// LcdFlags textColor;
// if (editMode)
// textColor = TEXT_INVERTED_COLOR;
// else if (hasFocus())
// textColor = TEXT_INVERTED_BGCOLOR;
// else
// textColor = 0;
//
// if (textHandler)
// dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, , textColor);
// else
// dc->drawTextAtIndex(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, values, getValue() - vmin, flags | textColor);
//
// dc->drawBitmapPattern(rect.w - 14, (rect.h - 5) / 2, LBM_DROPDOWN, textColor);
}
#if defined(HARDWARE_KEYS)
+27 -5
View File
@@ -22,7 +22,29 @@
#include "form.h"
class Choice : public FormField {
enum ChoiceType {
CHOICE_TYPE_DROPOWN,
CHOICE_TYPE_FOLDER,
};
class ChoiceBase : public FormField {
public:
ChoiceBase(Window * parent, const rect_t & rect, ChoiceType type = CHOICE_TYPE_DROPOWN):
FormField(parent, rect),
type(type)
{
}
inline ChoiceType getType() const
{
return type;
}
protected:
ChoiceType type;
};
class Choice : public ChoiceBase {
public:
Choice(Window * parent, const rect_t & rect, const char * values, int16_t vmin, int16_t vmax, std::function<int16_t()> getValue, std::function<void(int16_t)> setValue = nullptr, LcdFlags flags = 0);
@@ -59,14 +81,14 @@ class Choice : public FormField {
}
protected:
const char * values;
int16_t vmin;
int16_t vmax;
const char * values = nullptr;
int16_t vmin = 0;
int16_t vmax = 0;
std::function<int16_t()> getValue;
std::function<void(int16_t)> setValue;
std::function<bool(int)> isValueAvailable;
std::function<std::string(int32_t)> textHandler;
LcdFlags flags;
LcdFlags flags = 0;
void openMenu();
};
+1 -1
View File
@@ -36,7 +36,7 @@ void Dialog::paint(BitmapBuffer * dc)
dc->drawRect(0, 0, width() - 1, height() - 1, 1, SOLID, TEXT_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, PAGE_LINE_HEIGHT + 1, width() - 3, height() - PAGE_LINE_HEIGHT - 3, TEXT_BGCOLOR_INDEX);
dc->drawSolidFilledRect(1, PAGE_LINE_HEIGHT + 1, width() - 3, height() - PAGE_LINE_HEIGHT - 3, TEXT_BGCOLOR);
}
void Dialog::deleteLater()
+15 -28
View File
@@ -20,10 +20,8 @@
#include "filechoice.h"
#include "libopenui_file.h"
#include "menu.h"
const uint8_t LBM_FOLDER[] = {
#include "mask_folder.lbm"
};
#include "theme.h"
#include "message_dialog.h"
// comparison, not case sensitive.
bool compare_nocase(const std::string &first, const std::string &second)
@@ -32,7 +30,7 @@ bool compare_nocase(const std::string &first, const std::string &second)
}
FileChoice::FileChoice(Window * parent, const rect_t & rect, std::string folder, const char * extension, int maxlen, std::function<std::string()> getValue, std::function<void(std::string)> setValue):
FormField(parent, rect),
ChoiceBase(parent, rect, CHOICE_TYPE_FOLDER),
folder(std::move(folder)),
extension(extension),
maxlen(maxlen),
@@ -44,24 +42,10 @@ FileChoice::FileChoice(Window * parent, const rect_t & rect, std::string folder,
void FileChoice::paint(BitmapBuffer * dc)
{
FormField::paint(dc);
const char * displayedValue = getValue().c_str();
LcdFlags textColor;
if (editMode)
textColor = TEXT_INVERTED_COLOR;
else if (hasFocus())
textColor = TEXT_INVERTED_BGCOLOR;
else if (displayedValue[0] == '\0')
textColor = CURVE_AXIS_COLOR;
else
textColor = TEXT_COLOR;
dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, displayedValue[0] == '\0' ? "---" : displayedValue, textColor);
dc->drawBitmapPattern(rect.w - 20, (rect.h - 11) / 2, LBM_FOLDER, textColor);
theme->drawChoice(dc, this, getValue().c_str());
}
void FileChoice::openMenu()
bool FileChoice::openMenu()
{
FILINFO fno;
DIR dir;
@@ -124,12 +108,14 @@ void FileChoice::openMenu()
editMode = false;
setFocus();
});
}
else {
TRACE("NO FILES !!!!!");
// TODO popup "NO FILES"
return true;
}
}
new MessageDialog("Files", "No files on SD");
return false;
}
#if defined(HARDWARE_KEYS)
@@ -138,9 +124,10 @@ void FileChoice::onKeyEvent(event_t event)
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
if (event == EVT_KEY_BREAK(KEY_ENTER)) {
editMode = true;
invalidate();
openMenu();
if (openMenu()) {
editMode = true;
invalidate();
}
}
else {
FormField::onKeyEvent(event);
+3 -3
View File
@@ -20,10 +20,10 @@
#ifndef _FILECHOICE_H_
#define _FILECHOICE_H_
#include "form.h"
#include "choice.h"
#include <string>
class FileChoice: public FormField {
class FileChoice: public ChoiceBase {
public:
FileChoice(Window * parent, const rect_t & rect, std::string folder, const char * extension, int maxlen, std::function<std::string()> getValue, std::function<void(std::string)> setValue);
@@ -51,7 +51,7 @@ class FileChoice: public FormField {
std::function<std::string()> getValue;
std::function<void(std::string)> setValue;
void openMenu();
bool openMenu();
};
#endif // _FILECHOICE_H_
+9 -4
View File
@@ -46,22 +46,27 @@ class FormField: public Window {
inline static void clearCurrentField()
{
setCurrentField(nullptr);
};
}
inline static FormField * getCurrentField()
{
return current;
};
}
inline FormField * getPreviousField()
{
return previous;
};
}
inline FormField * getNextField()
{
return next;
};
}
inline bool isEditMode() const
{
return editMode;
}
inline static void link(FormField * previous, FormField * next)
{
+32
View File
@@ -122,4 +122,36 @@ enum FontSizeIndex
#define COLOR(index) LcdFlags((index) << 16)
#define COLOR_IDX(att) uint8_t((att) >> 16)
//#define TEXT_COLOR COLOR(TEXT_COLOR_INDEX)
//#define TEXT_BGCOLOR COLOR(TEXT_BGCOLOR_INDEX)
//#define TEXT_INVERTED_COLOR COLOR(TEXT_INVERTED_COLOR_INDEX)
//#define TEXT_INVERTED_BGCOLOR COLOR(TEXT_INVERTED_BGCOLOR_INDEX)
//#define TEXT_STATUSBAR_COLOR COLOR(TEXT_STATUSBAR_COLOR_INDEX)
//#define LINE_COLOR COLOR(LINE_COLOR_INDEX)
#define SCROLLBOX_COLOR COLOR(SCROLLBOX_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_AXIS_COLOR COLOR(CURVE_AXIS_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)
//#define CUSTOM_COLOR COLOR(CUSTOM_COLOR_INDEX)
#endif
+38
View File
@@ -0,0 +1,38 @@
/*
* 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 "message_dialog.h"
#include "static.h"
MessageDialog::MessageDialog(const char * title, const char * message):
Dialog(title, {50, 73, LCD_W - 100, LCD_H - 146})
{
new StaticText(this, {0, coord_t(height() - PAGE_LINE_HEIGHT) / 2, width(), PAGE_LINE_HEIGHT}, message, CENTERED);
}
#if defined(HARDWARE_KEYS)
void MessageDialog::onKeyEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
if (event == EVT_KEY_BREAK(KEY_EXIT) || event == EVT_KEY_BREAK(KEY_ENTER)) {
deleteLater();
}
}
#endif
+34
View File
@@ -0,0 +1,34 @@
/*
* 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 _MESSAGE_DIALOG_H_
#define _MESSAGE_DIALOG_H_
#include "dialog.h"
class MessageDialog: public Dialog {
public:
MessageDialog(const char * title, const char * message);
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override;
#endif
};
#endif // _MESSAGE_DIALOG_H_
+2
View File
@@ -23,6 +23,7 @@
#include "bitmapbuffer.h"
class PageHeader;
class ChoiceBase;
enum IconState {
STATE_DEFAULT,
@@ -34,6 +35,7 @@ class Theme {
virtual void drawMessageBox(const char * title, const char * text, const char * action, LcdFlags flags) const = 0;
virtual void drawProgressBar(BitmapBuffer * dc, coord_t x, coord_t y, coord_t w, coord_t h, int value) const = 0;
virtual void drawCheckBox(BitmapBuffer * dc, bool value, bool focus) 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;