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 {
public:
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):
FormField(parent, rect),
std::function<int32_t()> getValue, std::function<void(int32_t)> setValue = nullptr, WindowFlags windowFlags = 0, LcdFlags textFlags = 0):
FormField(parent, rect, windowFlags, textFlags),
vmin(vmin),
vmax(vmax),
_getValue(std::move(getValue)),
_setValue(std::move(setValue)),
flags(flags)
_setValue(std::move(setValue))
{
}
@@ -98,7 +97,6 @@ class BaseNumberEdit : public FormField {
int32_t step = 1;
std::function<int32_t()> _getValue;
std::function<void(int32_t)> _setValue;
LcdFlags flags;
};
#endif // _BASENUMBEREDIT_H_
+24 -14
View File
@@ -21,13 +21,13 @@
#include "bitmapbuffer.h"
#include "libopenui_config.h"
FormField::FormField(Window *parent, const rect_t & rect, WindowFlags windowFlags) :
Window(parent, rect, windowFlags)
FormField::FormField(Window * parent, const rect_t & rect, WindowFlags windowFlags, LcdFlags textFlags) :
Window(parent, rect, windowFlags, textFlags)
{
if (!(windowFlags & NO_FOCUS)) {
FormGroup * form = dynamic_cast<FormGroup *>(parent);
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)
return;
if (!first) {
first = field;
if (windowFlags & FORM_FORWARD_FOCUS)
link(previous, field);
last = field;
}
if (last)
link(last, field);
last = field;
if (!(windowFlags & FORM_FORWARD_FOCUS))
link(field, first);
else
field->setNextField(this);
if (!focusWindow && !(field->getWindowFlags() & FORM_FORWARD_FOCUS))
if (front) {
if (first)
link(field, first);
first = field;
}
else {
if (last)
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();
}
}
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 {
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)
{
@@ -109,7 +109,7 @@ class FormGroup: public FormField {
void setFocus(uint8_t flag = SET_FOCUS_DEFAULT) override;
void addField(FormField * field);
void addField(FormField * field, bool front = false);
protected:
FormField * first = nullptr;
+4 -4
View File
@@ -23,8 +23,8 @@
#include "keyboard_number.h"
#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):
BaseNumberEdit(parent, rect, vmin, vmax, std::move(getValue), std::move(setValue), 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), windowFlags, textFlags)
{
}
@@ -47,9 +47,9 @@ void NumberEdit::paint(BitmapBuffer * dc)
if (displayFunction)
displayFunction(dc, textColor, value);
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
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)
+1 -1
View File
@@ -26,7 +26,7 @@
class NumberEdit : public BaseNumberEdit {
public:
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)
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)
{
if (parent) {
parent->addChild(this);
parent->addChild(this, windowFlags & PUSH_FRONT);
if (!(windowFlags & TRANSPARENT)) {
invalidate();
}
+14 -10
View File
@@ -39,14 +39,15 @@ typedef uint32_t WindowFlags;
#undef TRANSPARENT
#endif
constexpr WindowFlags OPAQUE = 1u << 0;
constexpr WindowFlags TRANSPARENT = 1u << 1;
constexpr WindowFlags NO_SCROLLBAR = 1u << 2;
constexpr WindowFlags NO_FOCUS = 1u << 3;
constexpr WindowFlags FORWARD_SCROLL = 1u << 4;
constexpr WindowFlags REFRESH_ALWAYS = 1u << 5;
constexpr WindowFlags PAINT_CHILDREN_FIRST = 1u << 6;
constexpr WindowFlags WINDOW_FLAGS_LAST = PAINT_CHILDREN_FIRST;
constexpr WindowFlags OPAQUE = 1u << 0u;
constexpr WindowFlags TRANSPARENT = 1u << 1u;
constexpr WindowFlags NO_SCROLLBAR = 1u << 2u;
constexpr WindowFlags NO_FOCUS = 1u << 3u;
constexpr WindowFlags FORWARD_SCROLL = 1u << 4u;
constexpr WindowFlags REFRESH_ALWAYS = 1u << 5u;
constexpr WindowFlags PAINT_CHILDREN_FIRST = 1u << 6u;
constexpr WindowFlags PUSH_FRONT = 1u << 7u;
constexpr WindowFlags WINDOW_FLAGS_LAST = PUSH_FRONT;
enum SetFocusFlag {
SET_FOCUS_DEFAULT,
@@ -340,9 +341,12 @@ class 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)