chore(color): Libopenui refactor (#3614)

* Refactor object creation logic.
Remove unused LVGL features.

* Remove unused files.
Fix height for widgets.

* Rename 'OpenTxTheme' class to 'EdgeTxTheme'.
Cleanup commented out code.
Cleanup unused code from 'etx_lv_theme.cpp'.

* More cleanup.

* Move more style code to etx_lv_theme.cpp

* Update license

* Make default button height match other controls.

* Fix curve edit layout.

* Fix layouts.

* FormWindow and FormGroup provided identical functionality - rename FormGroup to FormWindow and remove duplicate.

* Simplify menu icon handling.
Remove unused 'flysky.cpp' file.

* Fix window size change.

* Simplify page header code.
Fix statistics view page.

* Remove unused file.
Replace redundant 'Subtitle' class with a macro.
Fix compiler warnings.

* Fix compiler warning in LvglWrapper.cpp.
Remove unused code in static.h.
Simplify about page.

* Rename ICON_OPENTX to ICON_EDGETX.

* Fix github build error.

* Fix github build error (attempt 2).

* Move ButtonMatrix styling to etx_lv_theme.cpp.

* Scroll bar consistency.

* Use styles for ButtonMatrix text color.

* Use 'active' color for selected USB advanced setup buttons. Move error message to bottom of page.

* Create style for popup window title bar.
Simplify advanced USB setup code.
Remove unused libopenui/carousel.* files.

* Add style for modal popup content.

* Remove unused BUTTON_BACKGROUND flag.

* Replace GridLayout with FormWindow. Remove unused gridlayout.h file.

* Fix rebase.

* Merge ChoiceEx class into Choice class code.
Remove unused CurveKeyboard.

* Use LVGL bar for progress indicator.
Update only style colors when theme changes (don't recreate all style settings).

* Move ProgressDialog class to dlalog.h/dialog.cpp files.

* Simplify trim and slider code in main view.
Simplify the hardware inputs code.
Fix dialog size.
Remove unused code in layout factory.

* Cleanup unused code.

* Add style for FormWindow class.
Merge BaseNumberEdit class into NumberEdit class and remove BaseNumberEdit.
Remove more unused files.
Cleanup libopenui_config.h files.

* Re-organise libopenui include files to fix build error.

* Fix build error.

* Add missed styles to etx_lv_theme.cpp.
Delete commented out #includes.
More cleaning up of libopenui_xxx.h files and dependencies.
Re-enable LVGL CHECKBOX feature.

* Merge libopenui_helpers.h into opentx_helpers.h file.

* Fix firmware build.

* Use object constructors for LVGL object creation as suggested by gagarinlg.
Add style for number edit text alignment.
Fix background color for focussed control.

* Move color related stuff from libopenui_defines.h to colors.h.
Remove need for libopenui_depends.h file.

* Merge libopenui_types.h content into opentx_types.h file.

* Rename CheckBox class to ToggleSwitch.

* Restore code to update flight mode text color when theme changes.

* Cleanup some more unused code.

* Remove redundant theme.h file.

* Fix rebase.

* Fix button matrix style.

* Fix rebase

* Fix rebase

* Ensure correct initialisation of Choice object.

* Fix rebase.

* Make the slider control bigger to make touch activation easier.

* Fix build error.

* Fix slider logic and cleanup code.

* Use ACTIVE theme color for inputs, mixes, LS, GV and SF.

* Improved border width consistency and focussed state consistency.

* Remove duplicate copy of the default theme colors.
This commit is contained in:
philmoz
2023-08-04 11:04:54 +10:00
committed by GitHub
parent c0df9e9c44
commit 69338ab0ab
231 changed files with 2178 additions and 5921 deletions
+1 -16
View File
@@ -15,14 +15,12 @@ set(LIBOPENUI_SRC
button.cpp
button_matrix.cpp
static.cpp
checkbox.cpp
carousel.cpp
toggleswitch.cpp
slider.cpp
mainwindow.cpp
menu.cpp
menutoolbar.cpp
choice.cpp
choiceex.cpp
filechoice.cpp
numberedit.cpp
textedit.cpp
@@ -33,11 +31,6 @@ set(LIBOPENUI_SRC
keyboard_text.cpp
keyboard_number.cpp
keyboard_base.cpp
# LVGL widgets
widgets/window_base.c
widgets/simple_btn.c
widgets/field_edit.c
widgets/edgetx_table.c
)
foreach(LIBOPENUI_FILE ${LIBOPENUI_SRC})
@@ -47,11 +40,3 @@ endforeach()
set(SRC ${SRC} ${LIBOPENUI_SRC_FILES}
${LIBOPENUI_SRC_DIR}/thirdparty/lz4/lz4.c
)
# add_library(libopenui_native OBJECT ${LIBOPENUI_SRC_FILES})
# add_library(libopenui_stm32 OBJECT ${LIBOPENUI_SRC_FILES})
# Dirty hack to include FatFs into libopenui
# TODO: this must go away
#target_include_directories(libopenui PRIVATE
# ${CMAKE_CURRENT_SOURCE_DIR}/../../FatFs)
-222
View File
@@ -1,222 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#pragma once
#include "form.h"
#include "strhelpers.h"
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,
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)
{
vmin = value;
}
void setMax(int value)
{
vmax = value;
}
void setDefault(int value)
{
vdefault = value;
}
int32_t getMin() const
{
return vmin;
}
int32_t getMax() const
{
return vmax;
}
int32_t getDefault() const
{
return vdefault;
}
void setStep(int value)
{
step = value;
}
int32_t getStep() const
{
return step;
}
void setFastStep(int value)
{
fastStep = value;
}
int32_t getFastStep() const
{
return fastStep;
}
void setAccelFactor(int value)
{
accelFactor = value;
}
int32_t getAccelFactor() const
{
return accelFactor;
}
void setValue(int value)
{
auto newValue = limit(vmin, value, vmax);
if (newValue != currentValue) {
currentValue = newValue;
if (instantChange && _setValue != nullptr) {
_setValue(currentValue);
}
}
if (lvobj != nullptr) {
std::string str;
if (displayFunction != nullptr) {
str = displayFunction(currentValue);
} else {
str = formatNumberAsString(currentValue, textFlags, 0, prefix.c_str(),
suffix.c_str());
}
lv_textarea_set_text(lvobj, str.c_str());
}
}
void setPrefix(std::string value)
{
prefix = std::move(value);
update();
}
void setSuffix(std::string value)
{
suffix = std::move(value);
update();
}
void setZeroText(std::string value)
{
zeroText = std::move(value);
update();
}
void enableInstantChange(bool value)
{
instantChange = value;
}
void disableInstantChange()
{
enableInstantChange(false);
}
void setSetValueHandler(std::function<void(int)> handler)
{
_setValue = std::move(handler);
}
void setGetValueHandler(std::function<int()> handler)
{
_getValue = std::move(handler);
}
int32_t getValue() const
{
return (editMode && !instantChange) ? currentValue
: _getValue != nullptr ? _getValue()
: 0;
}
void setEditMode(bool newEditMode) override
{
auto previousEditMode = editMode;
FormField::setEditMode(newEditMode);
if (!instantChange) {
if (!previousEditMode && newEditMode) {
if (_getValue != nullptr) currentValue = _getValue();
}
else if (previousEditMode && !newEditMode) {
if (_setValue != nullptr) _setValue(currentValue);
}
}
}
void setDisplayHandler(std::function<std::string(int value)> function)
{
displayFunction = std::move(function);
update();
}
virtual void update()
{
if (_getValue == nullptr) return;
auto newValue = _getValue();
if (newValue != currentValue) {
currentValue = newValue;
}
if (lvobj != nullptr) {
std::string str;
if (displayFunction != nullptr) {
str = displayFunction(currentValue);
} else {
str = formatNumberAsString(currentValue, textFlags, 0, prefix.c_str(),
suffix.c_str());
}
lv_textarea_set_text(lvobj, str.c_str());
}
}
virtual void paint(BitmapBuffer* dc) override {};
protected:
int vdefault = 0;
int vmin;
int vmax;
int step = 1;
int fastStep = 10;
int accelFactor = 4;
int currentValue;
bool instantChange = true;
std::string prefix;
std::string suffix;
std::string zeroText;
std::function<int()> _getValue;
std::function<void(int)> _setValue;
std::function<std::string(int)> displayFunction;
};
+2 -2
View File
@@ -19,9 +19,9 @@
#include <math.h>
#include <string.h>
#include "board.h"
#include "bitmapbuffer.h"
#include "libopenui_depends.h"
#include "libopenui_helpers.h"
#include "opentx_helpers.h"
#include "libopenui_file.h"
#include "font.h"
+2 -3
View File
@@ -21,10 +21,9 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "libopenui_types.h"
#include "opentx_types.h"
#include "libopenui_defines.h"
#include "libopenui_depends.h"
#include "libopenui_helpers.h"
#include "opentx_helpers.h"
#include "debug.h"
constexpr uint8_t SOLID = 0xFF;
-123
View File
@@ -1,123 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#pragma once
#include "window.h"
template <class T>
class BufferedWindow: public T
{
public:
using T::T;
~BufferedWindow() override
{
delete bitmap;
}
void invalidate(const rect_t & rect) override
{
paintUpdateNeeded = true;
T::invalidate(rect);
}
protected:
BitmapBuffer * bitmap = nullptr;
bool paintUpdateNeeded = false;
virtual void paintUpdate(BitmapBuffer * dc) = 0;
};
template <class T>
class OpaqueBufferedWindow: public BufferedWindow<T>
{
public:
using BufferedWindow<T>::BufferedWindow;
void paint(BitmapBuffer * dc) override
{
if (!this->bitmap) {
this->bitmap = new BitmapBuffer(BMP_RGB565, T::width(), T::height());
this->paintUpdateNeeded = true;
}
if (this->paintUpdateNeeded) {
this->paintUpdate(this->bitmap);
this->paintUpdateNeeded = false;
}
dc->drawBitmap(0, 0, this->bitmap);
}
};
template <class T>
class TransparentBufferedWindow: public BufferedWindow<T>
{
public:
using BufferedWindow<T>::BufferedWindow;
void paint(BitmapBuffer * dc) override
{
if (!BufferedWindow<T>::bitmap) {
this->bitmap = new BitmapBuffer(BMP_RGB565, T::width(), T::height());
this->paintUpdateNeeded = true;
}
if (this->paintUpdateNeeded) {
this->paintUpdate(dc);
// we can only store the bitmap if fully drawn
coord_t xmin, xmax, ymin, ymax;
dc->getClippingRect(xmin, xmax, ymin, ymax);
if (xmax - xmin >= this->width() && ymax - ymin >= this->height()) {
this->bitmap->drawBitmap(0, 0, dc, dc->getOffsetX(), dc->getOffsetY());
this->paintUpdateNeeded = false;
}
}
else {
dc->drawBitmap(0, 0, this->bitmap);
}
}
};
class TransparentBitmapBackground: public TransparentBufferedWindow<Window>
{
public:
TransparentBitmapBackground(Window * parent, const rect_t & rect, const BitmapBuffer * bitmap):
TransparentBufferedWindow<Window>(parent, rect, OPAQUE),
background(bitmap)
{
}
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "TransparentBitmapBackground";
}
#endif
protected:
const BitmapBuffer * background;
void paintUpdate(BitmapBuffer * dc) override
{
if (background) {
dc->drawBitmap((width() - background->width()) / 2, (height() - background->height()) / 2, background);
}
}
};
+3 -14
View File
@@ -16,13 +16,10 @@
* GNU General Public License for more details.
*/
#include "libopenui_config.h"
#include "button.h"
#include "font.h"
#include "theme.h"
#include "widgets/simple_btn.h"
static void update_checked_flag(lv_obj_t* obj, WindowFlags flags)
{
if (!(flags & BUTTON_CHECKED))
@@ -36,7 +33,7 @@ Button::Button(Window* parent, const rect_t& rect,
WindowFlags windowFlag, LcdFlags textFlags,
LvglCreate objConstruct) :
FormField(parent, rect, windowFlag, textFlags,
objConstruct ? objConstruct : simple_btn_create),
objConstruct ? objConstruct : lv_btn_create),
pressHandler(std::move(pressHandler))
{
lv_obj_add_event_cb(lvobj, Button::long_pressed, LV_EVENT_LONG_PRESSED, nullptr);
@@ -55,10 +52,7 @@ void Button::check(bool checked)
bool Button::checked() const
{
if (windowFlags & BUTTON_CHECKED_ON_FOCUS)
return hasFocus();
else
return windowFlags & BUTTON_CHECKED;
return windowFlags & BUTTON_CHECKED;
}
void Button::onPress()
@@ -102,7 +96,7 @@ void Button::long_pressed(lv_event_t* e)
TextButton::TextButton(Window* parent, const rect_t& rect, std::string text,
std::function<uint8_t(void)> pressHandler,
WindowFlags windowFlags) :
Button(parent, rect, std::move(pressHandler), windowFlags, 0, lv_btn_create),
Button(parent, rect, std::move(pressHandler), windowFlags, 0, etx_button_create),
text(std::move(text))
{
update_checked_flag(lvobj, windowFlags);
@@ -111,8 +105,3 @@ TextButton::TextButton(Window* parent, const rect_t& rect, std::string text,
lv_label_set_text(label, this->text.c_str());
lv_obj_center(label);
}
void IconButton::paint(BitmapBuffer * dc)
{
dc->drawBitmap(0, 0, theme->getIcon(icon, checked() ? STATE_PRESSED : STATE_DEFAULT));
}
+2 -27
View File
@@ -20,9 +20,7 @@
#include "form.h"
constexpr WindowFlags BUTTON_BACKGROUND = FORM_FLAGS_LAST << 1u;
constexpr WindowFlags BUTTON_CHECKED = FORM_FLAGS_LAST << 2u;
constexpr WindowFlags BUTTON_CHECKED_ON_FOCUS = FORM_FLAGS_LAST << 3u;
constexpr WindowFlags BUTTON_CHECKED = WINDOW_FLAGS_LAST << 1u;
class Button : public FormField
{
@@ -77,7 +75,7 @@ class TextButton: public Button
public:
TextButton(Window* parent, const rect_t& rect, std::string text,
std::function<uint8_t(void)> pressHandler = nullptr,
WindowFlags windowFlags = BUTTON_BACKGROUND | OPAQUE);
WindowFlags windowFlags = OPAQUE);
#if defined(DEBUG_WINDOWS)
std::string getName() const override
@@ -105,26 +103,3 @@ class TextButton: public Button
std::string text;
std::function<LcdFlags(void)> bgColorHandler = nullptr;
};
class IconButton: public Button
{
public:
IconButton(Window* parent, const rect_t& rect, uint8_t icon,
std::function<uint8_t(void)> pressHandler,
WindowFlags flags = 0) :
Button(parent, rect, std::move(pressHandler), flags), icon(icon)
{
}
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "IconButton(" + std::to_string(icon) + ")";
}
#endif
void paint(BitmapBuffer * dc) override;
protected:
uint8_t icon;
};
+13 -25
View File
@@ -31,43 +31,23 @@ static void btn_matrix_event(lv_event_t *e)
if (code == LV_EVENT_VALUE_CHANGED) {
lv_obj_t* obj = lv_event_get_target(e);
auto btn_id = (uint32_t *)lv_event_get_param(e);
auto btn_id = *((uint8_t *)lv_event_get_param(e));
auto btnm = (ButtonMatrix*)lv_event_get_user_data(e);
bool edited = lv_obj_has_state(obj, LV_STATE_EDITED);
bool is_pointer = lv_indev_get_type(lv_indev_get_act()) == LV_INDEV_TYPE_POINTER;
if (edited || is_pointer)
btnm->onPress((uint8_t)*btn_id);
}
else if (code == LV_EVENT_DRAW_PART_BEGIN) {
lv_obj_draw_part_dsc_t* dsc = lv_event_get_draw_part_dsc(e);
if (dsc->part == LV_PART_ITEMS) {
auto btnm = (ButtonMatrix*)lv_event_get_user_data(e);
if (btnm->isActive((uint8_t)dsc->id)) {
dsc->rect_dsc->bg_color = makeLvColor(COLOR_THEME_ACTIVE);
dsc->label_dsc->color = makeLvColor(COLOR_THEME_PRIMARY2);
} else {
dsc->rect_dsc->bg_color = makeLvColor(COLOR_THEME_PRIMARY2);
dsc->label_dsc->color = makeLvColor(COLOR_THEME_SECONDARY1);
}
} else if (dsc->part == LV_PART_MAIN) {
lv_obj_t* obj = lv_event_get_target(e);
if (lv_obj_has_state(obj, LV_STATE_FOCUS_KEY) &&
!lv_obj_has_state(obj, LV_STATE_EDITED)) {
dsc->rect_dsc->bg_color = makeLvColor(COLOR_THEME_FOCUS);
dsc->rect_dsc->bg_opa = LV_OPA_20;
}
if (edited || is_pointer) {
btnm->onPress(btn_id);
}
}
}
ButtonMatrix::ButtonMatrix(Window* parent, const rect_t& r) :
FormField(parent, r, 0, 0, lv_btnmatrix_create)
FormField(parent, r, 0, 0, etx_btnmatrix_create)
{
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICK_FOCUSABLE);
lv_obj_add_event_cb(lvobj, btn_matrix_event, LV_EVENT_ALL, this);
}
@@ -145,3 +125,11 @@ void ButtonMatrix::onClicked()
lv_group_focus_obj(lvobj);
FormField::onClicked();
}
void ButtonMatrix::setChecked(uint8_t btn_id)
{
if (isActive(btn_id))
lv_btnmatrix_set_btn_ctrl(lvobj, btn_id, LV_BTNMATRIX_CTRL_CHECKED);
else
lv_btnmatrix_clear_btn_ctrl(lvobj, btn_id, LV_BTNMATRIX_CTRL_CHECKED);
}
+18 -17
View File
@@ -22,23 +22,24 @@
class ButtonMatrix : public FormField
{
char** lv_btnm_map = nullptr;
uint8_t* txt_index = nullptr;
uint8_t txt_cnt = 0;
uint8_t btn_cnt = 0;
char** lv_btnm_map = nullptr;
uint8_t* txt_index = nullptr;
uint8_t txt_cnt = 0;
uint8_t btn_cnt = 0;
public:
ButtonMatrix(Window* parent, const rect_t& rect);
~ButtonMatrix();
virtual void onPress(uint8_t btn_id) {}
virtual bool isActive(uint8_t btn_id) { return false; }
protected:
void deallocate();
void initBtnMap(uint8_t cols, uint8_t btns);
void setText(uint8_t btn_id, const char* txt);
void update();
public:
ButtonMatrix(Window* parent, const rect_t& rect);
~ButtonMatrix();
void onClicked() override;
virtual void onPress(uint8_t btn_id) {}
virtual bool isActive(uint8_t btn_id) { return false; }
protected:
void deallocate();
void initBtnMap(uint8_t cols, uint8_t btns);
void setText(uint8_t btn_id, const char* txt);
void setChecked(uint8_t btn_id);
void update();
void onClicked() override;
};
-67
View File
@@ -1,67 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#include "carousel.h"
void CarouselWindow::update()
{
auto first = min<int>(selection - 2, items.size() - count);
first = max(0, first);
coord_t lastPosition = 0;
coord_t spacing = 10;
if (!items.empty() && count > 0)
spacing = (width() - items[0]->back->width() * (count - 1) - items[0]->front->width()) / (count - 1);
int index = 0;
for (auto & item: items) {
Window * window;
if (index == selection) {
item->back->detach();
window = item->front;
}
else {
item->front->detach();
window = item->back;
}
window->attach(this);
window->setLeft(lastPosition);
window->setTop((height() - window->height()) / 2);
lastPosition += window->width() + spacing;
index += 1;
}
}
#if defined(HARDWARE_KEYS)
void Carousel::onEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
if (event == EVT_ROTARY_RIGHT) {
if (body->selection < (int)body->items.size() - 1)
select(body->selection + 1);
}
else if (event == EVT_ROTARY_LEFT) {
if (body->selection > 0)
select(body->selection - 1);
}
else {
Window::onEvent(event);
}
}
#endif
-150
View File
@@ -1,150 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#pragma once
#include <vector>
#include "button.h"
class CarouselItem
{
public:
CarouselItem(Window * front, Window * back):
front(front),
back(back)
{
}
void setSelectHandler(std::function<void()> handler)
{
selectHandler = std::move(handler);
}
virtual ~CarouselItem() = default;
public:
Window * front;
Window * back;
std::function<void()> selectHandler;
};
class CarouselWindow: public Window
{
friend class Carousel;
public:
CarouselWindow(Window * parent, const rect_t & rect, uint8_t count):
Window(parent, rect, NO_SCROLLBAR),
count(count)
{
}
void deleteLater(bool detach = true, bool trash = true) override // NOLINT(google-default-arguments)
{
if (_deleted)
return;
clear();
Window::deleteLater(detach, trash);
}
void addItem(CarouselItem * item)
{
items.push_back(item);
update();
}
void clear()
{
// children will be deleted later (front and back)
children.clear();
for (auto & item: items) {
item->front->deleteLater();
item->back->deleteLater();
delete item;
}
items.clear();
}
void select(int index, bool scroll = true)
{
selection = index;
if (selection >= 0) {
auto item = items[selection];
if (item->selectHandler) {
item->selectHandler();
}
}
update();
}
protected:
std::vector<CarouselItem *> items;
int selection = 0;
unsigned count;
void update();
};
class Carousel: public Window
{
public:
Carousel(Window * parent, const rect_t & rect):
Window(parent, rect, NO_SCROLLBAR)
{
}
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "Carousel";
}
#endif
void addItem(CarouselItem * item)
{
body->addItem(item);
}
void clear()
{
body->clear();
}
void select(int index)
{
body->select(index);
previousButton->enable(index > 0);
nextButton->enable(index < (int)body->items.size() - 1);
}
int getSelection() const
{
return body->selection;
}
#if defined(HARDWARE_KEYS)
void onEvent(event_t event) override;
#endif
protected:
Button * previousButton = nullptr;
Button * nextButton = nullptr;
CarouselWindow * body = nullptr;
};
+34 -27
View File
@@ -38,20 +38,14 @@ void choice_changed_cb(lv_event_t *e)
ChoiceBase::ChoiceBase(Window* parent, const rect_t& rect, ChoiceType type,
WindowFlags windowFlags) :
FormField(parent, rect, windowFlags), type(type)
FormField(parent, rect, windowFlags, 0, etx_choice_create),
type(type)
{
lv_obj_set_height(lvobj, LV_SIZE_CONTENT);
lv_obj_set_width(lvobj, LV_SIZE_CONTENT);
// lv_obj_set_height(lvobj, LV_SIZE_CONTENT);
// lv_obj_set_width(lvobj, LV_SIZE_CONTENT);
lv_obj_set_layout(lvobj, LV_LAYOUT_FLEX);
lv_obj_set_flex_flow(lvobj, LV_FLEX_FLOW_ROW);
if (height() == 0)
{
lv_obj_set_style_pad_top(lvobj, 4, LV_PART_MAIN);
lv_obj_set_style_pad_bottom(lvobj, 4, LV_PART_MAIN);
lv_obj_set_style_radius(lvobj, 4, LV_PART_MAIN);
}
lv_obj_add_event_cb(lvobj, choice_changed_cb, LV_EVENT_VALUE_CHANGED, lvobj);
label = lv_label_create(lvobj);
@@ -60,18 +54,6 @@ ChoiceBase::ChoiceBase(Window* parent, const rect_t& rect, ChoiceType type,
lv_group_add_obj(def_group, lvobj);
}
// Normal font and background color
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2), LV_PART_MAIN);
lv_obj_set_style_bg_opa(lvobj, LV_OPA_100, LV_PART_MAIN);
lv_obj_set_style_pad_right(lvobj, 5, LV_PART_MAIN);
lv_obj_set_style_border_width(lvobj, 1, LV_PART_MAIN);
lv_obj_set_style_border_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY2), LV_PART_MAIN);
lv_obj_set_style_text_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY1), LV_PART_MAIN);
// focused
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_FOCUS), LV_PART_MAIN | LV_STATE_FOCUSED);
lv_obj_set_style_text_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2), LV_PART_MAIN | LV_STATE_FOCUSED);
lv_obj_set_style_pad_left(label, FIELD_PADDING_LEFT, LV_PART_MAIN);
lv_obj_set_style_pad_top(label, FIELD_PADDING_TOP, LV_PART_MAIN);
lv_obj_set_style_pad_right(label, CHOICE_LABEL_MARGIN_RIGHT, LV_PART_MAIN);
@@ -107,7 +89,8 @@ Choice::Choice(Window* parent, const rect_t& rect, int vmin, int vmax,
vmin(vmin),
vmax(vmax),
_getValue(std::move(_getValue)),
_setValue(std::move(_setValue))
_setValue(std::move(_setValue)),
longPressData({})
{
lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr);
}
@@ -119,7 +102,8 @@ Choice::Choice(Window* parent, const rect_t& rect, const char* const values[],
vmin(vmin),
vmax(vmax),
_getValue(std::move(_getValue)),
_setValue(std::move(_setValue))
_setValue(std::move(_setValue)),
longPressData({})
{
setValues(values);
lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr);
@@ -134,7 +118,8 @@ Choice::Choice(Window* parent, const rect_t& rect,
vmin(vmin),
vmax(vmax),
_getValue(std::move(_getValue)),
_setValue(std::move(_setValue))
_setValue(std::move(_setValue)),
longPressData({})
{
lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr);
}
@@ -146,7 +131,8 @@ Choice::Choice(Window* parent, const rect_t& rect, const char* values, int vmin,
vmin(vmin),
vmax(vmax),
_getValue(std::move(_getValue)),
_setValue(std::move(_setValue))
_setValue(std::move(_setValue)),
longPressData({})
{
if (values) {
uint8_t len = values[0];
@@ -200,7 +186,8 @@ void Choice::setValue(int val)
void Choice::onClicked()
{
openMenu();
if (!longPressData.isLongPressed)
openMenu();
}
void Choice::fillMenu(Menu *menu, const FilterFct& filter)
@@ -242,3 +229,23 @@ void Choice::openMenu()
menu->setCloseHandler([=]() { setEditMode(false); });
}
static void localLongPressHandler(lv_event_t* e)
{
lv_eventData_t* ld = (lv_eventData_t*)lv_event_get_user_data(e);
ld->isLongPressed = true;
ld->lv_LongPressHandler(ld->userData);
}
void Choice::set_lv_LongPressHandler(lvHandler_t longPressHandler, void* data)
{
TRACE("longPressHandler=%p", longPressHandler);
if (longPressHandler) {
longPressData.userData = data;
longPressData.lv_LongPressHandler = longPressHandler;
lv_obj_add_event_cb(lvobj, localLongPressHandler, LV_EVENT_LONG_PRESSED,
&longPressData);
lv_obj_add_event_cb(lvobj, ClickHandler, LV_EVENT_CLICKED, this);
}
}
+20 -3
View File
@@ -21,6 +21,14 @@
#include <vector>
#include "form.h"
typedef void (*lvHandler_t)(void*);
typedef struct {
void* userData;
bool isLongPressed;
lvHandler_t lv_LongPressHandler;
} lv_eventData_t;
class Menu;
constexpr int CHOICE_LABEL_MARGIN_RIGHT = 10;
@@ -36,8 +44,6 @@ class ChoiceBase : public FormField
ChoiceBase(Window *parent, const rect_t &rect,
ChoiceType type = CHOICE_TYPE_DROPOWN,
WindowFlags windowFlags = 0);
inline ChoiceType getType() const { return type; }
protected:
ChoiceType type;
@@ -167,9 +173,11 @@ class Choice: public ChoiceBase {
invalidate();
}
void set_lv_LongPressHandler(lvHandler_t longPressHandler, void* data);
protected:
friend class MenuToolbar;
std::string getLabelText() override;
std::vector<std::string> values;
int vmin = 0;
@@ -185,4 +193,13 @@ class Choice: public ChoiceBase {
void fillMenu(Menu *menu, const FilterFct& filter = nullptr);
virtual void openMenu();
lv_eventData_t longPressData;
std::function<void(event_t)> longPressHandler = nullptr;
static void ClickHandler(lv_event_t* e)
{
auto ch = (Choice*)lv_event_get_user_data(e);
if (ch) ch->longPressData.isLongPressed = false;
}
};
-48
View File
@@ -1,48 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#include "choiceex.h"
static void localLongPressHandler(lv_event_t* e)
{
lv_eventData_t* ld = (lv_eventData_t*)lv_event_get_user_data(e);
ld->isLongPressed = true;
ld->lv_LongPressHandler(ld->userData);
}
void ChoiceEx::set_lv_LongPressHandler(lvHandler_t longPressHandler, void* data)
{
TRACE("longPressHandler=%p", longPressHandler);
if (longPressHandler) {
longPressData.userData = data;
longPressData.lv_LongPressHandler = longPressHandler;
lv_obj_add_event_cb(lvobj, localLongPressHandler, LV_EVENT_LONG_PRESSED,
&longPressData);
lv_obj_add_event_cb(lvobj, ClickHandler, LV_EVENT_CLICKED, this);
}
}
ChoiceEx::ChoiceEx(Window* parent, const rect_t& rect, int16_t vmin,
int16_t vmax, std::function<int16_t()> getValue,
std::function<void(int16_t)> setValue,
WindowFlags windowFlags) :
Choice(parent, rect, vmin, vmax, getValue, setValue, windowFlags)
{
longPressData.isLongPressed = false;
}
-55
View File
@@ -1,55 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#pragma once
#include "choice.h"
typedef void (*lvHandler_t)(void*);
typedef struct {
void* userData;
bool isLongPressed;
lvHandler_t lv_LongPressHandler;
} lv_eventData_t;
class ChoiceEx : public Choice
{
public:
ChoiceEx(Window* parent, const rect_t& rect, int16_t vmin, int16_t vmax,
std::function<int16_t()> getValue,
std::function<void(int16_t)> setValue = nullptr,
WindowFlags windowFlags = 0);
void set_lv_LongPressHandler(lvHandler_t longPressHandler, void* data);
lv_eventData_t longPressData;
void onClicked() override
{
if (!longPressData.isLongPressed) Choice::onClicked();
}
protected:
std::function<void(event_t)> longPressHandler = nullptr;
static void ClickHandler(lv_event_t* e)
{
ChoiceEx* ch = (ChoiceEx*)lv_event_get_user_data(e);
if (ch) ch->longPressData.isLongPressed = false;
}
};
+36 -8
View File
@@ -19,18 +19,16 @@
#include "dialog.h"
#include "mainwindow.h"
#include "theme.h"
#include "progress.h"
DialogWindowContent::DialogWindowContent(Dialog* parent, const rect_t& rect) :
ModalWindowContent(parent, rect),
form(this, rect_t{})
{
form.setFlexLayout();
auto form_obj = form.getLvObj();
lv_obj_set_style_pad_all(form_obj, lv_dpx(8), 0);
lv_coord_t max_height = LCD_H * 0.8;
lv_obj_set_style_max_height(form_obj, max_height, 0);
lv_obj_set_style_max_height(form.getLvObj(), LCD_H * 0.8, 0);
lv_obj_set_style_pad_all(form.getLvObj(), lv_dpx(8), 0);
lv_obj_set_scrollbar_mode(form.getLvObj(), LV_SCROLLBAR_MODE_AUTO);
}
void DialogWindowContent::setTitle(const std::string& text)
@@ -65,8 +63,6 @@ std::string DialogWindowContent::getName() const
Dialog::Dialog(Window* parent, std::string title, const rect_t& rect) :
ModalWindow(parent), content(new DialogWindowContent(this, rect))
{
lv_obj_set_style_bg_color(content->getLvObj(), makeLvColor(COLOR_THEME_SECONDARY3), 0);
lv_obj_set_style_bg_opa(content->getLvObj(), LV_OPA_100, LV_PART_MAIN);
bringToTop();
if (!title.empty()) content->setTitle(std::move(title));
}
@@ -81,3 +77,35 @@ void Dialog::onEvent(event_t event)
// block key events
(void)event;
}
//-----------------------------------------------------------------------------
ProgressDialog::ProgressDialog(Window *parent, std::string title,
std::function<void()> onClose) :
Dialog(parent, title, rect_t{}),
progress(new Progress(&content->form, rect_t{})),
onClose(std::move(onClose))
{
progress->setHeight(LV_DPI_DEF / 4);
content->setWidth(LCD_W * 0.8);
content->updateSize();
auto content_w = lv_obj_get_content_width(content->form.getLvObj());
progress->setWidth(content_w);
// disable canceling dialog
setCloseWhenClickOutside(false);
}
void ProgressDialog::updateProgress(int percentage)
{
progress->setValue(percentage);
lv_refr_now(nullptr);
}
void ProgressDialog::closeDialog()
{
deleteLater();
onClose();
}
+23 -1
View File
@@ -40,7 +40,7 @@ class DialogWindowContent : public ModalWindowContent
#endif
public:
FormGroup form;
FormWindow form;
};
class Dialog : public ModalWindow
@@ -54,3 +54,25 @@ class Dialog : public ModalWindow
void onCancel() override;
void onEvent(event_t event) override;
};
class Progress;
class ProgressDialog : public Dialog
{
uint32_t lastUpdate = 0;
Progress *progress;
std::function<void()> onClose;
public:
ProgressDialog(Window *parent, std::string title,
std::function<void()> onClose);
void updateProgress(int percentage);
void setTitle(std::string title) { content->setTitle(title); }
void closeDialog();
protected:
// disable keys
void onEvent(event_t) override {}
};
+1 -1
View File
@@ -19,7 +19,7 @@
#pragma once
#include <lvgl/lvgl.h>
#include "libopenui_types.h"
#include "opentx_types.h"
const lv_font_t* getFont(LcdFlags flags);
uint8_t getFontHeight(LcdFlags flags);
+13 -22
View File
@@ -18,9 +18,6 @@
#include "form.h"
#include "bitmapbuffer.h"
#include "libopenui_config.h"
#include "widgets/window_base.h"
FormField::FormField(Window* parent, const rect_t& rect,
WindowFlags windowFlags, LcdFlags textFlags,
@@ -56,11 +53,6 @@ void FormField::enable(bool value)
}
}
bool FormField::isEnabled() const
{
return !lv_obj_has_state(lvobj, LV_STATE_DISABLED);
}
void FormField::onClicked()
{
lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
@@ -80,39 +72,39 @@ void FormField::onCancel()
}
}
FormGroup::Line::Line(Window* parent, lv_obj_t* obj, FlexGridLayout* layout) :
FormWindow::Line::Line(Window* parent, lv_obj_t* obj, FlexGridLayout* layout) :
Window(parent, obj), layout(layout)
{
construct();
}
FormGroup::Line::Line(Window* parent, FlexGridLayout* layout) :
FormWindow::Line::Line(Window* parent, FlexGridLayout* layout) :
Window(parent, rect_t{}), layout(layout)
{
construct();
}
void FormGroup::Line::construct()
void FormWindow::Line::construct()
{
// forward scroll and focus
windowFlags |= FORWARD_SCROLL | NO_FOCUS | FORM_FORWARD_FOCUS;
// Focus
windowFlags |= NO_FOCUS;
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICK_FOCUSABLE);
if (layout) {
layout->apply(lvobj);
}
lv_obj_set_height(lvobj, LV_SIZE_CONTENT);
lv_obj_set_width(lvobj, lv_pct(100));
lv_obj_set_height(lvobj, LV_SIZE_CONTENT);
}
void FormGroup::Line::setLayout(FlexGridLayout *l)
void FormWindow::Line::setLayout(FlexGridLayout *l)
{
layout = l;
if (layout) layout->apply(lvobj);
}
void FormGroup::Line::addChild(Window* window)
void FormWindow::Line::addChild(Window* window)
{
Window::addChild(window);
if (layout) {
@@ -121,14 +113,13 @@ void FormGroup::Line::addChild(Window* window)
}
}
FormGroup::FormGroup(Window* parent, const rect_t& rect,
WindowFlags windowflags, LvglCreate objConstruct) :
Window(parent, rect, windowflags, 0, objConstruct)
FormWindow::FormWindow(Window* parent, const rect_t& rect,
WindowFlags windowflags) :
Window(parent, rect, windowflags, 0, etx_form_window_create)
{
lv_obj_set_style_bg_opa(lvobj, LV_OPA_TRANSP, LV_PART_MAIN);
}
void FormGroup::setFlexLayout(lv_flex_flow_t flow, lv_coord_t padding)
void FormWindow::setFlexLayout(lv_flex_flow_t flow, lv_coord_t padding)
{
lv_obj_set_flex_flow(lvobj, flow);
if (_LV_FLEX_COLUMN & flow) {
@@ -140,7 +131,7 @@ void FormGroup::setFlexLayout(lv_flex_flow_t flow, lv_coord_t padding)
lv_obj_set_height(lvobj, LV_SIZE_CONTENT);
}
FormGroup::Line* FormGroup::newLine(FlexGridLayout* layout, lv_coord_t left_padding)
FormWindow::Line* FormWindow::newLine(FlexGridLayout* layout, lv_coord_t left_padding)
{
if (layout) layout->resetPos();
auto lv_line = window_create(lvobj);
+39 -76
View File
@@ -21,98 +21,61 @@
#include "window.h"
#include "flexlayout.h"
constexpr WindowFlags FORM_FORWARD_FOCUS = WINDOW_FLAGS_LAST << 1;
constexpr WindowFlags FORM_DETACHED = WINDOW_FLAGS_LAST << 2;
constexpr WindowFlags FORM_BORDER_FOCUS_ONLY = WINDOW_FLAGS_LAST << 3;
constexpr WindowFlags FORM_NO_BORDER = WINDOW_FLAGS_LAST << 4;
constexpr WindowFlags FORM_FLAGS_LAST = FORM_NO_BORDER;
class FormField : public Window
{
public:
FormField(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0,
LcdFlags textFlags = 0, LvglCreate objConstruct = nullptr);
public:
FormField(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0,
LcdFlags textFlags = 0, LvglCreate objConstruct = nullptr);
virtual void changeEnd(bool forceChanged = false)
{
if (changeHandler) { changeHandler(); }
}
virtual void changeEnd(bool forceChanged = false)
{
if (changeHandler) { changeHandler(); }
}
void setChangeHandler(std::function<void()> handler)
{
changeHandler = std::move(handler);
}
void setChangeHandler(std::function<void()> handler)
{
changeHandler = std::move(handler);
}
void setBackgroundHandler(std::function<uint32_t(FormField *field)> handler)
{
backgroundHandler = std::move(handler);
}
inline bool isEditMode() const { return editMode; }
virtual void setEditMode(bool newEditMode);
inline bool isEditMode() const { return editMode; }
virtual void setEditMode(bool newEditMode);
void enable(bool value = true);
void disable() { enable(false); }
bool isEnabled() const;
void enable(bool value = true);
void disable() { enable(false); }
void onFocusLost() override
{
setEditMode(false);
Window::onFocusLost();
}
void onClicked() override;
void onCancel() override;
void onClicked() override;
void onCancel() override;
protected:
bool editMode = false;
bool enabled = true;
std::function<void()> changeHandler = nullptr;
std::function<uint32_t(FormField *)> backgroundHandler = nullptr;
protected:
bool editMode = false;
bool enabled = true;
std::function<void()> changeHandler = nullptr;
};
class FormGroup : public Window
class FormWindow : public Window
{
public:
class Line : public Window
{
FlexGridLayout *layout;
void construct();
public:
class Line : public Window
{
public:
Line(Window *parent, lv_obj_t *obj, FlexGridLayout *layout = nullptr);
Line(Window *parent, FlexGridLayout *layout = nullptr);
public:
Line(Window *parent, lv_obj_t *obj, FlexGridLayout *layout = nullptr);
Line(Window *parent, FlexGridLayout *layout = nullptr);
void setLayout(FlexGridLayout *l);
void setLayout(FlexGridLayout *l);
protected:
void addChild(Window *window) override;
};
protected:
FlexGridLayout *layout;
FormGroup(Window *parent, const rect_t &rect, WindowFlags windowflags = 0,
LvglCreate objConstruct = nullptr);
void addChild(Window *window) override;
void construct();
};
FormWindow(Window *parent, const rect_t &rect, WindowFlags windowflags = 0);
#if defined(DEBUG_WINDOWS)
std::string getName() const override { return "FormGroup"; }
std::string getName() const override { return "FormWindow"; }
#endif
void setFlexLayout(lv_flex_flow_t flow = LV_FLEX_FLOW_COLUMN, lv_coord_t padding = 0);
Line* newLine(FlexGridLayout* layout = nullptr, lv_coord_t left_padding = 0);
};
class FormWindow : public FormGroup
{
public:
FormWindow(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0,
LvglCreate objConstruct = nullptr) :
FormGroup(parent, rect, windowFlags, objConstruct)
{
}
#if defined(DEBUG_WINDOWS)
std::string getName() const override { return "FormWindow"; }
#endif
protected:
void paint(BitmapBuffer *) override {}
void setFlexLayout(lv_flex_flow_t flow = LV_FLEX_FLOW_COLUMN, lv_coord_t padding = 0);
Line* newLine(FlexGridLayout* layout = nullptr, lv_coord_t left_padding = 0);
};
-121
View File
@@ -1,121 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#pragma once
#include "window.h"
class GridLayout {
public:
explicit GridLayout(coord_t width, coord_t top = 0):
width(width),
currentY(top)
{
}
explicit GridLayout(Window * window):
width(window->width())
{
}
rect_t getSlot(uint8_t count = 1, uint8_t index = 0) const
{
coord_t width = (this->width - (count - 1) * PAGE_LINE_SPACING) / count;
coord_t left = (width + PAGE_LINE_SPACING) * index;
return {left, currentY, width, PAGE_LINE_HEIGHT};
}
void spacer(coord_t height=PAGE_LINE_SPACING)
{
currentY += height;
}
void nextLine(coord_t height=PAGE_LINE_HEIGHT)
{
spacer(height + PAGE_LINE_SPACING);
}
void addWindow(Window * window)
{
window->adjustHeight();
currentY += window->rect.h + PAGE_LINE_SPACING;
}
coord_t getWindowHeight() const
{
return currentY;
}
protected:
coord_t width;
coord_t currentY = 0;
};
class FormGridLayout: public GridLayout {
public:
explicit FormGridLayout(coord_t width = LCD_W, coord_t top = 0):
GridLayout(width, top)
{
}
void setLabelWidth(coord_t value)
{
labelWidth = value;
}
void setMarginLeft(coord_t value)
{
lineMarginLeft = value;
}
void setMarginRight(coord_t value)
{
lineMarginRight = value;
}
rect_t getLineSlot()
{
return { lineMarginLeft, currentY, this->width - lineMarginRight - lineMarginLeft, PAGE_LINE_HEIGHT };
}
rect_t getCenteredSlot(coord_t width = 0 ) const
{
if (width == 0)
width = this->width;
return { lineMarginLeft + (this->width - width)/2, currentY, min(width, this->width - lineMarginRight - lineMarginLeft), PAGE_LINE_HEIGHT };
}
rect_t getLabelSlot(bool indent = false) const
{
coord_t left = indent ? lineMarginLeft + PAGE_INDENT_WIDTH : lineMarginLeft;
return { left, currentY, labelWidth - left, PAGE_LINE_HEIGHT };
}
rect_t getFieldSlot(uint8_t count = 1, uint8_t index = 0) const
{
coord_t width = (this->width - labelWidth - lineMarginRight - (count - 1) * PAGE_LINE_SPACING) / count;
coord_t left = labelWidth + (width + PAGE_LINE_SPACING) * index;
return {left, currentY, width, PAGE_LINE_HEIGHT};
}
protected:
coord_t labelWidth = PAGE_LABEL_WIDTH;
coord_t lineMarginLeft = PAGE_PADDING;
coord_t lineMarginRight = PAGE_PADDING;
};
+1 -4
View File
@@ -56,10 +56,7 @@ static void _assign_lv_group(lv_group_t* g)
Keyboard::Keyboard(coord_t height) :
Window(MainWindow::instance(), {0, LCD_H - height, LCD_W, height}, OPAQUE)
{
// set the background of the window and opacity to 100%
lv_obj_set_parent(lvobj, lv_layer_top()); // the keyboard is always on top
lv_obj_set_style_bg_color(lvobj, lv_color_make(0xE0, 0xE0, 0xE0), LV_PART_MAIN);
lv_obj_set_style_bg_opa(lvobj, LV_OPA_100, LV_PART_MAIN);
// use a separate group for the keyboard
group = lv_group_create();
@@ -68,7 +65,7 @@ Keyboard::Keyboard(coord_t height) :
auto old_g = lv_group_get_default();
lv_group_set_default(group);
keyboard = lv_keyboard_create(lvobj);
keyboard = etx_keyboard_create(lvobj);
lv_group_set_default(old_g);
lv_obj_add_event_cb(keyboard, keyboard_event_cb, LV_EVENT_ALL, this);
-20
View File
@@ -1,20 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#pragma once
+65 -40
View File
@@ -18,10 +18,69 @@
#pragma once
#include "libopenui_types.h"
#include "libopenui_compat.h"
#include "debug.h"
#include "board.h"
#include "colors.h"
#include "keys.h"
#include "opentx_types.h"
enum FontIndex
{
FONT_STD_INDEX,
FONT_BOLD_INDEX,
FONT_XXS_INDEX,
FONT_XS_INDEX,
FONT_L_INDEX,
FONT_XL_INDEX,
FONT_XXL_INDEX,
// this one MUST be last
FONTS_COUNT
};
constexpr uint32_t MENU_HEADER_BUTTON_WIDTH = 33;
constexpr uint32_t MENU_HEADER_BUTTONS_LEFT = 47;
constexpr uint32_t MENUS_TOOLBAR_BUTTON_WIDTH = 30;
constexpr uint32_t MENUS_TOOLBAR_BUTTON_PADDING = 3;
constexpr uint32_t MENU_HEADER_HEIGHT = 45;
constexpr uint32_t MENU_TITLE_TOP = 48;
constexpr uint32_t MENU_TITLE_HEIGHT = 21;
constexpr uint32_t MENU_BODY_TOP = MENU_TITLE_TOP + MENU_TITLE_HEIGHT;
constexpr uint32_t MENU_FOOTER_HEIGHT = 0;
constexpr uint32_t MENU_FOOTER_TOP = LCD_H - MENU_FOOTER_HEIGHT;
constexpr uint32_t MENU_BODY_HEIGHT = MENU_FOOTER_TOP - MENU_BODY_TOP;
constexpr uint32_t MENUS_MARGIN_LEFT = 6;
constexpr uint32_t MENU_HEADER_BACK_BUTTON_WIDTH = MENU_HEADER_HEIGHT;
constexpr uint32_t MENU_HEADER_BACK_BUTTON_HEIGHT = MENU_HEADER_HEIGHT;
constexpr coord_t PAGE_PADDING = 6;
constexpr uint32_t PAGE_LINE_HEIGHT = 20;
constexpr uint32_t FH = PAGE_LINE_HEIGHT;
constexpr uint32_t NUM_BODY_LINES = MENU_BODY_HEIGHT / PAGE_LINE_HEIGHT;
constexpr uint32_t FIELD_PADDING_LEFT = 3;
constexpr uint32_t FIELD_PADDING_TOP = 2;
constexpr uint32_t CURVE_SIDE_WIDTH = 100;
constexpr uint32_t CURVE_CENTER_X = LCD_W - CURVE_SIDE_WIDTH - 7;
constexpr uint32_t CURVE_CENTER_Y = 151;
constexpr uint32_t CURVE_COORD_WIDTH = 36;
constexpr uint32_t CURVE_COORD_HEIGHT = 17;
constexpr uint32_t DATETIME_SEPARATOR_X = LCD_W - 53;
constexpr uint32_t DATETIME_LINE1 = 7;
constexpr uint32_t DATETIME_LINE2 = 22;
constexpr uint32_t DATETIME_MIDDLE = (LCD_W + DATETIME_SEPARATOR_X + 1) / 2;
constexpr uint32_t PAGE_TITLE_TOP = 2;
constexpr uint32_t PAGE_TITLE_LEFT = 50;
constexpr coord_t POPUP_HEADER_HEIGHT = 30;
constexpr coord_t MODEL_SELECT_FOOTER_HEIGHT = 24;
/* obsolete flags */
#define BLINK 0
#define TIMEHOUR 0
@@ -33,7 +92,6 @@
#define RIGHT 0x08u /* align right */
#define SHADOWED 0x80u /* black copy at +1 +1 */
// 0x1000u used by Lua in api_colorlcd.h
#define SPACING_NUMBERS_CONST 0x2000u
// 0x8000u used by Lua in api_colorlcd.h
/* drawNumber flags */
@@ -49,40 +107,7 @@
#define FONT_INDEX(flags) (((flags) & FONT_MASK) >> 8u)
#define FONT(xx) (unsigned(FONT_ ## xx ## _INDEX) << 8u)
#define ARGB_SPLIT(color, a, r, g, b) \
uint16_t a = ((color) & 0xF000) >> 12; \
uint16_t r = ((color) & 0x0F00) >> 8; \
uint16_t g = ((color) & 0x00F0) >> 4; \
uint16_t b = ((color) & 0x000F)
#define RGB_SPLIT(color, r, g, b) \
uint16_t r = ((color) & 0xF800) >> 11; \
uint16_t g = ((color) & 0x07E0) >> 5; \
uint16_t b = ((color) & 0x001F)
#define ARGB_JOIN(a, r, g, b) \
(((a&0xF) << 12) + ((r&0xF) << 8) + ((g&0xF) << 4) + (b&0xF))
#define RGB_JOIN(r, g, b) \
(((r) << 11) + ((g) << 5) + (b))
#define GET_RED(color) \
(((color) & 0xF800) >> 8)
#define GET_GREEN(color) \
(((color) & 0x07E0) >> 3)
#define GET_BLUE(color) \
(((color) & 0x001F) << 3)
#define OPACITY_MAX 0x0Fu
#define OPACITY(value) ((value) & OPACITY_MAX)
#define RGB(r, g, b) (uint16_t)((((r) & 0xF8) << 8) + (((g) & 0xFC) << 3) + (((b) & 0xF8) >> 3))
#define ARGB(a, r, g, b) (uint16_t)((((a) & 0xF0) << 8) + (((r) & 0xF0) << 4) + (((g) & 0xF0) << 0) + (((b) & 0xF0) >> 4))
#define COLOR2FLAGS(color) LcdFlags(unsigned(color) << 16u)
#define COLOR_VAL(flags) ((flags) >> 16u)
#define COLOR_MASK(flags) ((flags) & 0xFFFF0000u)
#define LV_OBJ_FLAG_ENCODER_ACCEL LV_OBJ_FLAG_USER_1
#include "libopenui_config.h"
-56
View File
@@ -1,56 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#pragma once
#include <inttypes.h>
#include "libopenui_config.h"
void lcdNextLayer();
uint16_t* lcdGetScratchBuffer();
void DMACopyBitmap(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint16_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h);
void DMACopyAlphaBitmap(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint16_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h);
void DMACopyAlphaMask(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint8_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h, uint16_t bg_color);
void onKeyError();
void killEvents(event_t event);
// multiplication factor between 0 and 25
int8_t rotaryEncoderGetAccel();
//
// These colors MUST be defined
//
// #define COLOR_THEME_SECONDARY1
// #define COLOR_THEME_SECONDARY3
// #define COLOR_THEME_PRIMARY2
// #define COLOR_THEME_FOCUS
// #define COLOR_THEME_DISABLED
// #define COLOR_THEME_ACTIVE
// #define COLOR_THEME_FOCUS
// #define COLOR_THEME_PRIMARY3
// #define COLOR_THEME_SECONDARY1
// #define COLOR_THEME_PRIMARY2
// #define COLOR_THEME_SECONDARY1_THEME_SECONDARY1
// #define COLOR_THEME_SECONDARY2
// #define COLOR_THEME_PRIMARY2
// #define COLOR_THEME_FOCUS
// #define COLOR_THEME_PRIMARY1
// #define COLOR_THEME_SECONDARY3
// #define COLOR_THEME_FOCUS
// #define CUSTOM_COLOR
-1
View File
@@ -19,7 +19,6 @@
#include <inttypes.h>
#include <string.h>
#include "libopenui_file.h"
#include "libopenui_defines.h"
const char * getFileExtension(const char * filename, uint8_t size, uint8_t extMaxLen, uint8_t * fnlen, uint8_t * extlen)
{
-1
View File
@@ -18,7 +18,6 @@
#pragma once
#include "libopenui_compat.h" // for strcasecmp / VC++
#include <string>
#include <cstring>
#include <cinttypes>
@@ -1,20 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#include "libopenui_helpers.h"
-96
View File
@@ -1,96 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#pragma once
#include <string>
#include <cstring>
#if defined(min)
#undef min
#undef max
#endif
template<class T>
inline T min(T a, T b)
{
return a < b ? a : b;
}
template<class T>
inline T max(T a, T b)
{
return a > b ? a : b;
}
template<class T>
inline T limit(T vmin, T x, T vmax)
{
return ::min(::max(vmin, x), vmax);
}
inline int divRoundClosest(int n, int d)
{
if (d == 0)
return 0;
else
return ((n < 0) ^ (d < 0)) ? ((n - d/2)/d) : ((n + d/2)/d);
}
inline int multDivRoundClosest(int v, int n, int d)
{
if (n == d)
return v;
else
return divRoundClosest(v * n, d);
}
inline int mod(int k, int n)
{
return ((k %= n) < 0) ? k + n : k;
}
inline unsigned align32(unsigned n)
{
unsigned rest = (n & 3u);
return rest ? n + 4u - rest : n;
}
template<class T>
inline T sgn(T a)
{
return a > 0 ? 1 : (a < 0 ? -1 : 0);
}
// TODO duplicated code
inline std::string TEXT_AT_INDEX(const char *const *val, uint8_t idx)
{
return std::string(val[idx]);
}
inline const char * findNextLine(const char * stack)
{
while (true) {
const char * pos = strchr(stack, '\n');
if (!pos)
return nullptr;
if (pos == stack || *((uint8_t *)(pos - 1)) < 0xFE)
return pos;
stack = pos + 1;
}
}
-74
View File
@@ -1,74 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#pragma once
#include <cinttypes>
typedef int coord_t;
struct point_t
{
coord_t x;
coord_t y;
bool operator != (const point_t & b) const
{
return x != b.x || y != b.y;
}
};
struct rect_t
{
coord_t x, y, w, h;
constexpr coord_t left() const
{
return x;
}
constexpr coord_t right() const
{
return x + w;
}
constexpr coord_t top() const
{
return y;
}
constexpr coord_t bottom() const
{
return y + h;
}
bool contains(coord_t x, coord_t y) const
{
return (x >= this->x && x < this->x + this->w && y >= this->y && y < this->y + this->h);
}
bool contains(const rect_t & other) const
{
return left() <= other.left() && right() >= other.right() && top() <= other.top() && bottom() >= other.bottom();
}
};
static const rect_t nullRect = {0, 0, 0, 0};
typedef uint32_t LcdFlags;
typedef uint16_t event_t;
+1 -18
View File
@@ -21,12 +21,10 @@
#include "lvgl/lvgl.h"
MainWindow * MainWindow::_instance = nullptr;
MainWindow::MainWindow() :
Window(nullptr, {0, 0, LCD_W, LCD_H}, OPAQUE), invalidatedRect(rect)
Window(nullptr, {0, 0, LCD_W, LCD_H}, OPAQUE)
{
}
@@ -38,21 +36,6 @@ void MainWindow::emptyTrash()
trash.clear();
}
void MainWindow::invalidate(const rect_t& rect)
{
if (invalidatedRect.w) {
auto left = limit<coord_t>(0, rect.left(), invalidatedRect.left());
auto right = limit<coord_t>(invalidatedRect.right(), rect.right(), LCD_W);
auto top = limit<coord_t>(0, rect.top(), invalidatedRect.top());
auto bottom =
limit<coord_t>(rect.bottom(), invalidatedRect.bottom(), LCD_H);
invalidatedRect = {left, top, right - left, bottom - top};
} else {
invalidatedRect = rect;
}
}
void MainWindow::run(bool trash)
{
auto start = ticksNow();
-22
View File
@@ -34,11 +34,6 @@ class MainWindow: public Window
children.clear();
}
static bool isMainWindowCreated()
{
return _instance != nullptr;
}
static MainWindow * instance()
{
if (!_instance)
@@ -61,30 +56,13 @@ class MainWindow: public Window
}
#endif
void setActiveScreen() {
lv_scr_load(lvobj);
}
void invalidate()
{
invalidate({0, 0, rect.w, rect.h});
}
void invalidate(const rect_t & rect) override;
bool needsRefresh() const
{
return invalidatedRect.w > 0;
}
bool refresh();
void run(bool trash=true);
protected:
static MainWindow * _instance;
static void emptyTrash();
rect_t invalidatedRect;
const char * shutdown = nullptr;
};
+1 -3
View File
@@ -259,8 +259,6 @@ MenuWindowContent::MenuWindowContent(Menu* parent) :
(LCD_H - MENUS_WIDTH) / 2, MENUS_WIDTH, 0}),
body(this, {0, 0, width(), height()})
{
// body.setFocus(SET_FOCUS_DEFAULT);
lv_obj_set_style_bg_opa(lvobj, LV_OPA_100, LV_PART_MAIN);
}
coord_t MenuWindowContent::getHeaderHeight() const
@@ -278,7 +276,7 @@ void MenuWindowContent::deleteLater(bool detach, bool trash)
Menu::Menu(Window * parent, bool multiple):
ModalWindow(parent, true),
content(createMenuWindow(this)),
content(new MenuWindowContent(this)),
multiple(multiple)
{
}
+1 -2
View File
@@ -55,12 +55,11 @@ void MenuToolbarButton::paint(BitmapBuffer * dc)
}
MenuToolbar::MenuToolbar(Choice* choice, Menu* menu) :
Window(menu, MENUS_TOOLBAR_RECT, NO_SCROLLBAR),
Window(menu, MENUS_TOOLBAR_RECT, OPAQUE),
choice(choice),
menu(menu),
group(lv_group_create())
{
lv_obj_set_style_bg_opa(lvobj, LV_OPA_100, LV_PART_MAIN);
lv_group_add_obj(group, lvobj);
}
+3 -15
View File
@@ -22,12 +22,10 @@
#include "layer.h"
ModalWindow::ModalWindow(Window * parent, bool closeWhenClickOutside):
Window(parent->getFullScreenWindow(), {0, 0, LCD_W, LCD_H}),
Window(parent->getFullScreenWindow(), {0, 0, LCD_W, LCD_H}, 0, 0, etx_modal_create),
closeWhenClickOutside(closeWhenClickOutside)
{
Layer::push(this);
lv_obj_set_style_bg_color(lvobj, lv_color_black(), LV_PART_MAIN);
lv_obj_set_style_bg_opa(lvobj, LV_OPA_50, LV_PART_MAIN);
}
void ModalWindow::deleteLater(bool detach, bool trash)
@@ -46,7 +44,7 @@ void ModalWindow::onClicked()
ModalWindowContent::ModalWindowContent(ModalWindow* parent,
const rect_t& rect) :
Window(parent, rect, OPAQUE)
Window(parent, rect, OPAQUE, 0, etx_modal_content_create)
{
}
@@ -58,18 +56,8 @@ void ModalWindowContent::onClicked()
void ModalWindowContent::setTitle(const std::string& text)
{
if (!title) {
title = lv_label_create(lvobj);
title = etx_modal_title_create(lvobj);
lv_obj_move_to_index(title, 0);
lv_obj_set_width(title, lv_pct(100));
lv_obj_set_style_pad_all(title, PAGE_PADDING, LV_PART_MAIN);
lv_color_t bg_color = makeLvColor(COLOR_THEME_SECONDARY1);
lv_obj_set_style_bg_color(title, bg_color, LV_PART_MAIN);
lv_obj_set_style_bg_opa(title, LV_OPA_100, LV_PART_MAIN);
lv_color_t txt_color = makeLvColor(COLOR_THEME_PRIMARY2);
lv_obj_set_style_text_color(title, txt_color, LV_PART_MAIN);
lv_obj_update_layout(lvobj);
}
lv_label_set_text(title, text.c_str());
+6 -14
View File
@@ -17,8 +17,8 @@
*/
#include "numberedit.h"
#include "widgets/field_edit.h"
#include "keyboard_number.h"
#include "audio.h"
static void numberedit_cb(lv_event_t* e)
{
@@ -40,25 +40,17 @@ NumberEdit::NumberEdit(Window* parent, const rect_t& rect, int vmin, int vmax,
std::function<int()> getValue,
std::function<void(int)> setValue,
WindowFlags windowFlags, LcdFlags textFlags) :
BaseNumberEdit(parent, rect, vmin, vmax, std::move(getValue),
std::move(setValue), windowFlags, textFlags,
field_edit_create)
FormField(parent, rect, windowFlags, textFlags, etx_number_edit_create),
vmin(vmin),
vmax(vmax),
_getValue(std::move(getValue)),
_setValue(std::move(setValue))
{
// Allow encoder acceleration
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_ENCODER_ACCEL);
// properties
lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_OFF);
lv_textarea_set_password_mode(lvobj, false);
lv_textarea_set_one_line(lvobj, true);
lv_obj_add_event_cb(lvobj, numberedit_cb, LV_EVENT_KEY, this);
setHeight(33);
padTop(5);
padRight(4);
lv_obj_set_style_text_align(lvobj, LV_TEXT_ALIGN_RIGHT, 0);
lv_obj_set_style_radius(lvobj, 4, 0);
update();
}
+172 -19
View File
@@ -18,32 +18,185 @@
#pragma once
#include "basenumberedit.h"
#include "form.h"
#include "strhelpers.h"
#include <string>
class NumberEdit : public BaseNumberEdit
class NumberEdit: public FormField
{
public:
NumberEdit(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);
public:
NumberEdit(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);
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "NumberEdit(" + std::to_string(getValue()) + ")";
}
std::string getName() const override
{
return "NumberEdit(" + std::to_string(getValue()) + ")";
}
#endif
void setAvailableHandler(std::function<bool(int)> handler)
{
isValueAvailable = std::move(handler);
}
void setAvailableHandler(std::function<bool(int)> handler)
{
isValueAvailable = std::move(handler);
}
void onEvent(event_t event) override;
void onClicked() override;
void onEvent(event_t event) override;
void onClicked() override;
protected:
std::function<bool(int)> isValueAvailable;
void setMin(int value)
{
vmin = value;
}
void setMax(int value)
{
vmax = value;
}
void setDefault(int value)
{
vdefault = value;
}
int32_t getMin() const
{
return vmin;
}
int32_t getMax() const
{
return vmax;
}
int32_t getDefault() const
{
return vdefault;
}
void setStep(int value)
{
step = value;
}
int32_t getStep() const
{
return step;
}
void setFastStep(int value)
{
fastStep = value;
}
int32_t getFastStep() const
{
return fastStep;
}
void setAccelFactor(int value)
{
accelFactor = value;
}
int32_t getAccelFactor() const
{
return accelFactor;
}
void setValue(int value)
{
auto newValue = limit(vmin, value, vmax);
if (newValue != currentValue) {
currentValue = newValue;
if (_setValue != nullptr) {
_setValue(currentValue);
}
}
if (lvobj != nullptr) {
std::string str;
if (displayFunction != nullptr) {
str = displayFunction(currentValue);
} else {
str = formatNumberAsString(currentValue, textFlags, 0, prefix.c_str(),
suffix.c_str());
}
lv_textarea_set_text(lvobj, str.c_str());
}
}
void setPrefix(std::string value)
{
prefix = std::move(value);
update();
}
void setSuffix(std::string value)
{
suffix = std::move(value);
update();
}
void setZeroText(std::string value)
{
zeroText = std::move(value);
update();
}
void setSetValueHandler(std::function<void(int)> handler)
{
_setValue = std::move(handler);
}
void setGetValueHandler(std::function<int()> handler)
{
_getValue = std::move(handler);
}
int32_t getValue() const
{
return _getValue != nullptr ? _getValue() : 0;
}
void setDisplayHandler(std::function<std::string(int value)> function)
{
displayFunction = std::move(function);
update();
}
virtual void update()
{
if (_getValue == nullptr) return;
auto newValue = _getValue();
if (newValue != currentValue) {
currentValue = newValue;
}
if (lvobj != nullptr) {
std::string str;
if (displayFunction != nullptr) {
str = displayFunction(currentValue);
} else {
str = formatNumberAsString(currentValue, textFlags, 0, prefix.c_str(),
suffix.c_str());
}
lv_textarea_set_text(lvobj, str.c_str());
}
}
protected:
int vdefault = 0;
int vmin;
int vmax;
int step = 1;
int fastStep = 10;
int accelFactor = 4;
int currentValue;
std::string prefix;
std::string suffix;
std::string zeroText;
std::function<int()> _getValue;
std::function<void(int)> _setValue;
std::function<std::string(int)> displayFunction;
std::function<bool(int)> isValueAvailable;
};
+13 -3
View File
@@ -19,8 +19,18 @@
#include "progress.h"
#include "theme.h"
void Progress::paint(BitmapBuffer * dc)
Progress::Progress(Window * parent, const rect_t & rect):
Window(parent, rect)
{
auto val = value > 100 ? 100 : value;
theme->drawProgressBar(dc, 0, 0, width(), height(), val, 100);
bar = etx_bar_create(lvobj);
lv_bar_set_range(bar, 0, 100);
setValue(0);
}
void Progress::setValue(int newValue)
{
if (newValue != value) {
value = newValue;
lv_bar_set_value(bar, value, LV_ANIM_OFF);
}
}
+4 -14
View File
@@ -22,10 +22,7 @@
class Progress: public Window {
public:
Progress(Window * parent, const rect_t & rect):
Window(parent, rect)
{
}
Progress(Window * parent, const rect_t & rect);
#if defined(DEBUG_WINDOWS)
std::string getName() const override
@@ -34,16 +31,9 @@ class Progress: public Window {
}
#endif
void setValue(int newValue)
{
if (newValue != value) {
value = newValue;
invalidate();
}
}
void paint(BitmapBuffer * dc) override;
void setValue(int newValue);
protected:
int value = 0;
int value = -1;
lv_obj_t* bar;
};
-174
View File
@@ -1,174 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#pragma once
#include <touch.h>
#include <choice.h>
#include <font.h>
#include <static.h>
#include <limits.h>
#include "libopenui_config.h"
constexpr WindowFlags ROLLER_SEPARATION_LINES = (FORM_FLAGS_LAST << 1u);
constexpr coord_t SCROLL_POSITION_INVALIDATED = INT_MIN;
class Roller: public Choice
{
public:
Roller(FormGroup * parent, const rect_t & rect, const char * label, const char * const * values, int vmin, int vmax, std::function<int()> getValue, std::function<void(int)> setValue = nullptr, WindowFlags windowFlags = ROLLER_SEPARATION_LINES):
Choice(parent, rect, values, vmin, vmax, std::move(getValue), std::move(setValue), windowFlags | NO_SCROLLBAR)
{
init(label);
}
Roller(FormGroup * parent, const rect_t & rect, const char * label, std::vector<std::string> values, int vmin, int vmax, std::function<int()> getValue, std::function<void(int)> setValue = nullptr, WindowFlags windowFlags = ROLLER_SEPARATION_LINES):
Choice(parent, rect, std::move(values), vmin, vmax, std::move(getValue), std::move(setValue), windowFlags | NO_SCROLLBAR)
{
init(label);
}
void init(const char * label)
{
if (label) {
// the label is another window, could be changed, but is it needed?
new StaticText(parent, {rect.x, rect.y - ROLLER_LINE_HEIGHT, rect.w, ROLLER_LINE_HEIGHT}, label, 0, CENTERED);
}
setHeight(ROLLER_LINE_HEIGHT * 3 - 1);
setPageHeight(ROLLER_LINE_HEIGHT);
setInnerHeight(INFINITE_HEIGHT);
updateScrollPositionFromValue();
}
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "Roller";
}
#endif
void paint(BitmapBuffer * dc) override
{
int32_t value = getValue();
auto valuesCount = (int)getValuesCount();
if (valuesCount == 0) {
return;
}
int index = (scrollPositionY - ROLLER_LINE_HEIGHT + 1) / ROLLER_LINE_HEIGHT;
coord_t y = index * ROLLER_LINE_HEIGHT;
coord_t yMax = scrollPositionY + 3 * ROLLER_LINE_HEIGHT;
index = mod(index, valuesCount);
while (y < yMax) {
auto displayedValue = getValueFromIndex(index);
auto fgColor = COLOR_THEME_DISABLED;
if (value == displayedValue) {
fgColor = COLOR_THEME_PRIMARY2 | FONT(STD);
}
unsigned valueIndex = displayedValue - vmin;
if (valueIndex < values.size()) {
dc->drawText(width() / 2, y, values[valueIndex].c_str(), fgColor | CENTERED);
}
else {
dc->drawNumber(width() / 2, y, displayedValue, fgColor | CENTERED);
}
if (windowFlags & ROLLER_SEPARATION_LINES) {
dc->drawSolidHorizontalLine(0, y - 10, width(), COLOR_THEME_DISABLED);
}
if (++index == valuesCount)
index = 0;
y += ROLLER_LINE_HEIGHT;
}
}
void checkEvents() override
{
Window::checkEvents();
if (lastEditMode != editMode) {
updateScrollPositionFromValue();
lastEditMode = editMode;
}
if (lastScrollPositionY == SCROLL_POSITION_INVALIDATED) {
updateScrollPositionFromValue();
}
#if defined(HARDWARE_TOUCH)
if (touchState.event != TE_SLIDE) {
if (scrollPositionY != lastScrollPositionY) {
updateValueFromScrollPosition();
}
}
#endif
}
// virtual not needed until now
void setMin(int value)
{
Choice::setMin(value);
invalidateScrollPosition();
}
// virtual not needed until now
void setMax(int value)
{
Choice::setMax(value);
invalidateScrollPosition();
}
// virtual not needed until now
void setAvailableHandler(std::function<bool(int)> handler)
{
Choice::setAvailableHandler(std::move(handler));
invalidateScrollPosition();
}
void invalidateScrollPosition()
{
lastScrollPositionY = SCROLL_POSITION_INVALIDATED;
}
protected:
coord_t lastScrollPositionY = SCROLL_POSITION_INVALIDATED;
bool lastEditMode = false;
void updateScrollPositionFromValue()
{
setScrollPositionY(ROLLER_LINE_HEIGHT * (getIndexFromValue(this->getValue()) - 1));
lastScrollPositionY = scrollPositionY;
}
void updateValueFromScrollPosition()
{
lastScrollPositionY = scrollPositionY;
auto valuesCount = getValuesCount();
auto newValue = getValueFromIndex(mod((scrollPositionY / ROLLER_LINE_HEIGHT) + 1, valuesCount));
setValue(newValue);
invalidate();
}
};
+16 -64
View File
@@ -23,80 +23,32 @@
static void slider_changed_cb(lv_event_t* e)
{
lv_obj_t* target = lv_event_get_target(e);
auto code = lv_event_get_code(e);
Slider* sl = (Slider*)lv_obj_get_user_data(target);
if (code == LV_EVENT_VALUE_CHANGED) {
if (sl != nullptr) sl->setValue(lv_slider_get_value(target));
if (lv_event_get_code(e) == LV_EVENT_VALUE_CHANGED) {
Slider* sl = (Slider*)lv_event_get_user_data(e);
if (sl != nullptr) {
lv_obj_t* target = lv_event_get_target(e);
sl->setValue(lv_slider_get_value(target));
}
}
}
static lv_style_t style_main;
static lv_style_t style_ind;
static lv_style_t style_knob;
static lv_style_t style_focused;
static lv_style_t style_edit;
constexpr coord_t SLIDER_PADDING = 6;
Slider::Slider(Window* parent, const rect_t& rect, int32_t vmin, int32_t vmax,
Slider::Slider(Window* parent, coord_t width, int32_t vmin, int32_t vmax,
std::function<int()> getValue,
std::function<void(int)> setValue) :
FormField(parent,
{rect.x + SLIDER_PADDING, rect.y + SLIDER_PADDING,
rect.w - 2 * SLIDER_PADDING, rect.h - 2 * SLIDER_PADDING},
0, 0, lv_slider_create),
Window(parent, {0, 0, width, 32}, 0, 0, window_create),
vmin(vmin),
vmax(vmax),
_getValue(std::move(getValue)),
_setValue(std::move(setValue))
{
lv_obj_add_event_cb(lvobj, slider_changed_cb, LV_EVENT_VALUE_CHANGED, this);
lv_obj_add_event_cb(lvobj, slider_changed_cb, LV_EVENT_PRESSED, this);
lv_slider_set_range(lvobj, vmin, vmax);
padAll(7);
auto slider = etx_slider_create(lvobj);
lv_obj_set_width(slider, lv_pct(100));
lv_obj_add_event_cb(slider, slider_changed_cb, LV_EVENT_VALUE_CHANGED, this);
lv_slider_set_range(slider, vmin, vmax);
if (_getValue != nullptr)
lv_slider_set_value(lvobj, _getValue(), LV_ANIM_OFF);
// LV_PART_MAIN
lv_style_init(&style_main);
lv_style_set_bg_opa(&style_main, LV_OPA_100);
lv_style_set_bg_color(&style_main, makeLvColor(COLOR_THEME_SECONDARY1));
lv_style_set_radius(&style_main, LV_RADIUS_CIRCLE);
lv_obj_add_style(lvobj, &style_main, LV_PART_MAIN);
// LV_PART_INDICATOR
lv_style_init(&style_ind);
lv_style_set_bg_opa(&style_ind, LV_OPA_100);
lv_style_set_bg_color(&style_ind, makeLvColor(COLOR_THEME_SECONDARY1));
lv_obj_add_style(lvobj, &style_ind, LV_PART_INDICATOR);
// Knob
lv_style_init(&style_knob);
lv_style_set_bg_color(&style_knob, makeLvColor(COLOR_THEME_PRIMARY2));
lv_style_set_border_color(&style_knob, makeLvColor(COLOR_THEME_SECONDARY1));
lv_style_set_border_width(&style_knob, 2);
lv_obj_add_style(lvobj, &style_knob, LV_PART_KNOB);
// LV_STATE_FOCUSED
lv_style_init(&style_focused);
lv_style_set_bg_color(&style_focused, makeLvColor(COLOR_THEME_FOCUS));
lv_style_set_outline_width(&style_focused, 0);
lv_obj_add_style(lvobj, &style_focused, LV_PART_MAIN | LV_STATE_FOCUSED);
lv_obj_add_style(lvobj, &style_focused, LV_PART_MAIN | LV_STATE_FOCUSED | LV_STATE_EDITED);
lv_obj_add_style(lvobj, &style_focused, LV_PART_INDICATOR | LV_STATE_FOCUSED);
lv_obj_add_style(lvobj, &style_focused, LV_PART_INDICATOR | LV_STATE_FOCUSED | LV_STATE_EDITED);
lv_style_init(&style_edit);
lv_style_set_bg_color(&style_edit, makeLvColor(COLOR_THEME_EDIT));
lv_obj_add_style(lvobj, &style_edit, LV_PART_KNOB | LV_STATE_FOCUSED | LV_STATE_EDITED);
lv_slider_set_value(slider, _getValue(), LV_ANIM_OFF);
}
int Slider::value(coord_t x) const
{
return vmin + ((vmax - vmin) * x + (rect.w / 2)) / rect.w;
}
+2 -4
View File
@@ -20,10 +20,10 @@
#include "form.h"
class Slider : public FormField
class Slider : public Window
{
public:
Slider(Window* parent, const rect_t& rect, int32_t vmin, int32_t vmax,
Slider(Window* parent, coord_t width, int32_t vmin, int32_t vmax,
std::function<int()> getValue, std::function<void(int)> setValue);
#if defined(DEBUG_WINDOWS)
@@ -40,6 +40,4 @@ class Slider : public FormField
int vmax;
std::function<int()> _getValue;
std::function<void(int)> _setValue;
int value(coord_t x) const;
};
-5
View File
@@ -35,11 +35,6 @@ StaticText::StaticText(Window* parent, const rect_t& rect, std::string txt,
else if (textFlags & RIGHT)
lv_obj_set_style_text_align(lvobj, LV_TEXT_ALIGN_RIGHT, 0);
if (windowFlags & BUTTON_BACKGROUND) {
lv_obj_set_style_bg_opa(lvobj, LV_OPA_100, LV_PART_MAIN);
setBackgroundColor(COLOR_THEME_SECONDARY2);
}
lv_obj_set_style_grid_cell_x_align(lvobj, LV_GRID_ALIGN_STRETCH, 0);
lv_label_set_text(lvobj, text.c_str());
lv_obj_set_height(lvobj, LV_SIZE_CONTENT);
+1 -52
View File
@@ -19,7 +19,6 @@
#pragma once
#include "window.h"
#include "button.h" // TODO just for BUTTON_BACKGROUND
class StaticText: public Window
{
@@ -44,44 +43,11 @@ class StaticText: public Window
LcdFlags bgColor = 0;
};
class Subtitle: public StaticText {
public:
Subtitle(Window * parent, const rect_t & rect, const char * text, WindowFlags windowFlags = 0, LcdFlags textFlags = 0):
StaticText(parent, rect, text, windowFlags, textFlags | FONT(BOLD))
{
}
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "Subtitle \"" + text + "\"";
}
#endif
};
#define Subtitle(parent, text) StaticText(parent, rect_t{}, text, 0, COLOR_THEME_PRIMARY1 | FONT(BOLD))
class StaticBitmap: public Window
{
public:
StaticBitmap(Window * parent, const rect_t & rect, bool scale = false):
Window(parent, rect),
scale(scale)
{
}
StaticBitmap(Window * parent, const rect_t & rect, const char * filename, bool scale = false):
Window(parent, rect),
bitmap(BitmapBuffer::loadBitmap(filename)),
scale(scale)
{
}
StaticBitmap(Window * parent, const rect_t & rect, const BitmapBuffer * bitmap, bool scale = false):
Window(parent, rect),
bitmap(bitmap),
scale(scale)
{
}
StaticBitmap(Window * parent, const rect_t & rect, const BitmapBuffer * mask, LcdFlags color, bool scale = false):
Window(parent, rect),
bitmap(mask),
@@ -90,23 +56,6 @@ class StaticBitmap: public Window
{
}
void setBitmap(const char * filename)
{
setBitmap(BitmapBuffer::loadBitmap(filename));
}
void setMaskColor(LcdFlags value)
{
color = value;
}
void setBitmap(const BitmapBuffer * newBitmap)
{
delete bitmap;
bitmap = newBitmap;
invalidate();
}
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
+1 -2
View File
@@ -17,7 +17,6 @@
*/
#include "table.h"
#include "widgets/edgetx_table.h"
void TableField::event_cb(lv_event_t *e)
{
@@ -135,7 +134,7 @@ void TableField::draw_end(lv_event_t* e)
}
TableField::TableField(Window* parent, const rect_t& rect, WindowFlags windowFlags) :
Window(parent, rect, windowFlags, 0, table_create)
Window(parent, rect, windowFlags, 0, etx_table_create)
{
lv_obj_add_event_cb(lvobj, TableField::event_cb, LV_EVENT_ALL, nullptr);
}
+1 -1
View File
@@ -24,7 +24,7 @@ class TableField : public Window
{
public:
TableField(Window* parent, const rect_t& rect,
WindowFlags windowFlags = OPAQUE | FORM_NO_BORDER);
WindowFlags windowFlags = OPAQUE);
#if defined(DEBUG_WINDOWS)
std::string getName() const override { return "Table"; }
+1 -35
View File
@@ -19,50 +19,22 @@
#include "textedit.h"
#include "font.h"
#include "widgets/field_edit.h"
#if !defined(STR_EDIT)
#define STR_EDIT "Edit"
#endif
#if !defined(STR_CLEAR)
#define STR_CLEAR "Clear"
#endif
#include "keyboard_text.h"
#if defined(HARDWARE_KEYS)
#include "menu.h"
#endif
#if defined(CLIPBOARD)
#include "clipboard.h"
#endif
TextEdit::TextEdit(Window *parent, const rect_t &rect, char *value,
uint8_t length, LcdFlags windowFlags) :
FormField(parent, rect, windowFlags, 0,
field_edit_create),
etx_text_edit_create),
value(value),
length(length)
{
// properties
lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_OFF);
lv_textarea_set_password_mode(lvobj, false);
lv_textarea_set_one_line(lvobj, true);
lv_textarea_set_placeholder_text(lvobj, "---");
lv_textarea_set_max_length(lvobj, length);
setHeight(33);
padTop(5);
padLeft(4);
lv_obj_set_style_radius(lvobj, 4, 0);
if (width() == 0) {
lv_obj_set_width(lvobj, LV_DPI_DEF);
}
update();
}
@@ -104,9 +76,3 @@ void TextEdit::onClicked()
{
TextKeyboard::show(this);
}
void TextEdit::onFocusLost()
{
changeEnd();
FormField::onFocusLost();
}
-1
View File
@@ -46,5 +46,4 @@ class TextEdit : public FormField
void changeEnd(bool forceChanged = false) override;
void onClicked() override;
void onFocusLost() override;
};
-63
View File
@@ -1,63 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#pragma once
#include "bitmapbuffer.h"
#include "checkbox.h"
#include "button.h"
class Menu;
class MenuWindowContent;
class Dialog;
class DialogWindowContent;
class ChoiceBase;
enum IconState {
STATE_DEFAULT,
STATE_PRESSED,
};
class Theme {
public:
virtual void drawProgressBar(BitmapBuffer * dc, coord_t x, coord_t y,
coord_t w, coord_t h, int value, int total) const = 0;
virtual void drawCheckBox(BitmapBuffer* dc, CheckBox* checkBox) const
{
drawCheckBox(dc, checkBox->getValue(), 0, FIELD_PADDING_TOP,
checkBox->hasFocus());
const char* label = checkBox->getLabel();
if (label) dc->drawText(22, FIELD_PADDING_TOP, label);
}
virtual void drawCheckBox(BitmapBuffer * dc, bool checked, coord_t x, coord_t y, bool focus = false) const = 0;
virtual const BitmapBuffer * getIcon(uint8_t index, IconState state) const = 0;
virtual const BitmapBuffer * getIconMask(uint8_t index) const = 0;
virtual TextButton * createTextButton(FormGroup * parent, const rect_t & rect, std::string text, std::function<uint8_t(void)> pressHandler = nullptr, WindowFlags windowFlags = OPAQUE | BUTTON_BACKGROUND) const
{
return new TextButton(parent, rect, text, pressHandler, windowFlags);
}
};
extern Theme * theme;
MenuWindowContent * createMenuWindow(Menu * menu);
DialogWindowContent * createDialogWindow(Dialog * dialog, const rect_t & rect);
@@ -16,48 +16,39 @@
* GNU General Public License for more details.
*/
#include "checkbox.h"
#include "toggleswitch.h"
#include "theme.h"
static void checkbox_event_handler(lv_event_t* e)
static void toggleswitch_event_handler(lv_event_t* e)
{
lv_obj_t* target = lv_event_get_target(e);
CheckBox* cb = (CheckBox*)lv_obj_get_user_data(target);
ToggleSwitch* cb = (ToggleSwitch*)lv_obj_get_user_data(target);
if (cb) cb->setValue(lv_obj_get_state(target) & LV_STATE_CHECKED);
}
CheckBox::CheckBox(Window* parent, const rect_t& rect,
ToggleSwitch::ToggleSwitch(Window* parent, const rect_t& rect,
std::function<uint8_t()> getValue,
std::function<void(uint8_t)> setValue, WindowFlags flags) :
FormField(parent, rect, flags, 0, lv_switch_create),
FormField(parent, rect, flags, 0, etx_switch_create),
_getValue(std::move(getValue)),
_setValue(std::move(setValue))
{
// TODO: migrate to default theme
if (height() > 0)
lv_obj_set_width(lvobj, (lv_coord_t)(height() * 1.7f));
// PART_MAIN
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_DISABLED), LV_PART_MAIN);
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_DISABLED), LV_STATE_FOCUSED);
update();
lv_obj_add_event_cb(lvobj, checkbox_event_handler,
lv_obj_add_event_cb(lvobj, toggleswitch_event_handler,
LV_EVENT_VALUE_CHANGED, this);
}
void CheckBox::update() const
void ToggleSwitch::update() const
{
if (!_getValue) return;
if (_getValue()) lv_obj_add_state(lvobj, LV_STATE_CHECKED);
else lv_obj_clear_state(lvobj, LV_STATE_CHECKED);
}
void CheckBox::onClicked()
void ToggleSwitch::onClicked()
{
// prevent FormField::onClicked()
}
@@ -21,15 +21,15 @@
#include <utility>
#include "form.h"
class CheckBox : public FormField
class ToggleSwitch : public FormField
{
public:
CheckBox(Window* parent, const rect_t& rect,
ToggleSwitch(Window* parent, const rect_t& rect,
std::function<uint8_t()> getValue,
std::function<void(uint8_t)> setValue, WindowFlags flags = 0);
#if defined(DEBUG_WINDOWS)
std::string getName() const override { return "CheckBox"; }
std::string getName() const override { return "ToggleSwitch"; }
#endif
void onClicked() override;
@@ -1,69 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#include "edgetx_table.h"
#define MY_CLASS &table_class
static void table_event(const lv_obj_class_t * class_p, lv_event_t * e);
const lv_obj_class_t table_class = {
.constructor_cb = NULL,
.destructor_cb = NULL,
.event_cb = table_event,
.width_def = LV_SIZE_CONTENT,
.height_def = LV_SIZE_CONTENT,
.base_class = &lv_table_class,
.editable = LV_OBJ_CLASS_EDITABLE_TRUE,
.group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE,
.instance_size = 0,
};
lv_obj_t * table_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;
}
static void table_event(const lv_obj_class_t * class_p, lv_event_t * e)
{
lv_res_t res;
lv_event_code_t code = lv_event_get_code(e);
if (code != LV_EVENT_RELEASED) {
/*Call the ancestor's event handler*/
res = lv_obj_event_base(MY_CLASS, e);
if(res != LV_RES_OK) return;
} else {
lv_obj_t * obj = lv_event_get_target(e);
lv_table_t * table = (lv_table_t *)obj;
/*From lv_table.c: handler for LV_EVENT_RELEASED*/
lv_obj_invalidate(obj);
lv_indev_t* indev = lv_indev_get_act();
lv_obj_t* scroll_obj = lv_indev_get_scroll_obj(indev);
if (table->col_act != LV_TABLE_CELL_NONE &&
table->row_act != LV_TABLE_CELL_NONE && scroll_obj == NULL) {
res = lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL);
if (res != LV_RES_OK) return;
}
}
}
@@ -1,34 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#ifndef EDGETX_TABLE_H
#define EDGETX_TABLE_H
#include <lvgl/lvgl.h>
#ifdef __cplusplus
extern "C" {
#endif
extern const lv_obj_class_t table_class;
lv_obj_t* table_create(lv_obj_t* parent);
#ifdef __cplusplus
};
#endif
#endif
@@ -0,0 +1,46 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#pragma once
#include <lvgl/lvgl.h>
lv_obj_t* window_create(lv_obj_t* parent);
lv_obj_t* etx_form_window_create(lv_obj_t* parent);
lv_obj_t* etx_text_edit_create(lv_obj_t* parent);
lv_obj_t* etx_number_edit_create(lv_obj_t* parent);
lv_obj_t* etx_table_create(lv_obj_t* parent);
lv_obj_t* etx_keyboard_create(lv_obj_t* parent);
lv_obj_t* etx_switch_create(lv_obj_t* parent);
lv_obj_t* etx_slider_create(lv_obj_t* parent);
lv_obj_t* etx_btnmatrix_create(lv_obj_t* parent);
lv_obj_t* etx_button_create(lv_obj_t* parent);
lv_obj_t* etx_vbutton_create(lv_obj_t* parent);
lv_obj_t* etx_choice_create(lv_obj_t* parent);
lv_obj_t* etx_modal_create(lv_obj_t* parent);
lv_obj_t* etx_modal_content_create(lv_obj_t* parent);
lv_obj_t* etx_modal_title_create(lv_obj_t* parent);
lv_obj_t* etx_bar_create(lv_obj_t* parent);
lv_obj_t* input_mix_line_create(lv_obj_t* parent);
lv_obj_t* input_mix_group_create(lv_obj_t* parent);
-44
View File
@@ -1,44 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 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;
}
-35
View File
@@ -1,35 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#ifndef FIELD_EDIT_H
#define FIELD_EDIT_H
#include <lvgl/lvgl.h>
#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
@@ -1,40 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 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;
}
@@ -1,35 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#ifndef FIELD_EDIT_H
#define FIELD_EDIT_H
#include <lvgl/lvgl.h>
#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
-37
View File
@@ -1,37 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#include "simple_btn.h"
#define MY_CLASS &simple_btn_class
const lv_obj_class_t simple_btn_class = {
.width_def = LV_DPI_DEF,
.height_def = LV_DPI_DEF,
.group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE,
.instance_size = sizeof(lv_btn_t),
.base_class = &lv_btn_class,
};
lv_obj_t* simple_btn_create(lv_obj_t* parent)
{
LV_LOG_INFO("begin");
lv_obj_t * obj = lv_obj_class_create_obj(MY_CLASS, parent);
lv_obj_class_init_obj(obj);
return obj;
}
-35
View File
@@ -1,35 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#ifndef SIMPLE_BTN_H
#define SIMPLE_BTN_H
#include <lvgl/lvgl.h>
#ifdef __cplusplus
extern "C" {
#endif
extern const lv_obj_class_t simple_btn_class;
lv_obj_t* simple_btn_create(lv_obj_t* parent);
#ifdef __cplusplus
};
#endif
#endif
@@ -1,51 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#include "window_base.h"
void window_event_cb(lv_event_t* e);
#define MY_CLASS &window_base_class
static void window_base_event(const lv_obj_class_t* class_p, lv_event_t* e);
const lv_obj_class_t window_base_class = {
.base_class = &lv_obj_class,
.event_cb = window_base_event,
.width_def = LV_DPI_DEF,
.height_def = LV_DPI_DEF,
.editable = LV_OBJ_CLASS_EDITABLE_FALSE,
.group_def = LV_OBJ_CLASS_GROUP_DEF_FALSE,
.instance_size = sizeof(lv_obj_t)
};
static void window_base_event(const lv_obj_class_t* class_p, lv_event_t* e)
{
/* Call the ancestor's event handler */
lv_res_t res = lv_obj_event_base(MY_CLASS, e);
if (res != LV_RES_OK) return;
window_event_cb(e);
}
lv_obj_t* window_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;
}
@@ -1,35 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* libopenui - https://github.com/opentx/libopenui
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#ifndef WINDOW_BASE_H
#define WINDOW_BASE_H
#include <lvgl/lvgl.h>
#ifdef __cplusplus
extern "C" {
#endif
extern const lv_obj_class_t window_base_class;
lv_obj_t* window_create(lv_obj_t* parent);
#ifdef __cplusplus
};
#endif
#endif
+6 -179
View File
@@ -20,8 +20,6 @@
#include "touch.h"
#include "mainwindow.h"
#include "widgets/window_base.h"
std::list<Window *> Window::trash;
extern lv_obj_t *virtual_kb;
@@ -73,10 +71,6 @@ extern "C" void window_event_cb(lv_event_t * e)
TRACE_WINDOWS("PRESSED: %s", window->getWindowDebugString().c_str());
lv_indev_t *click_source = (lv_indev_t *)lv_event_get_param(e);
// if(lv_indev_get_type(click_source) == LV_INDEV_TYPE_KEYPAD ||
// lv_indev_get_type(click_source) == LV_INDEV_TYPE_ENCODER) {
// return;
// }
lv_area_t obj_coords;
lv_obj_get_coords(target, &obj_coords);
@@ -160,10 +154,12 @@ Window::Window(Window *parent, const rect_t &rect, WindowFlags windowFlags,
lv_obj_set_user_data(lvobj, this);
if (rect.w || rect.h) {
if (rect.x || rect.y)
lv_obj_set_pos(lvobj, rect.x, rect.y);
lv_obj_set_size(lvobj, rect.w, rect.h);
}
if (rect.w)
lv_obj_set_width(lvobj, rect.w);
if (rect.h)
lv_obj_set_height(lvobj, rect.h);
if (windowFlags & OPAQUE) {
lv_obj_set_style_bg_opa(lvobj, LV_OPA_MAX, LV_PART_MAIN);
@@ -273,16 +269,7 @@ void Window::setTextFlags(LcdFlags flags)
if (!lvobj) return;
// lv integration for colors
auto textColor = COLOR_VAL(flags);
auto r = GET_RED(textColor), g = GET_GREEN(textColor),
b = GET_BLUE(textColor);
lv_obj_set_style_text_color(lvobj, lv_color_make(r, g, b), LV_PART_MAIN);
// // rco: shouldn't this be done via 'setTextFlags()' on the children?
// for (uint32_t i = 0; i < lv_obj_get_child_cnt(lvobj); i++) {
// auto child = lv_obj_get_child(lvobj, i);
// lv_obj_set_style_text_color(child, lv_color_make(r, g, b), LV_PART_MAIN);
// }
lv_obj_set_style_text_color(lvobj, makeLvColor(textFlags), LV_PART_MAIN);
}
void Window::attach(Window *newParent)
@@ -393,122 +380,6 @@ void Window::padColumn(coord_t pad)
lv_obj_set_style_pad_column(lvobj, pad, 0);
}
bool Window::hasOpaqueRect(const rect_t & testRect) const
{
if (!rect.contains(testRect))
return false;
if (windowFlags & OPAQUE) {
return true;
}
rect_t relativeRect = {testRect.x - rect.x, testRect.y - rect.y, testRect.w, testRect.h};
for (auto child: children) {
if (child->hasOpaqueRect(relativeRect))
return true;
}
return false;
}
void Window::fullPaint(BitmapBuffer * dc)
{
if(lvobj != nullptr)
lv_obj_invalidate(lvobj);
bool paintNeeded = true;
std::list<Window *>::iterator firstChild;
coord_t xmin, xmax, ymin, ymax;
dc->getClippingRect(xmin, xmax, ymin, ymax);
coord_t x = dc->getOffsetX();
coord_t y = dc->getOffsetY();
if (windowFlags & PAINT_CHILDREN_FIRST) {
paintChildren(dc, children.begin());
dc->setOffset(x, y);
dc->setClippingRect(xmin, xmax, ymin, ymax);
}
else {
firstChild = children.end();
rect_t relativeRect = {xmin - x, ymin - y, xmax - xmin, ymax - ymin};
while (firstChild != children.begin()) {
auto child = *(--firstChild);
if (child->hasOpaqueRect(relativeRect)) {
paintNeeded = false;
break;
}
}
}
if (paintNeeded) {
TRACE_WINDOWS_INDENT("%s%s", getWindowDebugString().c_str(), hasFocus() ? " (*)" : "");
paint(dc);
#if defined(WINDOWS_INSPECT_BORDER_COLOR)
dc->drawSolidRect(0, 0, width(), height(), 1, WINDOWS_INSPECT_BORDER_COLOR);
#endif
}
else {
TRACE_WINDOWS_INDENT("%s (skipped)", getWindowDebugString().c_str());
}
if (!(windowFlags & PAINT_CHILDREN_FIRST)) {
paintChildren(dc, firstChild);
}
}
bool Window::isChildFullSize(const Window * child) const
{
return child->top() == 0 && child->height() == height() && child->left() == 0 && child->width() == width();
}
bool Window::isChildVisible(const Window * window) const
{
for (auto rit = children.rbegin(); rit != children.rend(); rit++) {
auto child = *rit;
if (child == window) {
return true;
}
if ((child->getWindowFlags() & OPAQUE) & isChildFullSize(child)) {
return false;
}
}
return false;
}
void Window::paintChildren(BitmapBuffer * dc, std::list<Window *>::iterator it)
{
coord_t x = dc->getOffsetX();
coord_t y = dc->getOffsetY();
coord_t xmin, xmax, ymin, ymax;
dc->getClippingRect(xmin, xmax, ymin, ymax);
for (; it != children.end(); it++) {
auto child = *it;
coord_t child_xmin = x + child->rect.x;
if (child_xmin >= xmax)
continue;
coord_t child_ymin = y + child->rect.y;
if (child_ymin >= ymax)
continue;
coord_t child_xmax = child_xmin + child->rect.w;
if (child_xmax <= xmin)
continue;
coord_t child_ymax = child_ymin + child->rect.h;
if (child_ymax <= ymin)
continue;
// dc->setOffset(x + child->rect.x - child->scrollPositionX,
// y + child->rect.y - child->scrollPositionY);
dc->setClippingRect(
max(xmin, x + child->rect.left()), min(xmax, x + child->rect.right()),
max(ymin, y + child->rect.top()), min(ymax, y + child->rect.bottom()));
child->fullPaint(dc);
}
}
void Window::bringToTop()
{
attach(parent); // does a detach + attach
@@ -558,52 +429,8 @@ bool Window::onTouchEnd(coord_t x, coord_t y)
if (parent && !(windowFlags & OPAQUE)) return parent->onTouchEnd(x, y);
return true;
}
bool Window::onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY)
{
// TODO: this is not used anymore: REMOVE
// for (auto it = children.rbegin(); it != children.rend(); ++it) {
// auto child = *it;
// if (child->rect.contains(startX, startY)) {
// if (child->onTouchSlide(x - child->rect.x, y - child->rect.y, startX - child->rect.x, startY - child->rect.y, slideX, slideY)) {
// return true;
// }
// }
// }
// return false;
return true;
}
#endif
coord_t Window::adjustHeight()
{
coord_t old = rect.h;
if (lvobj) {
lv_obj_set_height(lvobj, LV_SIZE_CONTENT);
lv_obj_update_layout(lvobj);
rect.h = lv_obj_get_height(lvobj);
lv_obj_set_style_height(lvobj, rect.h, LV_PART_MAIN);
}
return rect.h - old;
}
void Window::moveWindowsTop(coord_t y, coord_t delta)
{
if (getWindowFlags() & FORWARD_SCROLL) {
parent->moveWindowsTop(bottom(), delta);
}
for (auto child: children) {
if (child->rect.y >= y) {
child->setTop(child->top() + delta);
invalidate();
}
}
}
void Window::updateSize()
{
lv_obj_set_height(lvobj, LV_SIZE_CONTENT);
+13 -77
View File
@@ -28,10 +28,9 @@
#include "bitmapbuffer.h"
#include "libopenui_defines.h"
#include "libopenui_helpers.h"
#include "libopenui_config.h"
#include "opentx_helpers.h"
#include "widgets/window_base.h"
#include "widgets/etx_obj_create.h"
#include "LvglWrapper.h"
@@ -42,43 +41,26 @@ typedef uint32_t WindowFlags;
#undef TRANSPARENT
#endif
constexpr int INFINITE_HEIGHT = INT32_MAX;
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 = 0,
// SET_FOCUS_FORWARD = 1,
// SET_FOCUS_BACKWARD = 2,
// SET_FOCUS_FIRST = 3,
// SET_FOCUS_NO_SCROLL= 4
// };
constexpr WindowFlags NO_FOCUS = 1u << 2u;
constexpr WindowFlags REFRESH_ALWAYS = 1u << 3u;
constexpr WindowFlags WINDOW_FLAGS_LAST = REFRESH_ALWAYS;
typedef lv_obj_t *(*LvglCreate)(lv_obj_t *);
extern "C" void window_event_cb(lv_event_t * e);
class Window
{
friend class GridLayout;
friend void window_event_cb(lv_event_t * e);
friend void window_event_cb(lv_event_t * e);
public:
Window(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0,
LcdFlags textFlags = 0, LvglCreate objConstruct = nullptr);
Window(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0,
LcdFlags textFlags = 0, LvglCreate objConstruct = nullptr);
Window(Window *parent, lv_obj_t* lvobj);
Window(Window *parent, lv_obj_t* lvobj);
virtual ~Window();
virtual ~Window();
#if defined(DEBUG_WINDOWS)
virtual std::string getName() const;
@@ -89,11 +71,6 @@ class Window
Window *getParent() const { return parent; }
bool isChild(Window *window) const
{
return window == this || (parent && parent->isChild(window));
}
Window *getFullScreenWindow();
WindowFlags getWindowFlags() const { return windowFlags; }
@@ -108,8 +85,6 @@ class Window
typedef std::function<void(bool)> FocusHandler;
void setFocusHandler(FocusHandler h) { focusHandler = std::move(h); }
const std::list<Window *> getChildren() { return children; }
void clear();
virtual void deleteLater(bool detach = true, bool trash = true);
@@ -120,9 +95,9 @@ class Window
rect = value;
lv_obj_enable_style_refresh(false);
lv_obj_set_pos(lvobj, rect.x, rect.y);
lv_obj_set_width(lvobj, rect.w);
lv_obj_set_size(lvobj, rect.w, rect.h);
lv_obj_enable_style_refresh(true);
lv_obj_set_height(lvobj, rect.h);
lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY);
}
void setWidth(coord_t value)
@@ -131,17 +106,10 @@ class Window
lv_obj_set_width(lvobj, rect.w);
}
void setWindowCentered()
{
rect.x = (parent->width() - width()) / 2;
rect.y = (parent->height() - height()) / 2;
lv_obj_set_pos(lvobj, rect.x, rect.y);
}
void setHeight(coord_t value)
{
rect.h = value;
if (lvobj != nullptr) lv_obj_set_height(lvobj, rect.h);
lv_obj_set_height(lvobj, rect.h);
}
void setLeft(coord_t x)
@@ -200,22 +168,10 @@ class Window
void padRow(coord_t pad);
void padColumn(coord_t pad);
bool isChildVisible(const Window * window) const;
bool isChildFullSize(const Window * window) const;
bool isVisible() const
{
return parent && parent->isChildVisible(this);
}
virtual void onEvent(event_t event);
virtual void onClicked();
virtual void onCancel();
coord_t adjustHeight();
void moveWindowsTop(coord_t y, coord_t delta);
virtual void updateSize();
void invalidate()
@@ -269,25 +225,5 @@ class Window
void removeChild(Window * window);
virtual void invalidate(const rect_t & rect);
void fullPaint(BitmapBuffer * dc);
void paintChildren(BitmapBuffer * dc, std::list<Window *>::iterator it);
virtual void onFocusLost()
{
TRACE_WINDOWS("%s onFocusLost()", getWindowDebugString().c_str());
if (focusHandler) {
focusHandler(false);
}
invalidate();
}
#if defined(HARDWARE_TOUCH)
virtual bool onTouchSlide(coord_t x, coord_t y, coord_t startX,
coord_t startY, coord_t slideX, coord_t slideY);
#endif
bool hasOpaqueRect(const rect_t & testRect) const;
};