Forms refactoring
This commit is contained in:
+4
-4
@@ -444,12 +444,12 @@ coord_t BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char * s, uint8_
|
|||||||
c = uint8_t(*s) + ((c & 0x01) << 8) - 1;
|
c = uint8_t(*s) + ((c & 0x01) << 8) - 1;
|
||||||
if (c >= 0x101)
|
if (c >= 0x101)
|
||||||
c -= 1;
|
c -= 1;
|
||||||
c += 187;
|
c += CJK_FIRST_LETTER_INDEX;
|
||||||
uint8_t width = drawChar(x-1, y, font, fontspecs, c, flags);
|
uint8_t width = drawChar(x, y, font, fontspecs, c, flags);
|
||||||
INCREMENT_POS(width);
|
INCREMENT_POS(width);
|
||||||
}
|
}
|
||||||
else if (c >= 0x20) {
|
else if (c > 0x20) {
|
||||||
uint8_t width = drawChar(x-1, y, font, fontspecs, getMappedChar(c), flags);
|
uint8_t width = drawChar(x, y, font, fontspecs, getMappedChar(c), flags);
|
||||||
INCREMENT_POS(width);
|
INCREMENT_POS(width);
|
||||||
}
|
}
|
||||||
else if (c == '\n') {
|
else if (c == '\n') {
|
||||||
|
|||||||
+4
-4
@@ -25,8 +25,8 @@
|
|||||||
void Button::onPress()
|
void Button::onPress()
|
||||||
{
|
{
|
||||||
bool check = (pressHandler && pressHandler());
|
bool check = (pressHandler && pressHandler());
|
||||||
if (check != bool(flags & BUTTON_CHECKED)) {
|
if (check != bool(windowFlags & BUTTON_CHECKED)) {
|
||||||
flags ^= BUTTON_CHECKED;
|
windowFlags ^= BUTTON_CHECKED;
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ void TextButton::paint(BitmapBuffer * dc)
|
|||||||
textColor = FOCUS_COLOR;
|
textColor = FOCUS_COLOR;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (flags & BUTTON_BACKGROUND) {
|
if (windowFlags & BUTTON_BACKGROUND) {
|
||||||
if (hasFocus()) {
|
if (hasFocus()) {
|
||||||
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, FOCUS_BGCOLOR);
|
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, FOCUS_BGCOLOR);
|
||||||
dc->drawSolidFilledRect(2, 2, rect.w - 4, rect.h - 4, DISABLE_COLOR);
|
dc->drawSolidFilledRect(2, 2, rect.w - 4, rect.h - 4, DISABLE_COLOR);
|
||||||
@@ -102,7 +102,7 @@ void TextButton::paint(BitmapBuffer * dc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dc->drawText(rect.w / 2, (rect.h - getFontHeight(flags)) / 2, text.c_str(), CENTERED | textColor);
|
dc->drawText(rect.w / 2, (rect.h - getFontHeight(textFlags)) / 2, text.c_str(), CENTERED | textColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IconButton::paint(BitmapBuffer * dc)
|
void IconButton::paint(BitmapBuffer * dc)
|
||||||
|
|||||||
+18
-23
@@ -23,20 +23,17 @@
|
|||||||
#include "form.h"
|
#include "form.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
enum ButtonFlags {
|
constexpr WindowFlags BUTTON_BACKGROUND = FORM_FLAGS_LAST << 1;
|
||||||
BUTTON_BACKGROUND = 1,
|
constexpr WindowFlags BUTTON_CHECKED = FORM_FLAGS_LAST << 2;
|
||||||
BUTTON_CHECKED = 2,
|
constexpr WindowFlags BUTTON_NOFOCUS = FORM_FLAGS_LAST << 3;
|
||||||
BUTTON_NOFOCUS = 4,
|
constexpr WindowFlags BUTTON_CHECKED_ON_FOCUS = FORM_FLAGS_LAST << 4;
|
||||||
BUTTON_CHECKED_ON_FOCUS = 8,
|
constexpr WindowFlags BUTTON_DISABLED = FORM_FLAGS_LAST << 5;
|
||||||
BUTTON_DISABLED = 16,
|
|
||||||
};
|
|
||||||
|
|
||||||
class Button : public FormField {
|
class Button : public FormField {
|
||||||
public:
|
public:
|
||||||
Button(Window * parent, const rect_t & rect, std::function<uint8_t(void)> pressHandler=nullptr, uint8_t flags=0):
|
Button(FormGroup * parent, const rect_t & rect, std::function<uint8_t(void)> pressHandler = nullptr, WindowFlags windowFlags = 0):
|
||||||
FormField(parent, rect),
|
FormField(parent, rect, windowFlags),
|
||||||
pressHandler(pressHandler),
|
pressHandler(pressHandler)
|
||||||
flags(flags)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,8 +46,8 @@ class Button : public FormField {
|
|||||||
|
|
||||||
void enable(bool enabled=true)
|
void enable(bool enabled=true)
|
||||||
{
|
{
|
||||||
if (!enabled != bool(flags & BUTTON_DISABLED)) {
|
if (!enabled != bool(windowFlags & BUTTON_DISABLED)) {
|
||||||
flags ^= BUTTON_DISABLED;
|
windowFlags ^= BUTTON_DISABLED;
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,23 +59,23 @@ class Button : public FormField {
|
|||||||
|
|
||||||
void check(bool checked=true)
|
void check(bool checked=true)
|
||||||
{
|
{
|
||||||
if (checked != bool(flags & BUTTON_CHECKED)) {
|
if (checked != bool(windowFlags & BUTTON_CHECKED)) {
|
||||||
flags ^= BUTTON_CHECKED;
|
windowFlags ^= BUTTON_CHECKED;
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool enabled()
|
bool enabled()
|
||||||
{
|
{
|
||||||
return !(flags & BUTTON_DISABLED);
|
return !(windowFlags & BUTTON_DISABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool checked()
|
bool checked()
|
||||||
{
|
{
|
||||||
if (flags & BUTTON_CHECKED_ON_FOCUS)
|
if (windowFlags & BUTTON_CHECKED_ON_FOCUS)
|
||||||
return hasFocus();
|
return hasFocus();
|
||||||
else
|
else
|
||||||
return flags & BUTTON_CHECKED;
|
return windowFlags & BUTTON_CHECKED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPressHandler(std::function<uint8_t(void)> handler)
|
void setPressHandler(std::function<uint8_t(void)> handler)
|
||||||
@@ -104,18 +101,16 @@ class Button : public FormField {
|
|||||||
protected:
|
protected:
|
||||||
std::function<uint8_t(void)> pressHandler;
|
std::function<uint8_t(void)> pressHandler;
|
||||||
std::function<void(void)> checkHandler;
|
std::function<void(void)> checkHandler;
|
||||||
uint8_t flags;
|
|
||||||
|
|
||||||
void onPress();
|
void onPress();
|
||||||
};
|
};
|
||||||
|
|
||||||
class TextButton : public Button {
|
class TextButton : public Button {
|
||||||
public:
|
public:
|
||||||
TextButton(Window * parent, const rect_t & rect, std::string text, std::function<uint8_t(void)> pressHandler = nullptr, uint8_t flags = BUTTON_BACKGROUND):
|
TextButton(FormGroup * parent, const rect_t & rect, std::string text, std::function<uint8_t(void)> pressHandler = nullptr, WindowFlags windowFlags = BUTTON_BACKGROUND):
|
||||||
Button(parent, rect, pressHandler, flags),
|
Button(parent, rect, pressHandler, windowFlags | OPAQUE),
|
||||||
text(std::move(text))
|
text(std::move(text))
|
||||||
{
|
{
|
||||||
windowFlags = OPAQUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
@@ -141,7 +136,7 @@ class TextButton : public Button {
|
|||||||
|
|
||||||
class IconButton: public Button {
|
class IconButton: public Button {
|
||||||
public:
|
public:
|
||||||
IconButton(Window * parent, const rect_t & rect, uint8_t icon, std::function<uint8_t(void)> pressHandler, uint8_t flags = 0):
|
IconButton(FormGroup * parent, const rect_t & rect, uint8_t icon, std::function<uint8_t(void)> pressHandler, WindowFlags flags = 0):
|
||||||
Button(parent, rect, pressHandler, flags),
|
Button(parent, rect, pressHandler, flags),
|
||||||
icon(icon)
|
icon(icon)
|
||||||
{
|
{
|
||||||
|
|||||||
+3
-4
@@ -21,15 +21,14 @@
|
|||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
|
|
||||||
Choice::Choice(Window * parent, const rect_t & rect, const char * values, int16_t vmin, int16_t vmax,
|
Choice::Choice(FormGroup * 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) :
|
std::function<int16_t()> getValue, std::function<void(int16_t)> setValue) :
|
||||||
ChoiceBase(parent, rect),
|
ChoiceBase(parent, rect),
|
||||||
values(values),
|
values(values),
|
||||||
vmin(vmin),
|
vmin(vmin),
|
||||||
vmax(vmax),
|
vmax(vmax),
|
||||||
getValue(std::move(getValue)),
|
getValue(std::move(getValue)),
|
||||||
setValue(std::move(setValue)),
|
setValue(std::move(setValue))
|
||||||
flags(flags)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-5
@@ -29,9 +29,9 @@ enum ChoiceType {
|
|||||||
|
|
||||||
class ChoiceBase : public FormField {
|
class ChoiceBase : public FormField {
|
||||||
public:
|
public:
|
||||||
ChoiceBase(Window * parent, const rect_t & rect, ChoiceType type = CHOICE_TYPE_DROPOWN):
|
ChoiceBase(FormGroup * parent, const rect_t & rect, ChoiceType type = CHOICE_TYPE_DROPOWN):
|
||||||
FormField(parent, rect),
|
FormField(parent, rect),
|
||||||
type(type)
|
type(type)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ class ChoiceBase : public FormField {
|
|||||||
|
|
||||||
class Choice : public ChoiceBase {
|
class Choice : public ChoiceBase {
|
||||||
public:
|
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);
|
Choice(FormGroup * 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);
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
std::string getName() override
|
std::string getName() override
|
||||||
@@ -88,7 +88,6 @@ class Choice : public ChoiceBase {
|
|||||||
std::function<void(int16_t)> setValue;
|
std::function<void(int16_t)> setValue;
|
||||||
std::function<bool(int)> isValueAvailable;
|
std::function<bool(int)> isValueAvailable;
|
||||||
std::function<std::string(int32_t)> textHandler;
|
std::function<std::string(int32_t)> textHandler;
|
||||||
LcdFlags flags = 0;
|
|
||||||
|
|
||||||
virtual void openMenu();
|
virtual void openMenu();
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-3
@@ -19,15 +19,13 @@
|
|||||||
|
|
||||||
#include "dialog.h"
|
#include "dialog.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "form.h"
|
|
||||||
|
|
||||||
Dialog::Dialog(std::string title, const rect_t rect):
|
Dialog::Dialog(std::string title, const rect_t rect):
|
||||||
Window(&mainWindow, rect, OPAQUE),
|
FormGroup(&mainWindow, rect, OPAQUE),
|
||||||
title(std::move(title)),
|
title(std::move(title)),
|
||||||
previousFocus(focusWindow)
|
previousFocus(focusWindow)
|
||||||
{
|
{
|
||||||
bringToTop();
|
bringToTop();
|
||||||
FormField::clearCurrentField();
|
|
||||||
setFocus();
|
setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -20,9 +20,9 @@
|
|||||||
#ifndef _DIALOG_H_
|
#ifndef _DIALOG_H_
|
||||||
#define _DIALOG_H_
|
#define _DIALOG_H_
|
||||||
|
|
||||||
#include "window.h"
|
#include "form.h"
|
||||||
|
|
||||||
class Dialog: public Window {
|
class Dialog: public FormGroup {
|
||||||
public:
|
public:
|
||||||
Dialog(std::string title, const rect_t rect);
|
Dialog(std::string title, const rect_t rect);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ bool compare_nocase(const std::string &first, const std::string &second)
|
|||||||
return strcasecmp(first.c_str(), second.c_str()) < 0;
|
return strcasecmp(first.c_str(), second.c_str()) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
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):
|
FileChoice::FileChoice(FormGroup * parent, const rect_t & rect, std::string folder, const char * extension, int maxlen, std::function<std::string()> getValue, std::function<void(std::string)> setValue):
|
||||||
ChoiceBase(parent, rect, CHOICE_TYPE_FOLDER),
|
ChoiceBase(parent, rect, CHOICE_TYPE_FOLDER),
|
||||||
folder(std::move(folder)),
|
folder(std::move(folder)),
|
||||||
extension(extension),
|
extension(extension),
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
class FileChoice: public ChoiceBase {
|
class FileChoice: public ChoiceBase {
|
||||||
public:
|
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);
|
FileChoice(FormGroup * parent, const rect_t & rect, std::string folder, const char * extension, int maxlen, std::function<std::string()> getValue, std::function<void(std::string)> setValue);
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
std::string getName() override
|
std::string getName() override
|
||||||
|
|||||||
+96
-51
@@ -21,33 +21,12 @@
|
|||||||
#include "bitmapbuffer.h"
|
#include "bitmapbuffer.h"
|
||||||
#include "libopenui_config.h"
|
#include "libopenui_config.h"
|
||||||
|
|
||||||
FormField * FormField::current = nullptr;
|
FormField::FormField(Window *parent, const rect_t & rect, WindowFlags windowFlags) :
|
||||||
|
Window(parent, rect, windowFlags)
|
||||||
FormField::FormField(Window *parent, const rect_t &rect, uint8_t flags) :
|
|
||||||
Window(parent, rect, flags)
|
|
||||||
{
|
{
|
||||||
if (current) {
|
FormGroup * form = dynamic_cast<FormGroup *>(parent);
|
||||||
setPreviousField(current);
|
if (form) {
|
||||||
current->setNextField(this);
|
form->addField(this);
|
||||||
}
|
|
||||||
|
|
||||||
FormWindow * form = dynamic_cast<FormWindow *>(parent);
|
|
||||||
if (form && !form->getFirstField())
|
|
||||||
form->setFirstField(this);
|
|
||||||
|
|
||||||
current = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(HARDWARE_KEYS)
|
|
||||||
void FormWindow::onEvent(event_t event)
|
|
||||||
{
|
|
||||||
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
|
|
||||||
|
|
||||||
if (event == EVT_KEY_BREAK(KEY_EXIT) && first && getFocus() != first) {
|
|
||||||
first->setFocus();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Window::onEvent(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,12 +36,12 @@ void FormField::onEvent(event_t event)
|
|||||||
|
|
||||||
if (event == EVT_ROTARY_RIGHT/*EVT_KEY_BREAK(KEY_DOWN)*/) {
|
if (event == EVT_ROTARY_RIGHT/*EVT_KEY_BREAK(KEY_DOWN)*/) {
|
||||||
if (next) {
|
if (next) {
|
||||||
next->setFocus();
|
next->setFocus(SET_FOCUS_FORWARD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (event == EVT_ROTARY_LEFT/*EVT_KEY_BREAK(KEY_UP)*/) {
|
else if (event == EVT_ROTARY_LEFT/*EVT_KEY_BREAK(KEY_UP)*/) {
|
||||||
if (previous) {
|
if (previous) {
|
||||||
previous->setFocus();
|
previous->setFocus(SET_FOCUS_BACKWARD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (event == EVT_KEY_BREAK(KEY_ENTER)) {
|
else if (event == EVT_KEY_BREAK(KEY_ENTER)) {
|
||||||
@@ -78,24 +57,6 @@ void FormField::onEvent(event_t event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormGroup::onEvent(event_t event)
|
|
||||||
{
|
|
||||||
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
|
|
||||||
|
|
||||||
if (event == EVT_KEY_BREAK(KEY_ENTER)) {
|
|
||||||
editMode = true;
|
|
||||||
first->setFocus();
|
|
||||||
}
|
|
||||||
else if (event == EVT_KEY_BREAK(KEY_EXIT) && editMode) {
|
|
||||||
editMode = false;
|
|
||||||
setFocus();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
FormField::onEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void FormField::paint(BitmapBuffer * dc)
|
void FormField::paint(BitmapBuffer * dc)
|
||||||
{
|
{
|
||||||
if (editMode) {
|
if (editMode) {
|
||||||
@@ -109,12 +70,96 @@ void FormField::paint(BitmapBuffer * dc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormGroup::paint(BitmapBuffer * dc)
|
void FormGroup::addField(FormField * field)
|
||||||
{
|
{
|
||||||
if (!editMode && hasFocus()) {
|
if (field->getWindowFlags() & FORM_DETACHED)
|
||||||
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, FOCUS_BGCOLOR);
|
return;
|
||||||
|
|
||||||
|
if (!first) {
|
||||||
|
first = field;
|
||||||
|
if (windowFlags & FORM_FORWARD_FOCUS)
|
||||||
|
link(previous, field);
|
||||||
}
|
}
|
||||||
else if (!(windowFlags & BORDER_FOCUS_ONLY)) {
|
if (last)
|
||||||
dc->drawSolidRect(0, 0, rect.w, rect.h, 1, DISABLE_COLOR);
|
link(last, field);
|
||||||
|
last = field;
|
||||||
|
if (!(windowFlags & FORM_FORWARD_FOCUS))
|
||||||
|
link(field, first);
|
||||||
|
else
|
||||||
|
field->setNextField(this);
|
||||||
|
if (!focusWindow && !(field->getWindowFlags() & FORM_FORWARD_FOCUS))
|
||||||
|
field->setFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FormGroup::setFocus(uint8_t flag)
|
||||||
|
{
|
||||||
|
if (windowFlags & FORM_FORWARD_FOCUS) {
|
||||||
|
switch (flag) {
|
||||||
|
case SET_FOCUS_FIRST:
|
||||||
|
first->setFocus(SET_FOCUS_FIRST);
|
||||||
|
break;
|
||||||
|
case SET_FOCUS_BACKWARD:
|
||||||
|
if (focusWindow == first)
|
||||||
|
previous->setFocus(SET_FOCUS_BACKWARD);
|
||||||
|
else
|
||||||
|
last->setFocus(SET_FOCUS_BACKWARD);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (focusWindow == previous)
|
||||||
|
first->setFocus();
|
||||||
|
else
|
||||||
|
next->setFocus();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
FormField::setFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HARDWARE_KEYS)
|
||||||
|
void FormGroup::onEvent(event_t event)
|
||||||
|
{
|
||||||
|
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
|
||||||
|
|
||||||
|
if (event == EVT_KEY_BREAK(KEY_ENTER)) {
|
||||||
|
editMode = true;
|
||||||
|
first->setFocus();
|
||||||
|
}
|
||||||
|
else if (event == EVT_KEY_BREAK(KEY_EXIT) && editMode) {
|
||||||
|
editMode = false;
|
||||||
|
setFocus(SET_FOCUS_DEFAULT);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
FormField::onEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void FormGroup::paint(BitmapBuffer * dc)
|
||||||
|
{
|
||||||
|
if (!(windowFlags & FORM_FORWARD_FOCUS)) {
|
||||||
|
if (!editMode && hasFocus()) {
|
||||||
|
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, FOCUS_BGCOLOR);
|
||||||
|
}
|
||||||
|
else if (!(windowFlags & BORDER_FOCUS_ONLY)) {
|
||||||
|
dc->drawSolidRect(0, 0, rect.w, rect.h, 1, DISABLE_COLOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(HARDWARE_KEYS)
|
||||||
|
void FormWindow::onEvent(event_t event)
|
||||||
|
{
|
||||||
|
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
|
||||||
|
|
||||||
|
if (event == EVT_KEY_BREAK(KEY_EXIT) && first) {
|
||||||
|
Window * currentFocus = getFocus();
|
||||||
|
first->setFocus(SET_FOCUS_FIRST);
|
||||||
|
if (getFocus() != currentFocus)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Window::onEvent(event);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
+26
-77
@@ -22,11 +22,13 @@
|
|||||||
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
class FormField: public Window {
|
constexpr WindowFlags FORM_FORWARD_FOCUS = WINDOW_FLAGS_LAST << 1;
|
||||||
friend class FormWindow;
|
constexpr WindowFlags FORM_DETACHED = WINDOW_FLAGS_LAST << 2;
|
||||||
|
constexpr WindowFlags FORM_FLAGS_LAST = FORM_DETACHED;
|
||||||
|
|
||||||
|
class FormField: public Window {
|
||||||
public:
|
public:
|
||||||
FormField(Window * parent, const rect_t & rect, uint8_t flags=0);
|
FormField(Window * parent, const rect_t & rect, WindowFlags windowFlags = 0);
|
||||||
|
|
||||||
inline void setNextField(FormField *field)
|
inline void setNextField(FormField *field)
|
||||||
{
|
{
|
||||||
@@ -38,27 +40,12 @@ class FormField: public Window {
|
|||||||
previous = field;
|
previous = field;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static void setCurrentField(FormField * field)
|
inline FormField * getPreviousField()
|
||||||
{
|
|
||||||
current = field;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static void clearCurrentField()
|
|
||||||
{
|
|
||||||
setCurrentField(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static FormField * getCurrentField()
|
|
||||||
{
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual FormField * getPreviousField()
|
|
||||||
{
|
{
|
||||||
return previous;
|
return previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual FormField * getNextField()
|
inline FormField * getNextField()
|
||||||
{
|
{
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
@@ -86,7 +73,6 @@ class FormField: public Window {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static FormField * current;
|
|
||||||
FormField * next = nullptr;
|
FormField * next = nullptr;
|
||||||
FormField * previous = nullptr;
|
FormField * previous = nullptr;
|
||||||
bool editMode = false;
|
bool editMode = false;
|
||||||
@@ -94,13 +80,12 @@ class FormField: public Window {
|
|||||||
|
|
||||||
class FormGroup: public FormField {
|
class FormGroup: public FormField {
|
||||||
public:
|
public:
|
||||||
FormGroup(Window * parent, const rect_t & rect, uint8_t flags=0) :
|
FormGroup(Window * parent, const rect_t & rect, WindowFlags windowflags = 0) :
|
||||||
FormField(parent, rect, flags)
|
FormField(parent, rect, windowflags)
|
||||||
{
|
{
|
||||||
FormField::current = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~FormGroup()
|
~FormGroup() override
|
||||||
{
|
{
|
||||||
deleteChildren();
|
deleteChildren();
|
||||||
}
|
}
|
||||||
@@ -116,33 +101,26 @@ class FormGroup: public FormField {
|
|||||||
{
|
{
|
||||||
Window::clear();
|
Window::clear();
|
||||||
first = nullptr;
|
first = nullptr;
|
||||||
FormField::current = nullptr;
|
last = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setFirstField(FormField * field)
|
void setFocus(uint8_t flag = SET_FOCUS_DEFAULT) override;
|
||||||
{
|
|
||||||
first = field;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void setLastField(FormField * field = nullptr)
|
void addField(FormField * field);
|
||||||
{
|
|
||||||
// by default the current field is the last one
|
|
||||||
if (!field)
|
|
||||||
field = getCurrentField();
|
|
||||||
|
|
||||||
FormField::link(field, first);
|
inline FormField * getFirstField()
|
||||||
|
|
||||||
// now the current field is the group, it will be linked to the next one
|
|
||||||
FormField::setCurrentField(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
FormField * getFirstField()
|
|
||||||
{
|
{
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline FormField * getLastField()
|
||||||
|
{
|
||||||
|
return last;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FormField * first = nullptr;
|
FormField * first = nullptr;
|
||||||
|
FormField * last = nullptr;
|
||||||
|
|
||||||
#if defined(HARDWARE_KEYS)
|
#if defined(HARDWARE_KEYS)
|
||||||
void onEvent(event_t event) override;
|
void onEvent(event_t event) override;
|
||||||
@@ -151,12 +129,11 @@ class FormGroup: public FormField {
|
|||||||
void paint(BitmapBuffer * dc) override;
|
void paint(BitmapBuffer * dc) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FormWindow: public Window {
|
class FormWindow: public FormGroup {
|
||||||
public:
|
public:
|
||||||
FormWindow(Window * parent, const rect_t & rect) :
|
FormWindow(Window * parent, const rect_t & rect, WindowFlags windowFlags = 0) :
|
||||||
Window(parent, rect)
|
FormGroup(parent, rect, windowFlags)
|
||||||
{
|
{
|
||||||
FormField::current = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
@@ -166,42 +143,14 @@ class FormWindow: public Window {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void clear()
|
|
||||||
{
|
|
||||||
first = nullptr;
|
|
||||||
Window::clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
FormField * getFirstField()
|
|
||||||
{
|
|
||||||
return first;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void setFirstField(FormField * field)
|
|
||||||
{
|
|
||||||
first = field;
|
|
||||||
field->setFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void setLastField(FormField * field = nullptr)
|
|
||||||
{
|
|
||||||
if (!field)
|
|
||||||
field = FormField::getCurrentField();
|
|
||||||
FormField::link(field, first);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
#if defined(HARDWARE_KEYS)
|
|
||||||
void onEvent(event_t event) override;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void paint(BitmapBuffer * dc) override
|
void paint(BitmapBuffer * dc) override
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
#if defined(HARDWARE_KEYS)
|
||||||
FormField * first = nullptr;
|
void onEvent(event_t event) override;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+2
-2
@@ -24,9 +24,9 @@ void MenuToolbarButton::paint(BitmapBuffer * dc)
|
|||||||
{
|
{
|
||||||
if (checked()) {
|
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, FOCUS_BGCOLOR);
|
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);
|
dc->drawSizedText(rect.w / 2, (rect.h - getFontHeight(STDSIZE)) / 2 + 1, &picto, 1, CENTERED | FOCUS_COLOR);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dc->drawSizedText(rect.w / 2, (rect.h - getFontHeight(flags)) / 2 + 1, &picto, 1, CENTERED | DEFAULT_COLOR);
|
dc->drawSizedText(rect.w / 2, (rect.h - getFontHeight(STDSIZE)) / 2 + 1, &picto, 1, CENTERED | DEFAULT_COLOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-4
@@ -27,7 +27,7 @@ int getFirstAvailable(int min, int max, std::function<bool(int)>isValueAvailable
|
|||||||
|
|
||||||
class MenuToolbarButton: public Button {
|
class MenuToolbarButton: public Button {
|
||||||
public:
|
public:
|
||||||
MenuToolbarButton(Window * window, const rect_t & rect, char picto):
|
MenuToolbarButton(FormGroup * window, const rect_t & rect, char picto):
|
||||||
#if defined(HARDWARE_TOUCH)
|
#if defined(HARDWARE_TOUCH)
|
||||||
Button(window, rect, nullptr, BUTTON_CHECKED_ON_FOCUS),
|
Button(window, rect, nullptr, BUTTON_CHECKED_ON_FOCUS),
|
||||||
#else
|
#else
|
||||||
@@ -66,16 +66,15 @@ class MenuToolbarButton: public Button {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class MenuToolbar: public Window {
|
class MenuToolbar: public FormGroup {
|
||||||
friend T;
|
friend T;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MenuToolbar(T * choice, Menu * menu):
|
MenuToolbar(T * choice, Menu * menu):
|
||||||
Window(menu, MENUS_TOOLBAR_RECT, NO_SCROLLBAR),
|
FormGroup(menu, MENUS_TOOLBAR_RECT, NO_SCROLLBAR),
|
||||||
choice(choice),
|
choice(choice),
|
||||||
menu(menu)
|
menu(menu)
|
||||||
{
|
{
|
||||||
FormField::clearCurrentField();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~MenuToolbar() override
|
~MenuToolbar() override
|
||||||
|
|||||||
+4
-4
@@ -22,10 +22,10 @@
|
|||||||
|
|
||||||
void StaticText::paint(BitmapBuffer * dc)
|
void StaticText::paint(BitmapBuffer * dc)
|
||||||
{
|
{
|
||||||
if (flags & BUTTON_BACKGROUND)
|
if (windowFlags & BUTTON_BACKGROUND)
|
||||||
dc->drawSolidFilledRect(0, 0, rect.w, rect.h, DISABLE_COLOR);
|
dc->drawSolidFilledRect(0, 0, rect.w, rect.h, DISABLE_COLOR);
|
||||||
if (flags & CENTERED)
|
if (textFlags & CENTERED)
|
||||||
dc->drawText(rect.w / 2, (rect.h - getFontHeight(flags)) / 2, text.c_str(), CENTERED | flags);
|
dc->drawText(rect.w / 2, (rect.h - getFontHeight(textFlags)) / 2, text.c_str(), textFlags);
|
||||||
else
|
else
|
||||||
dc->drawText(0, 0, text.c_str(), flags);
|
dc->drawText(0, 0, text.c_str(), textFlags);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-12
@@ -25,10 +25,9 @@
|
|||||||
|
|
||||||
class StaticText : public Window {
|
class StaticText : public Window {
|
||||||
public:
|
public:
|
||||||
StaticText(Window * parent, const rect_t & rect, std::string text = "", LcdFlags flags = 0) :
|
StaticText(Window * parent, const rect_t & rect, std::string text = "", WindowFlags windowFlags = 0, LcdFlags textFlags = 0) :
|
||||||
Window(parent, rect),
|
Window(parent, rect, windowFlags, textFlags),
|
||||||
text(std::move(text)),
|
text(std::move(text))
|
||||||
flags(flags)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,12 +38,6 @@ class StaticText : public Window {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void setFlags(LcdFlags flags)
|
|
||||||
{
|
|
||||||
this->flags = flags;
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void paint(BitmapBuffer * dc) override;
|
void paint(BitmapBuffer * dc) override;
|
||||||
|
|
||||||
void setText(std::string value)
|
void setText(std::string value)
|
||||||
@@ -55,13 +48,12 @@ class StaticText : public Window {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string text;
|
std::string text;
|
||||||
LcdFlags flags;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Subtitle: public StaticText {
|
class Subtitle: public StaticText {
|
||||||
public:
|
public:
|
||||||
Subtitle(Window * parent, const rect_t & rect, const char * text):
|
Subtitle(Window * parent, const rect_t & rect, const char * text):
|
||||||
StaticText(parent, rect, text, BOLD)
|
StaticText(parent, rect, text, 0, BOLD)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -22,16 +22,17 @@
|
|||||||
Window * Window::focusWindow = nullptr;
|
Window * Window::focusWindow = nullptr;
|
||||||
std::list<Window *> Window::trash;
|
std::list<Window *> Window::trash;
|
||||||
|
|
||||||
Window::Window(Window * parent, const rect_t & rect, uint8_t flags):
|
Window::Window(Window * parent, const rect_t & rect, WindowFlags windowFlags, LcdFlags textFlags):
|
||||||
parent(parent),
|
parent(parent),
|
||||||
rect(rect),
|
rect(rect),
|
||||||
innerWidth(rect.w),
|
innerWidth(rect.w),
|
||||||
innerHeight(rect.h),
|
innerHeight(rect.h),
|
||||||
windowFlags(flags)
|
windowFlags(windowFlags),
|
||||||
|
textFlags(textFlags)
|
||||||
{
|
{
|
||||||
if (parent) {
|
if (parent) {
|
||||||
parent->addChild(this);
|
parent->addChild(this);
|
||||||
if (!(flags & TRANSPARENT)) {
|
if (!(windowFlags & TRANSPARENT)) {
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,7 +109,7 @@ void Window::clearFocus()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setFocus()
|
void Window::setFocus(uint8_t flag)
|
||||||
{
|
{
|
||||||
TRACE_WINDOWS("%s setFocus()", getWindowDebugString().c_str());
|
TRACE_WINDOWS("%s setFocus()", getWindowDebugString().c_str());
|
||||||
|
|
||||||
|
|||||||
+26
-10
@@ -31,23 +31,33 @@
|
|||||||
#include "libopenui_helpers.h"
|
#include "libopenui_helpers.h"
|
||||||
#include "libopenui_config.h"
|
#include "libopenui_config.h"
|
||||||
|
|
||||||
|
typedef uint32_t WindowFlags;
|
||||||
|
|
||||||
// OPAQUE/TRANSPARENT defined in WinGDI
|
// OPAQUE/TRANSPARENT defined in WinGDI
|
||||||
#ifndef OPAQUE
|
#ifndef OPAQUE
|
||||||
#define OPAQUE 1
|
#define OPAQUE 1
|
||||||
#define TRANSPARENT 2
|
#define TRANSPARENT 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
constexpr uint8_t NO_SCROLLBAR = 4;
|
constexpr WindowFlags NO_SCROLLBAR = 4;
|
||||||
constexpr uint8_t FORWARD_SCROLL = 8;
|
constexpr WindowFlags FORWARD_SCROLL = 8;
|
||||||
constexpr uint8_t REFRESH_ALWAYS = 16;
|
constexpr WindowFlags REFRESH_ALWAYS = 16;
|
||||||
constexpr uint8_t BORDER_FOCUS_ONLY = 32;
|
constexpr WindowFlags BORDER_FOCUS_ONLY = 32;
|
||||||
constexpr uint8_t PAINT_CHILDREN_FIRST = 64;
|
constexpr WindowFlags PAINT_CHILDREN_FIRST = 64;
|
||||||
|
constexpr WindowFlags WINDOW_FLAGS_LAST = PAINT_CHILDREN_FIRST;
|
||||||
|
|
||||||
|
enum SetFocusFlag {
|
||||||
|
SET_FOCUS_DEFAULT,
|
||||||
|
SET_FOCUS_FORWARD,
|
||||||
|
SET_FOCUS_BACKWARD,
|
||||||
|
SET_FOCUS_FIRST
|
||||||
|
};
|
||||||
|
|
||||||
class Window {
|
class Window {
|
||||||
friend class GridLayout;
|
friend class GridLayout;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Window(Window * parent, const rect_t & rect, uint8_t flags=0);
|
Window(Window * parent, const rect_t & rect, WindowFlags windowFlags = 0, LcdFlags textFlags = 0);
|
||||||
|
|
||||||
virtual ~Window();
|
virtual ~Window();
|
||||||
|
|
||||||
@@ -86,16 +96,21 @@ class Window {
|
|||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getWindowFlags() const
|
WindowFlags getWindowFlags() const
|
||||||
{
|
{
|
||||||
return windowFlags;
|
return windowFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setWindowFlags(uint8_t flags)
|
void setWindowFlags(WindowFlags flags)
|
||||||
{
|
{
|
||||||
windowFlags = flags;
|
windowFlags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setTextFlags(LcdFlags flags)
|
||||||
|
{
|
||||||
|
textFlags = flags;
|
||||||
|
}
|
||||||
|
|
||||||
void setCloseHandler(std::function<void()> handler)
|
void setCloseHandler(std::function<void()> handler)
|
||||||
{
|
{
|
||||||
closeHandler = std::move(handler);
|
closeHandler = std::move(handler);
|
||||||
@@ -126,7 +141,7 @@ class Window {
|
|||||||
|
|
||||||
static void clearFocus();
|
static void clearFocus();
|
||||||
|
|
||||||
void setFocus();
|
virtual void setFocus(uint8_t flag = SET_FOCUS_DEFAULT);
|
||||||
|
|
||||||
void setRect(rect_t rect)
|
void setRect(rect_t rect)
|
||||||
{
|
{
|
||||||
@@ -292,7 +307,8 @@ class Window {
|
|||||||
coord_t innerHeight;
|
coord_t innerHeight;
|
||||||
coord_t scrollPositionX = 0;
|
coord_t scrollPositionX = 0;
|
||||||
coord_t scrollPositionY = 0;
|
coord_t scrollPositionY = 0;
|
||||||
uint8_t windowFlags;
|
WindowFlags windowFlags;
|
||||||
|
LcdFlags textFlags;
|
||||||
|
|
||||||
static Window * focusWindow;
|
static Window * focusWindow;
|
||||||
static std::list<Window *> trash;
|
static std::list<Window *> trash;
|
||||||
|
|||||||
Reference in New Issue
Block a user