WIP: default theme
This commit is contained in:
committed by
Raphael Coeffic
parent
83a5fd913f
commit
2a0bb66daf
+12
-9
@@ -25,15 +25,18 @@
|
||||
class BaseNumberEdit: public FormField
|
||||
{
|
||||
public:
|
||||
BaseNumberEdit(Window * parent, const rect_t &rect, int vmin, int vmax,
|
||||
std::function<int()> getValue, std::function<void(int)> setValue = nullptr, WindowFlags windowFlags = 0, LcdFlags textFlags = 0, LvglWidgetFactory *factory = nullptr):
|
||||
FormField(parent, rect, windowFlags, textFlags, factory),
|
||||
vmin(vmin),
|
||||
vmax(vmax),
|
||||
_getValue(std::move(getValue)),
|
||||
_setValue(std::move(setValue))
|
||||
{
|
||||
}
|
||||
BaseNumberEdit(Window* parent, const rect_t& rect, int vmin, int vmax,
|
||||
std::function<int()> getValue,
|
||||
std::function<void(int)> setValue = nullptr,
|
||||
WindowFlags windowFlags = 0, LcdFlags textFlags = 0,
|
||||
LvglCreate objConstruct = nullptr) :
|
||||
FormField(parent, rect, windowFlags, textFlags, objConstruct),
|
||||
vmin(vmin),
|
||||
vmax(vmax),
|
||||
_getValue(std::move(getValue)),
|
||||
_setValue(std::move(setValue))
|
||||
{
|
||||
}
|
||||
|
||||
void setMin(int value)
|
||||
{
|
||||
|
||||
+27
-16
@@ -81,13 +81,12 @@ void Button::checkEvents()
|
||||
}
|
||||
|
||||
lv_style_t style_btn;
|
||||
LvglWidgetFactory textButtonFactory = {lv_btn_create, nullptr};
|
||||
|
||||
TextButton::TextButton(FormGroup* parent, const rect_t& rect, std::string text,
|
||||
std::function<uint8_t(void)> pressHandler,
|
||||
WindowFlags windowFlags,
|
||||
LcdFlags textFlags) :
|
||||
Button(parent, rect, std::move(pressHandler), windowFlags, textFlags, &textButtonFactory),
|
||||
std::function<uint8_t(void)> pressHandler,
|
||||
WindowFlags windowFlags, LcdFlags textFlags) :
|
||||
Button(parent, rect, std::move(pressHandler), windowFlags, textFlags,
|
||||
lv_btn_create),
|
||||
text(std::move(text))
|
||||
{
|
||||
setTextFlags(textFlags | COLOR_THEME_PRIMARY1);
|
||||
@@ -97,25 +96,37 @@ TextButton::TextButton(FormGroup* parent, const rect_t& rect, std::string text,
|
||||
|
||||
lv_style_init(&style_btn);
|
||||
lv_style_set_radius(&style_btn, 0);
|
||||
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY2), LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_ACTIVE), LV_PART_MAIN | LV_STATE_CHECKED);
|
||||
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_ACTIVE), LV_PART_MAIN | LV_STATE_CHECKED | LV_STATE_FOCUSED);
|
||||
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_FOCUS), LV_PART_MAIN | LV_STATE_FOCUSED);
|
||||
|
||||
//TODO: use 'style_btn' instead of local style
|
||||
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY2),
|
||||
LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_ACTIVE),
|
||||
LV_PART_MAIN | LV_STATE_CHECKED);
|
||||
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_ACTIVE),
|
||||
LV_PART_MAIN | LV_STATE_CHECKED | LV_STATE_FOCUSED);
|
||||
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_FOCUS),
|
||||
LV_PART_MAIN | LV_STATE_FOCUSED);
|
||||
lv_obj_set_style_bg_opa(lvobj, LV_OPA_100, LV_PART_MAIN);
|
||||
lv_obj_set_style_border_width(lvobj, 0, LV_PART_MAIN);
|
||||
|
||||
lv_obj_set_style_border_width(lvobj, 1, LV_PART_MAIN | LV_STATE_CHECKED | LV_STATE_FOCUSED);
|
||||
lv_obj_set_style_border_color(lvobj, makeLvColor(COLOR_THEME_FOCUS), LV_PART_MAIN | LV_STATE_CHECKED | LV_STATE_FOCUSED);
|
||||
|
||||
lv_obj_set_style_text_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2), LV_PART_MAIN | LV_STATE_FOCUSED);
|
||||
lv_obj_set_style_border_width(
|
||||
lvobj, 1, LV_PART_MAIN | LV_STATE_CHECKED | LV_STATE_FOCUSED);
|
||||
lv_obj_set_style_border_color(
|
||||
lvobj, makeLvColor(COLOR_THEME_FOCUS),
|
||||
LV_PART_MAIN | LV_STATE_CHECKED | LV_STATE_FOCUSED);
|
||||
|
||||
lv_obj_add_style(lvobj, &style_btn,0);
|
||||
lv_obj_set_style_text_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2),
|
||||
LV_PART_MAIN | LV_STATE_FOCUSED);
|
||||
|
||||
lv_obj_add_style(lvobj, &style_btn, 0);
|
||||
|
||||
label = lv_label_create(lvobj);
|
||||
lv_label_set_text(label, this->text.c_str());
|
||||
lv_obj_center(label);
|
||||
lv_obj_set_style_text_color(label, makeLvColor(this->getTextFlags()), LV_PART_MAIN);
|
||||
lv_obj_set_style_text_color(label, makeLvColor(COLOR_THEME_PRIMARY2), LV_PART_MAIN | LV_STATE_FOCUSED);
|
||||
lv_obj_set_style_text_color(label, makeLvColor(this->getTextFlags()),
|
||||
LV_PART_MAIN);
|
||||
lv_obj_set_style_text_color(label, makeLvColor(COLOR_THEME_PRIMARY2),
|
||||
LV_PART_MAIN | LV_STATE_FOCUSED);
|
||||
}
|
||||
|
||||
void IconButton::paint(BitmapBuffer * dc)
|
||||
|
||||
+9
-8
@@ -28,14 +28,15 @@ constexpr WindowFlags BUTTON_CHECKED_ON_FOCUS = FORM_FLAGS_LAST << 3u;
|
||||
class Button: public FormField
|
||||
{
|
||||
public:
|
||||
Button(FormGroup* parent, const rect_t& rect,
|
||||
std::function<uint8_t(void)> pressHandler = nullptr,
|
||||
WindowFlags windowFlags = 0, LcdFlags textFlags = 0, LvglWidgetFactory *factory = nullptr) :
|
||||
FormField(parent, rect, windowFlags, textFlags, factory),
|
||||
pressHandler(std::move(pressHandler))
|
||||
{
|
||||
lv_obj_set_style_bg_opa(lvobj, LV_OPA_TRANSP, LV_PART_MAIN);
|
||||
}
|
||||
Button(FormGroup* parent, const rect_t& rect,
|
||||
std::function<uint8_t(void)> pressHandler = nullptr,
|
||||
WindowFlags windowFlags = 0, LcdFlags textFlags = 0,
|
||||
LvglCreate objConstruct = nullptr) :
|
||||
FormField(parent, rect, windowFlags, textFlags, objConstruct),
|
||||
pressHandler(std::move(pressHandler))
|
||||
{
|
||||
lv_obj_set_style_bg_opa(lvobj, LV_OPA_TRANSP, LV_PART_MAIN);
|
||||
}
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override
|
||||
|
||||
+21
-17
@@ -20,25 +20,22 @@
|
||||
#include "checkbox.h"
|
||||
#include "theme.h"
|
||||
|
||||
LvglWidgetFactory checkBoxFactory = { lv_checkbox_create, nullptr };
|
||||
lv_style_t style_indicator;
|
||||
lv_style_t style_edit;
|
||||
|
||||
|
||||
static void checkbox_event_handler(lv_event_t * e)
|
||||
static void checkbox_event_handler(lv_event_t* e)
|
||||
{
|
||||
lv_obj_t * target = lv_event_get_target(e);
|
||||
CheckBox* cb = (CheckBox *)lv_obj_get_user_data(target);
|
||||
|
||||
lv_obj_t* target = lv_event_get_target(e);
|
||||
CheckBox* cb = (CheckBox*)lv_obj_get_user_data(target);
|
||||
|
||||
onKeyPress();
|
||||
if (cb)
|
||||
cb->setValue(lv_obj_get_state(target) & LV_STATE_CHECKED);
|
||||
if (cb) cb->setValue(lv_obj_get_state(target) & LV_STATE_CHECKED);
|
||||
}
|
||||
|
||||
CheckBox::CheckBox(Window* parent, const rect_t& rect,
|
||||
std::function<uint8_t()> getValue,
|
||||
std::function<void(uint8_t)> setValue, WindowFlags flags) :
|
||||
FormField(parent, rect, flags, 0, &checkBoxFactory),
|
||||
FormField(parent, rect, flags, 0, lv_checkbox_create),
|
||||
_getValue(std::move(getValue)),
|
||||
_setValue(std::move(setValue))
|
||||
{
|
||||
@@ -46,23 +43,30 @@ CheckBox::CheckBox(Window* parent, const rect_t& rect,
|
||||
setWidth(size);
|
||||
setHeight(size);
|
||||
|
||||
//TODO: migrate to default theme
|
||||
|
||||
// BORDER
|
||||
lv_obj_set_style_border_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY2), LV_PART_INDICATOR);
|
||||
lv_obj_set_style_border_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY2),
|
||||
LV_PART_INDICATOR);
|
||||
lv_obj_set_style_border_width(lvobj, 1, LV_PART_INDICATOR);
|
||||
|
||||
lv_obj_set_style_border_color(lvobj, makeLvColor(COLOR_THEME_FOCUS), LV_PART_INDICATOR | LV_STATE_FOCUSED);
|
||||
lv_obj_set_style_border_color(lvobj, makeLvColor(COLOR_THEME_FOCUS),
|
||||
LV_PART_INDICATOR | LV_STATE_FOCUSED);
|
||||
lv_obj_set_style_border_width(lvobj, 2, LV_PART_INDICATOR | LV_STATE_FOCUSED);
|
||||
|
||||
// UNCHECKED BACKGROUND
|
||||
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2), LV_PART_INDICATOR);
|
||||
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2), LV_PART_INDICATOR | LV_STATE_CHECKED);
|
||||
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2),
|
||||
LV_PART_INDICATOR);
|
||||
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2),
|
||||
LV_PART_INDICATOR | LV_STATE_CHECKED);
|
||||
|
||||
lv_obj_set_style_text_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY1), LV_PART_INDICATOR | LV_STATE_CHECKED);
|
||||
lv_obj_set_style_text_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY1),
|
||||
LV_PART_INDICATOR | LV_STATE_CHECKED);
|
||||
|
||||
if (_getValue())
|
||||
lv_obj_add_state(lvobj, LV_STATE_CHECKED);
|
||||
if (_getValue()) lv_obj_add_state(lvobj, LV_STATE_CHECKED);
|
||||
|
||||
lv_obj_add_event_cb(lvobj, checkbox_event_handler, LV_EVENT_VALUE_CHANGED, this);
|
||||
lv_obj_add_event_cb(lvobj, checkbox_event_handler, LV_EVENT_VALUE_CHANGED,
|
||||
this);
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
|
||||
+4
-4
@@ -27,8 +27,8 @@ static lv_style_t edit_style;
|
||||
|
||||
FormField::FormField(Window* parent, const rect_t& rect,
|
||||
WindowFlags windowFlags, LcdFlags textFlags,
|
||||
LvglWidgetFactory* factory) :
|
||||
Window(parent, rect, windowFlags, textFlags, factory)
|
||||
LvglCreate objConstruct) :
|
||||
Window(parent, rect, windowFlags, textFlags, objConstruct)
|
||||
{
|
||||
if (!(windowFlags & NO_FOCUS)) {
|
||||
auto* form = dynamic_cast<FormGroup*>(parent);
|
||||
@@ -113,8 +113,8 @@ static lv_style_t border_style;
|
||||
static lv_style_t focus_border_style;
|
||||
|
||||
FormGroup::FormGroup(Window* parent, const rect_t& rect,
|
||||
WindowFlags windowflags, LvglWidgetFactory* factory) :
|
||||
FormField(parent, rect, windowflags)
|
||||
WindowFlags windowflags, LvglCreate objConstruct) :
|
||||
FormField(parent, rect, windowflags, 0, objConstruct)
|
||||
{
|
||||
lv_obj_set_style_bg_opa(lvobj, LV_OPA_TRANSP, LV_PART_MAIN);
|
||||
|
||||
|
||||
+4
-4
@@ -31,7 +31,7 @@ class FormField : public Window
|
||||
{
|
||||
public:
|
||||
FormField(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0,
|
||||
LcdFlags textFlags = 0, LvglWidgetFactory *factory = nullptr);
|
||||
LcdFlags textFlags = 0, LvglCreate objConstruct = nullptr);
|
||||
|
||||
virtual void changeEnd(bool forceChanged = false)
|
||||
{
|
||||
@@ -118,7 +118,7 @@ class FormGroup : public FormField
|
||||
{
|
||||
public:
|
||||
FormGroup(Window *parent, const rect_t &rect, WindowFlags windowflags = 0,
|
||||
LvglWidgetFactory *factory = nullptr);
|
||||
LvglCreate objConstruct = nullptr);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override { return "FormGroup"; }
|
||||
@@ -180,8 +180,8 @@ class FormWindow : public FormGroup
|
||||
{
|
||||
public:
|
||||
FormWindow(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0,
|
||||
LvglWidgetFactory *factory = nullptr) :
|
||||
FormGroup(parent, rect, windowFlags, factory)
|
||||
LvglCreate objConstruct = nullptr) :
|
||||
FormGroup(parent, rect, windowFlags, objConstruct)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
+1
-5
@@ -21,10 +21,6 @@
|
||||
#include "font.h"
|
||||
#include "theme.h"
|
||||
|
||||
LvglWidgetFactory menuBodyWidgetFactory = { [] (lv_obj_t *parent) {
|
||||
return lv_list_create(parent);
|
||||
}, nullptr};
|
||||
|
||||
void menuBodyEventCallback(lv_event_t *e)
|
||||
{
|
||||
auto code = lv_event_get_code(e);
|
||||
@@ -53,7 +49,7 @@ void menuBodyEventCallback(lv_event_t *e)
|
||||
}
|
||||
|
||||
MenuBody::MenuBody(Window * parent, const rect_t & rect):
|
||||
Window(parent, rect, OPAQUE, 0, &menuBodyWidgetFactory)
|
||||
Window(parent, rect, OPAQUE, 0, lv_list_create)
|
||||
{
|
||||
setPageHeight(MENUS_LINE_HEIGHT);
|
||||
}
|
||||
|
||||
+1
-2
@@ -24,7 +24,6 @@
|
||||
#endif
|
||||
|
||||
|
||||
static LvglWidgetFactory numberEditFactory = { lv_textarea_create, nullptr };
|
||||
static lv_style_t style_main;
|
||||
static lv_style_t style_edit;
|
||||
|
||||
@@ -64,7 +63,7 @@ NumberEdit::NumberEdit(Window* parent, const rect_t& rect, int vmin, int vmax,
|
||||
WindowFlags windowFlags, LcdFlags textFlags) :
|
||||
BaseNumberEdit(parent, rect, vmin, vmax, std::move(getValue),
|
||||
std::move(setValue), windowFlags, textFlags,
|
||||
&numberEditFactory)
|
||||
lv_textarea_create)
|
||||
{
|
||||
// properties
|
||||
lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_OFF);
|
||||
|
||||
+1
-3
@@ -44,8 +44,6 @@ static lv_style_t style_knob;
|
||||
static lv_style_t style_focused;
|
||||
static lv_style_t style_edit;
|
||||
|
||||
static LvglWidgetFactory sliderFactory = { lv_slider_create, nullptr };
|
||||
|
||||
constexpr coord_t SLIDER_PADDING = 6;
|
||||
|
||||
Slider::Slider(Window* parent, const rect_t& rect, int32_t vmin, int32_t vmax,
|
||||
@@ -54,7 +52,7 @@ Slider::Slider(Window* parent, const rect_t& rect, int32_t vmin, int32_t vmax,
|
||||
FormField(parent,
|
||||
{rect.x + SLIDER_PADDING, rect.y + SLIDER_PADDING,
|
||||
rect.w - 2 * SLIDER_PADDING, rect.h - 2 * SLIDER_PADDING},
|
||||
0, 0, &sliderFactory),
|
||||
0, 0, lv_slider_create),
|
||||
vmin(vmin),
|
||||
vmax(vmax),
|
||||
_getValue(std::move(getValue)),
|
||||
|
||||
+1
-2
@@ -44,13 +44,12 @@
|
||||
|
||||
static lv_style_t style_main;
|
||||
static lv_style_t style_edit;
|
||||
static LvglWidgetFactory textEditFactory = { lv_textarea_create, nullptr };
|
||||
|
||||
TextEdit::TextEdit(Window *parent, const rect_t &rect, char *value,
|
||||
uint8_t length, LcdFlags windowFlags,
|
||||
const char *_extra_chars) :
|
||||
FormField(parent, {rect.x, rect.y, rect.w, rect.h - 2}, windowFlags, 0,
|
||||
&textEditFactory),
|
||||
lv_textarea_create),
|
||||
value(value),
|
||||
length(length)
|
||||
{
|
||||
|
||||
+3
-16
@@ -137,19 +137,8 @@ static void window_event_cb(lv_event_t * e)
|
||||
}
|
||||
}
|
||||
|
||||
LvglWidgetFactory windowFactory = LvglWidgetFactory(
|
||||
[] (lv_obj_t *parent) {
|
||||
return lv_obj_create(parent);
|
||||
},
|
||||
[] (LvglWidgetFactory *factory) {
|
||||
lv_style_set_pad_all(&factory->style, 0);
|
||||
lv_style_set_bg_opa(&factory->style, LV_OPA_TRANSP);
|
||||
lv_style_set_border_width(&factory->style, 0);
|
||||
lv_style_set_radius(&factory->style, 0);
|
||||
});
|
||||
|
||||
Window::Window(Window *parent, const rect_t &rect, WindowFlags windowFlags,
|
||||
LcdFlags textFlags, LvglWidgetFactory *factory) :
|
||||
LcdFlags textFlags, LvglCreate objConstruct) :
|
||||
parent(parent),
|
||||
rect(rect),
|
||||
innerWidth(rect.w),
|
||||
@@ -158,11 +147,9 @@ Window::Window(Window *parent, const rect_t &rect, WindowFlags windowFlags,
|
||||
textFlags(textFlags)
|
||||
{
|
||||
lv_obj_t *lvParent = parent != nullptr ? parent->lvobj : nullptr;
|
||||
lvobj = (factory == nullptr) ?
|
||||
windowFactory.construct(lvParent) :
|
||||
factory->construct(lvParent);
|
||||
lvobj = (objConstruct == nullptr) ? lv_obj_create(lvParent)
|
||||
: objConstruct(lvParent);
|
||||
|
||||
lv_obj_add_style(lvobj, &windowFactory.style, LV_PART_MAIN);
|
||||
lv_obj_set_pos(lvobj, rect.x, rect.y);
|
||||
lv_obj_set_size(lvobj, rect.w, rect.h);
|
||||
lv_obj_set_user_data(lvobj, this);
|
||||
|
||||
+5
-2
@@ -59,14 +59,17 @@ enum SetFocusFlag
|
||||
SET_FOCUS_FIRST
|
||||
};
|
||||
|
||||
typedef lv_obj_t *(*LvglCreate)(lv_obj_t *);
|
||||
|
||||
class Window
|
||||
{
|
||||
friend class GridLayout;
|
||||
|
||||
public:
|
||||
Window(Window * parent, const rect_t & rect, WindowFlags windowFlags = 0, LcdFlags textFlags = 0, LvglWidgetFactory *factory = nullptr);
|
||||
Window(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0,
|
||||
LcdFlags textFlags = 0, LvglCreate objConstruct = nullptr);
|
||||
|
||||
virtual ~Window();
|
||||
virtual ~Window();
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
virtual std::string getName() const
|
||||
|
||||
Reference in New Issue
Block a user