Possibility to PUSH_FRONT a field in a form

This commit is contained in:
Bertrand Songis
2020-03-11 19:22:46 +01:00
parent 91d00309ed
commit 86e24f417a
7 changed files with 49 additions and 37 deletions
+3 -5
View File
@@ -25,13 +25,12 @@
class BaseNumberEdit : public FormField { class BaseNumberEdit : public FormField {
public: public:
BaseNumberEdit(Window * parent, const rect_t &rect, int32_t vmin, int32_t vmax, BaseNumberEdit(Window * parent, const rect_t &rect, int32_t vmin, int32_t vmax,
std::function<int32_t()> getValue, std::function<void(int32_t)> setValue = nullptr, LcdFlags flags = 0): std::function<int32_t()> getValue, std::function<void(int32_t)> setValue = nullptr, WindowFlags windowFlags = 0, LcdFlags textFlags = 0):
FormField(parent, rect), FormField(parent, rect, windowFlags, textFlags),
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)
{ {
} }
@@ -98,7 +97,6 @@ class BaseNumberEdit : public FormField {
int32_t step = 1; int32_t step = 1;
std::function<int32_t()> _getValue; std::function<int32_t()> _getValue;
std::function<void(int32_t)> _setValue; std::function<void(int32_t)> _setValue;
LcdFlags flags;
}; };
#endif // _BASENUMBEREDIT_H_ #endif // _BASENUMBEREDIT_H_
+24 -14
View File
@@ -21,13 +21,13 @@
#include "bitmapbuffer.h" #include "bitmapbuffer.h"
#include "libopenui_config.h" #include "libopenui_config.h"
FormField::FormField(Window *parent, const rect_t & rect, WindowFlags windowFlags) : FormField::FormField(Window * parent, const rect_t & rect, WindowFlags windowFlags, LcdFlags textFlags) :
Window(parent, rect, windowFlags) Window(parent, rect, windowFlags, textFlags)
{ {
if (!(windowFlags & NO_FOCUS)) { if (!(windowFlags & NO_FOCUS)) {
FormGroup * form = dynamic_cast<FormGroup *>(parent); FormGroup * form = dynamic_cast<FormGroup *>(parent);
if (form) { if (form) {
form->addField(this); form->addField(this, windowFlags & PUSH_FRONT);
} }
} }
} }
@@ -74,25 +74,35 @@ void FormField::paint(BitmapBuffer * dc)
} }
} }
void FormGroup::addField(FormField * field) void FormGroup::addField(FormField * field, bool front)
{ {
if (field->getWindowFlags() & FORM_DETACHED) if (field->getWindowFlags() & FORM_DETACHED)
return; return;
if (!first) { if (!first) {
first = field; first = field;
if (windowFlags & FORM_FORWARD_FOCUS) last = field;
link(previous, field);
} }
if (last) if (front) {
link(last, field); if (first)
last = field; link(field, first);
if (!(windowFlags & FORM_FORWARD_FOCUS)) first = field;
link(field, first); }
else else {
field->setNextField(this); if (last)
if (!focusWindow && !(field->getWindowFlags() & FORM_FORWARD_FOCUS)) link(last, field);
last = field;
}
if (windowFlags & FORM_FORWARD_FOCUS) {
last->setNextField(this);
link(previous, first);
}
else {
link(last, first);
}
if (!focusWindow && !(field->getWindowFlags() & FORM_FORWARD_FOCUS)) {
field->setFocus(); field->setFocus();
}
} }
void FormGroup::setFocus(uint8_t flag) void FormGroup::setFocus(uint8_t flag)
+2 -2
View File
@@ -30,7 +30,7 @@ constexpr WindowFlags FORM_FLAGS_LAST = FORM_NO_BORDER;
class FormField: public Window { class FormField: public Window {
public: public:
FormField(Window * parent, const rect_t & rect, WindowFlags windowFlags = 0); FormField(Window * parent, const rect_t & rect, WindowFlags windowFlags = 0, LcdFlags textFlags = 0);
inline void setNextField(FormField *field) inline void setNextField(FormField *field)
{ {
@@ -109,7 +109,7 @@ class FormGroup: public FormField {
void setFocus(uint8_t flag = SET_FOCUS_DEFAULT) override; void setFocus(uint8_t flag = SET_FOCUS_DEFAULT) override;
void addField(FormField * field); void addField(FormField * field, bool front = false);
protected: protected:
FormField * first = nullptr; FormField * first = nullptr;
+4 -4
View File
@@ -23,8 +23,8 @@
#include "keyboard_number.h" #include "keyboard_number.h"
#endif #endif
NumberEdit::NumberEdit(Window * parent, const rect_t & rect, int32_t vmin, int32_t vmax, std::function<int32_t()> getValue, std::function<void(int32_t)> setValue, LcdFlags flags): NumberEdit::NumberEdit(Window * parent, const rect_t & rect, int32_t vmin, int32_t vmax, std::function<int32_t()> getValue, std::function<void(int32_t)> setValue, WindowFlags windowFlags, LcdFlags textFlags):
BaseNumberEdit(parent, rect, vmin, vmax, std::move(getValue), std::move(setValue), flags) BaseNumberEdit(parent, rect, vmin, vmax, std::move(getValue), std::move(setValue), windowFlags, textFlags)
{ {
} }
@@ -47,9 +47,9 @@ void NumberEdit::paint(BitmapBuffer * dc)
if (displayFunction) if (displayFunction)
displayFunction(dc, textColor, value); displayFunction(dc, textColor, value);
else if (value == 0 && !zeroText.empty()) else if (value == 0 && !zeroText.empty())
dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, zeroText.c_str(), textColor | flags); dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, zeroText.c_str(), textColor | textFlags);
else else
dc->drawNumber(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, textColor | flags, 0, prefix.c_str(), suffix.c_str()); dc->drawNumber(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, textColor | textFlags, 0, prefix.c_str(), suffix.c_str());
} }
void NumberEdit::onEvent(event_t event) void NumberEdit::onEvent(event_t event)
+1 -1
View File
@@ -26,7 +26,7 @@
class NumberEdit : public BaseNumberEdit { class NumberEdit : public BaseNumberEdit {
public: public:
NumberEdit(Window * parent, const rect_t & rect, int32_t vmin, int32_t vmax, NumberEdit(Window * parent, const rect_t & rect, int32_t vmin, int32_t vmax,
std::function<int32_t()> getValue, std::function<void(int32_t)> setValue = nullptr, LcdFlags flags = 0); std::function<int32_t()> getValue, std::function<void(int32_t)> setValue = nullptr, WindowFlags windowFlags = 0, LcdFlags textFlags = 0);
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() override
+1 -1
View File
@@ -32,7 +32,7 @@ Window::Window(Window * parent, const rect_t & rect, WindowFlags windowFlags, Lc
textFlags(textFlags) textFlags(textFlags)
{ {
if (parent) { if (parent) {
parent->addChild(this); parent->addChild(this, windowFlags & PUSH_FRONT);
if (!(windowFlags & TRANSPARENT)) { if (!(windowFlags & TRANSPARENT)) {
invalidate(); invalidate();
} }
+14 -10
View File
@@ -39,14 +39,15 @@ typedef uint32_t WindowFlags;
#undef TRANSPARENT #undef TRANSPARENT
#endif #endif
constexpr WindowFlags OPAQUE = 1u << 0; constexpr WindowFlags OPAQUE = 1u << 0u;
constexpr WindowFlags TRANSPARENT = 1u << 1; constexpr WindowFlags TRANSPARENT = 1u << 1u;
constexpr WindowFlags NO_SCROLLBAR = 1u << 2; constexpr WindowFlags NO_SCROLLBAR = 1u << 2u;
constexpr WindowFlags NO_FOCUS = 1u << 3; constexpr WindowFlags NO_FOCUS = 1u << 3u;
constexpr WindowFlags FORWARD_SCROLL = 1u << 4; constexpr WindowFlags FORWARD_SCROLL = 1u << 4u;
constexpr WindowFlags REFRESH_ALWAYS = 1u << 5; constexpr WindowFlags REFRESH_ALWAYS = 1u << 5u;
constexpr WindowFlags PAINT_CHILDREN_FIRST = 1u << 6; constexpr WindowFlags PAINT_CHILDREN_FIRST = 1u << 6u;
constexpr WindowFlags WINDOW_FLAGS_LAST = PAINT_CHILDREN_FIRST; constexpr WindowFlags PUSH_FRONT = 1u << 7u;
constexpr WindowFlags WINDOW_FLAGS_LAST = PUSH_FRONT;
enum SetFocusFlag { enum SetFocusFlag {
SET_FOCUS_DEFAULT, SET_FOCUS_DEFAULT,
@@ -340,9 +341,12 @@ class Window {
void attach(Window * window); void attach(Window * window);
void addChild(Window * window) void addChild(Window * window, bool front = false)
{ {
children.push_back(window); if (front)
children.push_front(window);
else
children.push_back(window);
} }
void removeChild(Window * window) void removeChild(Window * window)