diff --git a/radio/src/thirdparty/libopenui/src/CMakeLists.txt b/radio/src/thirdparty/libopenui/src/CMakeLists.txt index 13b688369..6fb2a9cb2 100644 --- a/radio/src/thirdparty/libopenui/src/CMakeLists.txt +++ b/radio/src/thirdparty/libopenui/src/CMakeLists.txt @@ -38,6 +38,7 @@ set(LIBOPENUI_SRC # LVGL widgets widgets/window_base.c widgets/simple_btn.c + widgets/field_edit.c ) if(SOFTWARE_KEYBOARD) diff --git a/radio/src/thirdparty/libopenui/src/numberedit.cpp b/radio/src/thirdparty/libopenui/src/numberedit.cpp index 10f2af558..9f4ba582f 100644 --- a/radio/src/thirdparty/libopenui/src/numberedit.cpp +++ b/radio/src/thirdparty/libopenui/src/numberedit.cpp @@ -18,6 +18,7 @@ */ #include "numberedit.h" +#include "widgets/field_edit.h" #if defined(SOFTWARE_KEYBOARD) #include "keyboard_number.h" @@ -40,34 +41,13 @@ static void numberedit_cb(lv_event_t* e) } } -// create a new class for number edit so we can set the sytles differently if needed. -const lv_obj_class_t lv_numberedit_class = { - .base_class = &lv_obj_class, - .constructor_cb = lv_textarea_class.constructor_cb, - .destructor_cb = lv_textarea_class.destructor_cb, - .user_data = nullptr, - .event_cb = lv_textarea_class.event_cb, - .width_def = LV_DPI_DEF / 2, - .height_def = LV_SIZE_CONTENT, - .editable = LV_OBJ_CLASS_EDITABLE_TRUE, - .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, - .instance_size = sizeof(lv_textarea_t) -}; - -lv_obj_t *lv_numberedit_create(lv_obj_t *parent) -{ - lv_obj_t * obj = lv_obj_class_create_obj(&lv_numberedit_class, parent); - lv_obj_class_init_obj(obj); - return obj; -} - NumberEdit::NumberEdit(Window* parent, const rect_t& rect, int vmin, int vmax, std::function getValue, std::function setValue, WindowFlags windowFlags, LcdFlags textFlags) : BaseNumberEdit(parent, rect, vmin, vmax, std::move(getValue), std::move(setValue), windowFlags, textFlags, - lv_numberedit_create) + field_edit_create) { // properties lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_OFF); diff --git a/radio/src/thirdparty/libopenui/src/textedit.cpp b/radio/src/thirdparty/libopenui/src/textedit.cpp index 6bd890942..35d29c800 100644 --- a/radio/src/thirdparty/libopenui/src/textedit.cpp +++ b/radio/src/thirdparty/libopenui/src/textedit.cpp @@ -19,7 +19,10 @@ #include "textedit.h" #include "font.h" -#include "libopenui_config.h" + +#include "widgets/field_edit.h" + +// #include "libopenui_config.h" #if !defined(STR_EDIT) #define STR_EDIT "Edit" @@ -45,7 +48,7 @@ TextEdit::TextEdit(Window *parent, const rect_t &rect, char *value, uint8_t length, LcdFlags windowFlags, const char *_extra_chars) : FormField(parent, rect, windowFlags, 0, - lv_textarea_create), + field_edit_create), value(value), length(length) { diff --git a/radio/src/thirdparty/libopenui/src/widgets/field_edit.c b/radio/src/thirdparty/libopenui/src/widgets/field_edit.c new file mode 100644 index 000000000..6fb27d9fb --- /dev/null +++ b/radio/src/thirdparty/libopenui/src/widgets/field_edit.c @@ -0,0 +1,45 @@ +/* + * 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 "field_edit.h" + +#define MY_CLASS &field_edit_class + +static void field_edit_event(const lv_obj_class_t* class_p, lv_event_t* e) +{ + /* Call the ancestor's event handler */ + lv_obj_event_base(MY_CLASS, e); +} + +const lv_obj_class_t field_edit_class = { + .base_class = &lv_textarea_class, + .event_cb = field_edit_event, + .width_def = LV_DPI_DEF / 2, + .height_def = LV_SIZE_CONTENT, + .editable = LV_OBJ_CLASS_EDITABLE_TRUE, + .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, + .instance_size = sizeof(lv_textarea_t) +}; + +lv_obj_t* field_edit_create(lv_obj_t* parent) +{ + lv_obj_t* obj = lv_obj_class_create_obj(MY_CLASS, parent); + lv_obj_class_init_obj(obj); + return obj; +} diff --git a/radio/src/thirdparty/libopenui/src/widgets/field_edit.h b/radio/src/thirdparty/libopenui/src/widgets/field_edit.h new file mode 100644 index 000000000..7cf6d1f1b --- /dev/null +++ b/radio/src/thirdparty/libopenui/src/widgets/field_edit.h @@ -0,0 +1,36 @@ +/* + * 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 FIELD_EDIT_H +#define FIELD_EDIT_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern const lv_obj_class_t field_edit_class; +lv_obj_t* field_edit_create(lv_obj_t* parent); + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/radio/src/thirdparty/libopenui/src/widgets/number_edit.c b/radio/src/thirdparty/libopenui/src/widgets/number_edit.c new file mode 100644 index 000000000..19624a2fa --- /dev/null +++ b/radio/src/thirdparty/libopenui/src/widgets/number_edit.c @@ -0,0 +1,41 @@ +/* + * 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 "field_edit.h" + +#define MY_CLASS &field_edit_class + +const lv_obj_class_t field_edit_class = { + .base_class = &lv_obj_class, + .constructor_cb = lv_textarea_class.constructor_cb, + .destructor_cb = lv_textarea_class.destructor_cb, + .event_cb = lv_textarea_class.event_cb, + .width_def = LV_DPI_DEF / 2, + .height_def = LV_SIZE_CONTENT, + .editable = LV_OBJ_CLASS_EDITABLE_TRUE, + .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, + .instance_size = sizeof(lv_textarea_t) +}; + +lv_obj_t* field_edit_create(lv_obj_t* parent) +{ + lv_obj_t* obj = lv_obj_class_create_obj(MY_CLASS, parent); + lv_obj_class_init_obj(obj); + return obj; +} diff --git a/radio/src/thirdparty/libopenui/src/widgets/number_edit.h b/radio/src/thirdparty/libopenui/src/widgets/number_edit.h new file mode 100644 index 000000000..7cf6d1f1b --- /dev/null +++ b/radio/src/thirdparty/libopenui/src/widgets/number_edit.h @@ -0,0 +1,36 @@ +/* + * 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 FIELD_EDIT_H +#define FIELD_EDIT_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern const lv_obj_class_t field_edit_class; +lv_obj_t* field_edit_create(lv_obj_t* parent); + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/radio/src/thirdparty/libopenui/src/window.cpp b/radio/src/thirdparty/libopenui/src/window.cpp index 376627632..928897c89 100644 --- a/radio/src/thirdparty/libopenui/src/window.cpp +++ b/radio/src/thirdparty/libopenui/src/window.cpp @@ -117,12 +117,12 @@ extern "C" void window_event_cb(lv_event_t * e) lv_point_t* p = (lv_point_t*)lv_event_get_param(e); lv_coord_t scroll_bottom = lv_obj_get_scroll_bottom(target); - // TRACE("SCROLL[x=%d;y=%d;top=%d;bottom=%d]", p->x, p->y, - // scroll_y, scroll_bottom); + TRACE("SCROLL[x=%d;y=%d;top=%d;bottom=%d]", p->x, p->y, + scroll_y, scroll_bottom); - if (scroll_y <= lv_dpx(45) && p->y > 0) { + if (scroll_y <= 45 && p->y > 0) { lv_obj_scroll_by(target, 0, scroll_y, LV_ANIM_OFF); - } else if (scroll_bottom <= lv_dpx(16) && p->y < 0) { + } else if (scroll_bottom <= 16 && p->y < 0) { lv_obj_scroll_by(target, 0, -scroll_bottom, LV_ANIM_OFF); } }