From 69338ab0ab4ffd9d69296a50c0692208241083b3 Mon Sep 17 00:00:00 2001 From: philmoz Date: Fri, 4 Aug 2023 11:04:54 +1000 Subject: [PATCH] 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. --- radio/src/audio.h | 2 + radio/src/datastructs_private.h | 2 +- radio/src/gui/128x64/lcd.h | 4 - radio/src/gui/212x64/lcd.h | 4 - radio/src/gui/colorlcd/CMakeLists.txt | 6 - radio/src/gui/colorlcd/LvglWrapper.cpp | 5 +- radio/src/gui/colorlcd/LvglWrapper.h | 3 + radio/src/gui/colorlcd/access_settings.cpp | 14 +- radio/src/gui/colorlcd/afhds3_options.cpp | 12 +- radio/src/gui/colorlcd/afhds3_options.h | 2 +- radio/src/gui/colorlcd/bitmaps.cpp | 2 +- radio/src/gui/colorlcd/channel_range.cpp | 2 +- radio/src/gui/colorlcd/channel_range.h | 2 +- radio/src/gui/colorlcd/color_editor.cpp | 10 +- radio/src/gui/colorlcd/color_editor.h | 2 +- radio/src/gui/colorlcd/color_picker.cpp | 10 +- radio/src/gui/colorlcd/colors.h | 37 + radio/src/gui/colorlcd/confirm_dialog.cpp | 3 +- radio/src/gui/colorlcd/crossfire_settings.cpp | 2 +- radio/src/gui/colorlcd/crossfire_settings.h | 2 +- radio/src/gui/colorlcd/curve.cpp | 4 +- radio/src/gui/colorlcd/curve_param.cpp | 2 +- radio/src/gui/colorlcd/curve_param.h | 3 +- radio/src/gui/colorlcd/curveedit.cpp | 145 +- radio/src/gui/colorlcd/curveedit.h | 15 +- radio/src/gui/colorlcd/custom_failsafe.cpp | 6 +- radio/src/gui/colorlcd/draw_functions.cpp | 4 +- radio/src/gui/colorlcd/fab_button.cpp | 5 +- radio/src/gui/colorlcd/fab_button.h | 4 +- radio/src/gui/colorlcd/file_carosell.cpp | 4 +- radio/src/gui/colorlcd/file_carosell.h | 2 +- radio/src/gui/colorlcd/file_preview.cpp | 2 +- radio/src/gui/colorlcd/flysky_settings.cpp | 12 +- radio/src/gui/colorlcd/flysky_settings.h | 4 +- radio/src/gui/colorlcd/fm_matrix.cpp | 15 +- radio/src/gui/colorlcd/fm_matrix.h | 2 +- radio/src/gui/colorlcd/fonts.cpp | 2 +- radio/src/gui/colorlcd/fullscreen_dialog.cpp | 8 +- radio/src/gui/colorlcd/gui.h | 1 - radio/src/gui/colorlcd/hw_bluetooth.cpp | 4 +- radio/src/gui/colorlcd/hw_bluetooth.h | 2 +- radio/src/gui/colorlcd/hw_extmodule.cpp | 4 +- radio/src/gui/colorlcd/hw_extmodule.h | 2 +- radio/src/gui/colorlcd/hw_inputs.cpp | 24 +- radio/src/gui/colorlcd/hw_inputs.h | 7 +- radio/src/gui/colorlcd/hw_intmodule.cpp | 8 +- radio/src/gui/colorlcd/hw_intmodule.h | 2 +- radio/src/gui/colorlcd/hw_serial.cpp | 6 +- radio/src/gui/colorlcd/hw_serial.h | 2 +- radio/src/gui/colorlcd/input_mix_group.cpp | 2 - radio/src/gui/colorlcd/input_source.cpp | 2 +- radio/src/gui/colorlcd/input_source.h | 4 +- radio/src/gui/colorlcd/keyboard_curve.cpp | 94 - radio/src/gui/colorlcd/keyboard_curve.h | 60 - .../colorlcd/layouts/layout_factory_impl.cpp | 2 +- radio/src/gui/colorlcd/layouts/sliders.cpp | 60 +- radio/src/gui/colorlcd/layouts/sliders.h | 14 +- .../src/gui/colorlcd/layouts/topbar_impl.cpp | 3 +- radio/src/gui/colorlcd/layouts/trims.cpp | 35 +- radio/src/gui/colorlcd/libopenui.h | 7 +- radio/src/gui/colorlcd/list_line_button.cpp | 2 - .../colorlcd/lvgl_widgets/input_mix_group.c | 35 - .../colorlcd/lvgl_widgets/input_mix_group.h | 32 - .../colorlcd/lvgl_widgets/input_mix_line.c | 34 - .../colorlcd/lvgl_widgets/input_mix_line.h | 32 - radio/src/gui/colorlcd/lz4_bitmaps.cpp | 2 +- radio/src/gui/colorlcd/material-backup.cpp | 200 -- radio/src/gui/colorlcd/menu_model.cpp | 2 +- radio/src/gui/colorlcd/menus.h | 2 +- radio/src/gui/colorlcd/mixer_edit.h | 2 +- radio/src/gui/colorlcd/mixer_edit_adv.cpp | 18 +- radio/src/gui/colorlcd/mixer_edit_adv.h | 2 +- radio/src/gui/colorlcd/model_curves.cpp | 9 +- radio/src/gui/colorlcd/model_flightmodes.cpp | 8 +- radio/src/gui/colorlcd/model_gvars.cpp | 5 +- radio/src/gui/colorlcd/model_inputs.cpp | 2 +- .../gui/colorlcd/model_logical_switches.cpp | 3 +- .../src/gui/colorlcd/model_mixer_scripts.cpp | 13 +- radio/src/gui/colorlcd/model_mixes.cpp | 4 +- radio/src/gui/colorlcd/model_outputs.cpp | 2 +- radio/src/gui/colorlcd/model_select.cpp | 55 +- radio/src/gui/colorlcd/model_select.h | 20 - radio/src/gui/colorlcd/model_setup.cpp | 12 +- radio/src/gui/colorlcd/model_telemetry.cpp | 43 +- radio/src/gui/colorlcd/model_templates.cpp | 2 - radio/src/gui/colorlcd/model_usbjoystick.cpp | 78 +- radio/src/gui/colorlcd/model_usbjoystick.h | 2 +- radio/src/gui/colorlcd/module_setup.cpp | 25 +- radio/src/gui/colorlcd/mpm_settings.cpp | 58 +- radio/src/gui/colorlcd/mpm_settings.h | 9 +- radio/src/gui/colorlcd/multi_rfprotos.cpp | 27 +- radio/src/gui/colorlcd/multi_rfprotos.h | 8 +- radio/src/gui/colorlcd/output_edit.cpp | 2 +- radio/src/gui/colorlcd/page.cpp | 11 +- radio/src/gui/colorlcd/page.h | 2 +- radio/src/gui/colorlcd/ppm_settings.cpp | 2 +- radio/src/gui/colorlcd/ppm_settings.h | 2 +- radio/src/gui/colorlcd/preflight_checks.cpp | 84 +- radio/src/gui/colorlcd/preview_window.h | 40 +- radio/src/gui/colorlcd/pxx1_settings.cpp | 2 +- radio/src/gui/colorlcd/pxx1_settings.h | 2 +- radio/src/gui/colorlcd/radio_calibration.cpp | 2 +- .../colorlcd/radio_ghost_module_config.cpp | 3 +- radio/src/gui/colorlcd/radio_hardware.cpp | 32 +- radio/src/gui/colorlcd/radio_sdmanager.cpp | 14 +- radio/src/gui/colorlcd/radio_setup.cpp | 104 +- .../gui/colorlcd/radio_spectrum_analyser.cpp | 2 +- radio/src/gui/colorlcd/radio_theme.cpp | 6 +- radio/src/gui/colorlcd/radio_trainer.cpp | 8 +- radio/src/gui/colorlcd/screen_setup.cpp | 56 +- radio/src/gui/colorlcd/screen_setup.h | 2 +- radio/src/gui/colorlcd/select_fab_button.cpp | 2 +- radio/src/gui/colorlcd/select_fab_button.h | 2 +- .../src/gui/colorlcd/select_fab_carousel.cpp | 2 +- radio/src/gui/colorlcd/select_fab_carousel.h | 2 +- radio/src/gui/colorlcd/sourcechoice.cpp | 3 +- radio/src/gui/colorlcd/sourcechoice.h | 4 +- radio/src/gui/colorlcd/special_functions.cpp | 21 +- radio/src/gui/colorlcd/switch_warn_dialog.h | 1 - radio/src/gui/colorlcd/switchchoice.cpp | 3 +- radio/src/gui/colorlcd/switchchoice.h | 4 +- radio/src/gui/colorlcd/tabsgroup.cpp | 14 +- radio/src/gui/colorlcd/tabsgroup.h | 4 +- radio/src/gui/colorlcd/theme.cpp | 56 +- radio/src/gui/colorlcd/theme.h | 38 +- radio/src/gui/colorlcd/theme_manager.cpp | 21 +- radio/src/gui/colorlcd/themes/480_default.cpp | 176 +- .../src/gui/colorlcd/themes/etx_lv_theme.cpp | 1741 +++++++---------- radio/src/gui/colorlcd/themes/etx_lv_theme.h | 39 +- radio/src/gui/colorlcd/themes/flysky.cpp | 439 ----- radio/src/gui/colorlcd/throttle_params.cpp | 4 +- radio/src/gui/colorlcd/timeedit.cpp | 19 - radio/src/gui/colorlcd/timer_setup.cpp | 9 +- radio/src/gui/colorlcd/topbar.cpp | 4 +- radio/src/gui/colorlcd/trainer_bluetooth.cpp | 2 +- radio/src/gui/colorlcd/trainer_bluetooth.h | 2 +- radio/src/gui/colorlcd/trainer_setup.cpp | 12 +- radio/src/gui/colorlcd/trims_setup.cpp | 2 +- radio/src/gui/colorlcd/view_about.cpp | 8 +- .../gui/colorlcd/view_logical_switches.cpp | 2 +- radio/src/gui/colorlcd/view_main.cpp | 4 +- .../src/gui/colorlcd/view_main_decoration.cpp | 78 +- radio/src/gui/colorlcd/view_main_decoration.h | 5 +- radio/src/gui/colorlcd/view_main_menu.cpp | 2 +- radio/src/gui/colorlcd/view_statistics.cpp | 6 +- radio/src/gui/colorlcd/view_text.cpp | 1 - radio/src/gui/colorlcd/widget.cpp | 2 +- radio/src/gui/colorlcd/widget_settings.cpp | 2 +- .../colorlcd/widgets/widgets_container_impl.h | 2 +- radio/src/gui/colorlcd/widgets_container.h | 2 +- radio/src/gui/colorlcd/widgets_setup.cpp | 6 +- radio/src/gui/colorlcd/widgets_setup.h | 2 +- radio/src/keys.h | 1 - radio/src/lua/api_colorlcd.cpp | 2 +- radio/src/lua/lua_api.h | 1 - radio/src/lv_conf.h | 10 +- radio/src/main.cpp | 2 +- radio/src/opentx.cpp | 4 +- radio/src/opentx_helpers.h | 45 +- radio/src/opentx_types.h | 66 +- radio/src/storage/sdcard_common.cpp | 2 +- radio/src/targets/horus/board.h | 5 + radio/src/targets/horus/lcd_driver.cpp | 1 - radio/src/targets/horus/libopenui_config.h | 98 +- radio/src/targets/nv14/board.h | 4 + radio/src/targets/nv14/lcd_driver.cpp | 2 - radio/src/targets/nv14/libopenui_config.h | 96 +- .../thirdparty/libopenui/src/CMakeLists.txt | 17 +- .../thirdparty/libopenui/src/basenumberedit.h | 222 --- .../thirdparty/libopenui/src/bitmapbuffer.cpp | 4 +- .../thirdparty/libopenui/src/bitmapbuffer.h | 5 +- .../thirdparty/libopenui/src/bufferedwindow.h | 123 -- radio/src/thirdparty/libopenui/src/button.cpp | 17 +- radio/src/thirdparty/libopenui/src/button.h | 29 +- .../libopenui/src/button_matrix.cpp | 38 +- .../thirdparty/libopenui/src/button_matrix.h | 35 +- .../src/thirdparty/libopenui/src/carousel.cpp | 67 - radio/src/thirdparty/libopenui/src/carousel.h | 150 -- radio/src/thirdparty/libopenui/src/choice.cpp | 61 +- radio/src/thirdparty/libopenui/src/choice.h | 23 +- .../src/thirdparty/libopenui/src/choiceex.cpp | 48 - radio/src/thirdparty/libopenui/src/choiceex.h | 55 - radio/src/thirdparty/libopenui/src/dialog.cpp | 44 +- radio/src/thirdparty/libopenui/src/dialog.h | 24 +- radio/src/thirdparty/libopenui/src/font.h | 2 +- radio/src/thirdparty/libopenui/src/form.cpp | 35 +- radio/src/thirdparty/libopenui/src/form.h | 113 +- .../src/thirdparty/libopenui/src/gridlayout.h | 121 -- .../libopenui/src/keyboard_base.cpp | 5 +- .../libopenui/src/libopenui_compat.h | 20 - .../libopenui/src/libopenui_defines.h | 103 +- .../libopenui/src/libopenui_depends.h | 56 - .../libopenui/src/libopenui_file.cpp | 1 - .../thirdparty/libopenui/src/libopenui_file.h | 1 - .../libopenui/src/libopenui_helpers.cpp | 20 - .../libopenui/src/libopenui_helpers.h | 96 - .../libopenui/src/libopenui_types.h | 74 - .../thirdparty/libopenui/src/mainwindow.cpp | 19 +- .../src/thirdparty/libopenui/src/mainwindow.h | 22 - radio/src/thirdparty/libopenui/src/menu.cpp | 4 +- .../thirdparty/libopenui/src/menutoolbar.cpp | 3 +- .../thirdparty/libopenui/src/modal_window.cpp | 18 +- .../thirdparty/libopenui/src/numberedit.cpp | 20 +- .../src/thirdparty/libopenui/src/numberedit.h | 191 +- .../src/thirdparty/libopenui/src/progress.cpp | 16 +- radio/src/thirdparty/libopenui/src/progress.h | 18 +- radio/src/thirdparty/libopenui/src/roller.h | 174 -- radio/src/thirdparty/libopenui/src/slider.cpp | 78 +- radio/src/thirdparty/libopenui/src/slider.h | 6 +- radio/src/thirdparty/libopenui/src/static.cpp | 5 - radio/src/thirdparty/libopenui/src/static.h | 53 +- radio/src/thirdparty/libopenui/src/table.cpp | 3 +- radio/src/thirdparty/libopenui/src/table.h | 2 +- .../src/thirdparty/libopenui/src/textedit.cpp | 36 +- radio/src/thirdparty/libopenui/src/textedit.h | 1 - radio/src/thirdparty/libopenui/src/theme.h | 63 - .../src/{checkbox.cpp => toggleswitch.cpp} | 25 +- .../src/{checkbox.h => toggleswitch.h} | 6 +- .../libopenui/src/widgets/edgetx_table.c | 69 - .../libopenui/src/widgets/edgetx_table.h | 34 - .../libopenui/src/widgets/etx_obj_create.h | 46 + .../libopenui/src/widgets/field_edit.c | 44 - .../libopenui/src/widgets/field_edit.h | 35 - .../libopenui/src/widgets/number_edit.c | 40 - .../libopenui/src/widgets/number_edit.h | 35 - .../libopenui/src/widgets/simple_btn.c | 37 - .../libopenui/src/widgets/simple_btn.h | 35 - .../libopenui/src/widgets/window_base.c | 51 - .../libopenui/src/widgets/window_base.h | 35 - radio/src/thirdparty/libopenui/src/window.cpp | 185 +- radio/src/thirdparty/libopenui/src/window.h | 90 +- 231 files changed, 2143 insertions(+), 5886 deletions(-) delete mode 100644 radio/src/gui/colorlcd/keyboard_curve.cpp delete mode 100644 radio/src/gui/colorlcd/keyboard_curve.h delete mode 100644 radio/src/gui/colorlcd/lvgl_widgets/input_mix_group.c delete mode 100644 radio/src/gui/colorlcd/lvgl_widgets/input_mix_group.h delete mode 100644 radio/src/gui/colorlcd/lvgl_widgets/input_mix_line.c delete mode 100644 radio/src/gui/colorlcd/lvgl_widgets/input_mix_line.h delete mode 100644 radio/src/gui/colorlcd/material-backup.cpp delete mode 100644 radio/src/gui/colorlcd/themes/flysky.cpp delete mode 100644 radio/src/thirdparty/libopenui/src/basenumberedit.h delete mode 100644 radio/src/thirdparty/libopenui/src/bufferedwindow.h delete mode 100644 radio/src/thirdparty/libopenui/src/carousel.cpp delete mode 100644 radio/src/thirdparty/libopenui/src/carousel.h delete mode 100644 radio/src/thirdparty/libopenui/src/choiceex.cpp delete mode 100644 radio/src/thirdparty/libopenui/src/choiceex.h delete mode 100644 radio/src/thirdparty/libopenui/src/gridlayout.h delete mode 100644 radio/src/thirdparty/libopenui/src/libopenui_compat.h delete mode 100644 radio/src/thirdparty/libopenui/src/libopenui_depends.h delete mode 100644 radio/src/thirdparty/libopenui/src/libopenui_helpers.cpp delete mode 100644 radio/src/thirdparty/libopenui/src/libopenui_helpers.h delete mode 100644 radio/src/thirdparty/libopenui/src/libopenui_types.h delete mode 100644 radio/src/thirdparty/libopenui/src/roller.h delete mode 100644 radio/src/thirdparty/libopenui/src/theme.h rename radio/src/thirdparty/libopenui/src/{checkbox.cpp => toggleswitch.cpp} (64%) rename radio/src/thirdparty/libopenui/src/{checkbox.h => toggleswitch.h} (90%) delete mode 100644 radio/src/thirdparty/libopenui/src/widgets/edgetx_table.c delete mode 100644 radio/src/thirdparty/libopenui/src/widgets/edgetx_table.h create mode 100644 radio/src/thirdparty/libopenui/src/widgets/etx_obj_create.h delete mode 100644 radio/src/thirdparty/libopenui/src/widgets/field_edit.c delete mode 100644 radio/src/thirdparty/libopenui/src/widgets/field_edit.h delete mode 100644 radio/src/thirdparty/libopenui/src/widgets/number_edit.c delete mode 100644 radio/src/thirdparty/libopenui/src/widgets/number_edit.h delete mode 100644 radio/src/thirdparty/libopenui/src/widgets/simple_btn.c delete mode 100644 radio/src/thirdparty/libopenui/src/widgets/simple_btn.h delete mode 100644 radio/src/thirdparty/libopenui/src/widgets/window_base.c delete mode 100644 radio/src/thirdparty/libopenui/src/widgets/window_base.h diff --git a/radio/src/audio.h b/radio/src/audio.h index bbc06d488cc..44a0deac9fd 100644 --- a/radio/src/audio.h +++ b/radio/src/audio.h @@ -559,6 +559,8 @@ void audioTask(void * pdata); #define AUDIO_ERROR_MESSAGE(e) audioEvent(e) #define AUDIO_TIMER_MINUTE(t) playDuration(t, 0, 0) +void onKeyError(); + void audioKeyPress(); void audioKeyError(); void audioTrimPress(int value); diff --git a/radio/src/datastructs_private.h b/radio/src/datastructs_private.h index afc53777225..e863330a8e9 100644 --- a/radio/src/datastructs_private.h +++ b/radio/src/datastructs_private.h @@ -834,7 +834,7 @@ PACK(struct TrainerData { #define THEME_NAME_LEN 8 #define THEME_DATA \ NOBACKUP(char themeName[THEME_NAME_LEN]); \ - NOBACKUP(OpenTxTheme::PersistentData themeData); + NOBACKUP(EdgeTxTheme::PersistentData themeData); #else #define THEME_DATA #endif diff --git a/radio/src/gui/128x64/lcd.h b/radio/src/gui/128x64/lcd.h index 1dc5e86695c..6862c8f5a3f 100644 --- a/radio/src/gui/128x64/lcd.h +++ b/radio/src/gui/128x64/lcd.h @@ -27,10 +27,6 @@ #include "opentx_types.h" #include "board.h" -typedef uint32_t LcdFlags; -typedef uint8_t pixel_t; -typedef int coord_t; - #define BOX_WIDTH 23 #define CENTER #define CENTER_OFS 0 diff --git a/radio/src/gui/212x64/lcd.h b/radio/src/gui/212x64/lcd.h index 99b55dd3a6c..fd4a4254ca4 100644 --- a/radio/src/gui/212x64/lcd.h +++ b/radio/src/gui/212x64/lcd.h @@ -27,10 +27,6 @@ #include "opentx_types.h" #include "board.h" -typedef uint32_t LcdFlags; -typedef uint8_t pixel_t; -typedef int coord_t; - #define BOX_WIDTH 31 #define CENTER "\015" #define CENTER_OFS (7*FW-FW/2) diff --git a/radio/src/gui/colorlcd/CMakeLists.txt b/radio/src/gui/colorlcd/CMakeLists.txt index c2d05b98b12..f84f13302e7 100644 --- a/radio/src/gui/colorlcd/CMakeLists.txt +++ b/radio/src/gui/colorlcd/CMakeLists.txt @@ -216,12 +216,6 @@ add_gui_src(input_mix_button.cpp) add_gui_src(channel_bar.cpp) add_gui_src(list_line_button.cpp) -add_gui_src(lvgl_widgets/input_mix_line.c) -add_gui_src(lvgl_widgets/input_mix_group.c) - -if(HARDWARE_TOUCH) - add_gui_src(keyboard_curve.cpp) -endif() if(USBJ_EX) add_gui_src(model_usbjoystick.cpp) diff --git a/radio/src/gui/colorlcd/LvglWrapper.cpp b/radio/src/gui/colorlcd/LvglWrapper.cpp index 2a599b1a3dd..6c7109feb51 100644 --- a/radio/src/gui/colorlcd/LvglWrapper.cpp +++ b/radio/src/gui/colorlcd/LvglWrapper.cpp @@ -24,7 +24,6 @@ #include "LvglWrapper.h" #include "themes/etx_lv_theme.h" -#include "widgets/field_edit.h" #include "view_main.h" @@ -277,12 +276,10 @@ static void rotaryDriverRead(lv_indev_drv_t *drv, lv_indev_data_t *data) } } -// libopenui_depends.h int8_t rotaryEncoderGetAccel() { return _rotary_enc_accel; } #else // !defined(ROTARY_ENCODER_NAVIGATION) -// libopenui_depends.h int8_t rotaryEncoderGetAccel() { return 0; } #endif // defined(ROTARY_ENCODER_NAVIGATION) @@ -342,7 +339,7 @@ void initLvglTheme() /* Initialize the ETX theme */ lv_theme_t* th = etx_lv_theme_init( NULL, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), - false, LV_FONT_DEFAULT); + LV_FONT_DEFAULT); /* Assign the theme to the current display*/ lv_disp_set_theme(NULL, th); diff --git a/radio/src/gui/colorlcd/LvglWrapper.h b/radio/src/gui/colorlcd/LvglWrapper.h index 6b5f0887b31..d82c86f7f95 100644 --- a/radio/src/gui/colorlcd/LvglWrapper.h +++ b/radio/src/gui/colorlcd/LvglWrapper.h @@ -55,4 +55,7 @@ class LvglWrapper static void runNested(); }; +// multiplication factor between 0 and 25 +int8_t rotaryEncoderGetAccel(); + #endif // _LVGLWRAPPER_H_ diff --git a/radio/src/gui/colorlcd/access_settings.cpp b/radio/src/gui/colorlcd/access_settings.cpp index 2e26ea264ec..0f087a704e1 100644 --- a/radio/src/gui/colorlcd/access_settings.cpp +++ b/radio/src/gui/colorlcd/access_settings.cpp @@ -342,7 +342,7 @@ RegisterDialog::RegisterDialog(Window* parent, uint8_t moduleIdx) : // new StaticText(line, rect_t{}, STR_STATUS, 0, COLOR_THEME_PRIMARY1); // status = new StaticText(line, rect_t{}, STR_WAITING_FOR_RX, 0, COLOR_THEME_PRIMARY1); - auto box = new FormGroup(form, rect_t{}); + auto box = new FormWindow(form, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW_WRAP, lv_dpx(8)); lv_obj_set_style_flex_main_place(box->getLvObj(), LV_FLEX_ALIGN_SPACE_EVENLY, 0); box->padAll(lv_dpx(8)); @@ -522,7 +522,7 @@ void ModuleOptions::update() line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_EXT_ANTENNA, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, + new ToggleSwitch(line, rect_t{}, []() { const auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); return hwSettings.moduleSettings.externalAntenna; @@ -581,7 +581,7 @@ void ModuleOptions::update() line = form->newLine(&grid); - auto box = new FormGroup(form, rect_t{}); + auto box = new FormWindow(form, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW_WRAP, lv_dpx(8)); lv_obj_set_style_flex_main_place(box->getLvObj(), LV_FLEX_ALIGN_SPACE_EVENLY, 0); box->padAll(lv_dpx(8)); @@ -750,7 +750,7 @@ void RxOptions::update() // PWM rate line = form->newLine(&grid); new StaticText(line, rect_t{}, isModuleR9MAccess(moduleIdx) ? "6.67ms PWM" : "7ms PWM"); - new CheckBox( + new ToggleSwitch( line, rect_t{}, []() { auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); @@ -764,7 +764,7 @@ void RxOptions::update() // telemetry disabled line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_TELEMETRY_DISABLED); - auto tele25mw = new CheckBox( + auto tele25mw = new ToggleSwitch( line, rect_t{}, []() { auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); @@ -785,7 +785,7 @@ void RxOptions::update() // telemetry 25 mW line = form->newLine(&grid); new StaticText(line, rect_t{}, "25mw Tele"); - new CheckBox( + new ToggleSwitch( line, rect_t{}, []() { auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); @@ -875,7 +875,7 @@ void RxOptions::update() line = form->newLine(&grid); new DynamicText(line, rect_t{}, [=]() { return statusText; }); - auto box = new FormGroup(form, rect_t{}); + auto box = new FormWindow(form, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW_WRAP, lv_dpx(8)); lv_obj_set_style_flex_main_place(box->getLvObj(), LV_FLEX_ALIGN_SPACE_EVENLY, 0); box->padAll(lv_dpx(8)); diff --git a/radio/src/gui/colorlcd/afhds3_options.cpp b/radio/src/gui/colorlcd/afhds3_options.cpp index 0376d79b4e0..0594d8fe459 100644 --- a/radio/src/gui/colorlcd/afhds3_options.cpp +++ b/radio/src/gui/colorlcd/afhds3_options.cpp @@ -22,8 +22,6 @@ #include "afhds3_options.h" #include "opentx.h" -//#include "checkbox.h" - static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, @@ -75,7 +73,7 @@ static void pwmfreq_changedV0(lv_event_t* e) } } PWMfrequencyChoice::PWMfrequencyChoice(Window* parent, uint8_t moduleIdx, uint8_t channelIdx) : - FormGroup(parent, rect_t{}) + FormWindow(parent, rect_t{}) { setFlexLayout(LV_FLEX_FLOW_ROW); lv_obj_set_width(lvobj, LV_SIZE_CONTENT); @@ -112,7 +110,7 @@ PWMfrequencyChoice::PWMfrequencyChoice(Window* parent, uint8_t moduleIdx, uint8_ } PWMfrequencyChoice::PWMfrequencyChoice(Window* parent, uint8_t moduleIdx ) : - FormGroup(parent, rect_t{}) + FormWindow(parent, rect_t{}) { setFlexLayout(LV_FLEX_FLOW_ROW); lv_obj_set_width(lvobj, LV_SIZE_CONTENT); @@ -163,7 +161,7 @@ AFHDS3_Options::AFHDS3_Options(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP) title += ")"; header.setTitle2(title); - auto form = new FormGroup(&body, rect_t{}); + auto form = new FormWindow(&body, rect_t{}); form->setFlexLayout(); form->padAll(lv_dpx(8)); @@ -183,7 +181,7 @@ AFHDS3_Options::AFHDS3_Options(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP) temp_str += " "; temp_str += STR_SYNC; new StaticText(line, rect_t{}, temp_str); - new CheckBox(line, rect_t{}, GET_SET_AND_SYNC(cfg, vCfg->PWMFrequency.Synchronized, + new ToggleSwitch(line, rect_t{}, GET_SET_AND_SYNC(cfg, vCfg->PWMFrequency.Synchronized, afhds3::DirtyConfig::DC_RX_CMD_FREQUENCY_V0)); line = form->newLine(&grid); @@ -212,7 +210,7 @@ AFHDS3_Options::AFHDS3_Options(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP) temp_str += " "; temp_str += STR_SYNC; new StaticText(line, rect_t{}, temp_str); - new CheckBox( + new ToggleSwitch( line, rect_t{}, GET_DEFAULT((vCfg->PWMFrequenciesV1.Synchronized&1<>i), [=](uint8_t newVal) { vCfg->PWMFrequenciesV1.Synchronized &= ~(1<value > 0) { - auto accel = rotaryEncoderGetAccel(); + uint32_t accel = rotaryEncoderGetAccel(); bar->value--; if (accel > 0) { if (accel > bar->value) bar->value = 0; @@ -75,7 +75,7 @@ void ColorBar::on_key(lv_event_t* e) } } else if (key == LV_KEY_RIGHT) { if (bar->value < bar->maxValue) { - auto accel = rotaryEncoderGetAccel(); + uint32_t accel = rotaryEncoderGetAccel(); bar->value++; if (accel > 0) { if (accel < bar->maxValue - bar->value) bar->value += accel; @@ -327,7 +327,7 @@ void ThemeColorType::makeButton(Window* parent, uint32_t color) void ThemeColorType::makeButtonsRow(Window* parent, uint32_t c1, uint32_t c2, uint32_t c3) { - auto hbox = new FormGroup(parent, rect_t{}); + auto hbox = new FormWindow(parent, rect_t{}); hbox->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8)); lv_obj_set_flex_align(hbox->getLvObj(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_AROUND); @@ -347,7 +347,7 @@ ThemeColorType::ThemeColorType(Window* parent, uint32_t color) : lv_style_set_border_width(&style, 2); lv_style_set_border_color(&style, lv_palette_main(LV_PALETTE_GREY)); - auto vbox = new FormGroup(parent, rect_t{}); + auto vbox = new FormWindow(parent, rect_t{}); vbox->setFlexLayout(LV_FLEX_FLOW_COLUMN, lv_dpx(8)); makeButtonsRow(vbox, COLOR_THEME_PRIMARY1, COLOR_THEME_PRIMARY2, COLOR_THEME_PRIMARY3); @@ -366,7 +366,7 @@ uint32_t ThemeColorType::getRGB() ///////////////////////////////////////////////////////////////////////// ColorEditor::ColorEditor(Window *parent, const rect_t& rect, uint32_t color, std::function setValue) : - FormGroup(parent, rect), + FormWindow(parent, rect), _setValue(std::move(setValue)), _color(color) { diff --git a/radio/src/gui/colorlcd/color_editor.h b/radio/src/gui/colorlcd/color_editor.h index 88e4bdc7e21..598f2a28d34 100644 --- a/radio/src/gui/colorlcd/color_editor.h +++ b/radio/src/gui/colorlcd/color_editor.h @@ -122,7 +122,7 @@ enum COLOR_EDITOR_TYPE }; // the ColorEditor() control is a group of other controls -class ColorEditor : public FormGroup +class ColorEditor : public FormWindow { public: ColorEditor(Window* parent, const rect_t& rect, uint32_t color, diff --git a/radio/src/gui/colorlcd/color_picker.cpp b/radio/src/gui/colorlcd/color_picker.cpp index 93e6cbc6ebf..569cedf2c3b 100644 --- a/radio/src/gui/colorlcd/color_picker.cpp +++ b/radio/src/gui/colorlcd/color_picker.cpp @@ -71,13 +71,13 @@ class ColorEditorPopup : public Dialog auto cedit = new ColorEditor(line, r, color, [=](uint32_t c) { updateColor(c); }); lv_obj_set_style_grid_cell_x_align(cedit->getLvObj(), LV_GRID_ALIGN_CENTER, 0); - auto vbox = new FormGroup(line, rect_t{}); + auto vbox = new FormWindow(line, rect_t{}); lv_obj_set_style_grid_cell_x_align(vbox->getLvObj(), LV_GRID_ALIGN_CENTER, 0); vbox->setFlexLayout(LV_FLEX_FLOW_COLUMN, lv_dpx(8)); vbox->setWidth(r.w); vbox->setHeight(r.h); - auto hbox = new FormGroup(vbox, rect_t{}); + auto hbox = new FormWindow(vbox, rect_t{}); hbox->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8)); auto hbox_obj = hbox->getLvObj(); lv_obj_set_flex_align(hbox_obj, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_SPACE_AROUND); @@ -92,7 +92,7 @@ class ColorEditorPopup : public Dialog updateColor(color); - hbox = new FormGroup(vbox, rect_t{}); + hbox = new FormWindow(vbox, rect_t{}); hbox->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8)); lv_obj_set_flex_align(hbox->getLvObj(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_AROUND); @@ -127,7 +127,7 @@ class ColorEditorPopup : public Dialog // color editor defaults to HSV hsvBtn->check(true); - hbox = new FormGroup(vbox, rect_t{}); + hbox = new FormWindow(vbox, rect_t{}); hbox->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8)); lv_obj_set_flex_align(hbox->getLvObj(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_END, LV_FLEX_ALIGN_SPACE_BETWEEN); lv_obj_set_flex_grow(hbox->getLvObj(), 1); @@ -170,7 +170,7 @@ static void color_editor_popup(lv_event_t* e) ColorPicker::ColorPicker(Window* parent, const rect_t& rect, std::function getValue, std::function setValue) : - FormField(parent, rect, 0, 0, lv_btn_create), + FormField(parent, rect, 0, 0, etx_button_create), setValue(std::move(setValue)) { lv_obj_set_style_bg_opa(lvobj, LV_OPA_100, LV_PART_MAIN); diff --git a/radio/src/gui/colorlcd/colors.h b/radio/src/gui/colorlcd/colors.h index 8d22636581a..db516d77547 100644 --- a/radio/src/gui/colorlcd/colors.h +++ b/radio/src/gui/colorlcd/colors.h @@ -46,6 +46,42 @@ enum LcdColorIndex { LCD_COLOR_COUNT, }; +#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) + // // Basic color definitions // @@ -53,6 +89,7 @@ enum LcdColorIndex { #define WHITE RGB(0xFF, 0xFF, 0xFF) #define BLACK RGB(0, 0, 0) +#define RGB_FLAG 0x8000u #define RGB2FLAGS(r, g, b) (COLOR2FLAGS(RGB(r, g, b)) | RGB_FLAG) // diff --git a/radio/src/gui/colorlcd/confirm_dialog.cpp b/radio/src/gui/colorlcd/confirm_dialog.cpp index 0776f79c01a..38c11396850 100644 --- a/radio/src/gui/colorlcd/confirm_dialog.cpp +++ b/radio/src/gui/colorlcd/confirm_dialog.cpp @@ -22,7 +22,6 @@ #include "opentx.h" #include "confirm_dialog.h" #include "static.h" -#include "gridlayout.h" ConfirmDialog::ConfirmDialog(Window* parent, const char* title, const char* message, @@ -39,7 +38,7 @@ ConfirmDialog::ConfirmDialog(Window* parent, const char* title, lv_obj_set_style_bg_color(content->getLvObj(), makeLvColor(COLOR_THEME_SECONDARY3), 0); - auto box = new FormGroup(form, rect_t{}); + auto box = new FormWindow(form, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW); lv_obj_set_style_flex_main_place(box->getLvObj(), LV_FLEX_ALIGN_SPACE_EVENLY, 0); diff --git a/radio/src/gui/colorlcd/crossfire_settings.cpp b/radio/src/gui/colorlcd/crossfire_settings.cpp index b7c3a64abc4..6865c72579e 100644 --- a/radio/src/gui/colorlcd/crossfire_settings.cpp +++ b/radio/src/gui/colorlcd/crossfire_settings.cpp @@ -30,7 +30,7 @@ CrossfireSettings::CrossfireSettings(Window* parent, const FlexGridLayout& g, uint8_t moduleIdx) : - FormGroup(parent, rect_t{}), md(&g_model.moduleData[moduleIdx]) + FormWindow(parent, rect_t{}), md(&g_model.moduleData[moduleIdx]) { FlexGridLayout grid(g); setFlexLayout(); diff --git a/radio/src/gui/colorlcd/crossfire_settings.h b/radio/src/gui/colorlcd/crossfire_settings.h index d93f5c86a31..91ffcd53ebb 100644 --- a/radio/src/gui/colorlcd/crossfire_settings.h +++ b/radio/src/gui/colorlcd/crossfire_settings.h @@ -26,7 +26,7 @@ struct ModuleData; -class CrossfireSettings : public FormGroup, public ModuleOptions +class CrossfireSettings : public FormWindow, public ModuleOptions { ModuleData* md; diff --git a/radio/src/gui/colorlcd/curve.cpp b/radio/src/gui/colorlcd/curve.cpp index 813cb10ffdc..e096d8a7fcb 100644 --- a/radio/src/gui/colorlcd/curve.cpp +++ b/radio/src/gui/colorlcd/curve.cpp @@ -109,9 +109,9 @@ void CurveRenderer::paint(BitmapBuffer * dc, uint8_t ofst) Curve::Curve(Window * parent, const rect_t & rect, std::function function, std::function position): Window(parent, rect, OPAQUE), + base(rect_t{0, 0, rect.w, rect.h}, function), function(std::move(function)), - position(std::move(position)), - base(rect_t{0, 0, rect.w, rect.h}, function) + position(std::move(position)) { } diff --git a/radio/src/gui/colorlcd/curve_param.cpp b/radio/src/gui/colorlcd/curve_param.cpp index 01d42930985..2339e1428a4 100644 --- a/radio/src/gui/colorlcd/curve_param.cpp +++ b/radio/src/gui/colorlcd/curve_param.cpp @@ -75,7 +75,7 @@ CurveParam::CurveParam(Window* parent, const rect_t& rect, CurveRef* ref, GET_DEFAULT(ref->value), setRefValue); // CURVE_REF_CUSTOM - cust_choice = new ChoiceEx(this, rect_t{}, -MAX_CURVES, MAX_CURVES, + cust_choice = new Choice(this, rect_t{}, -MAX_CURVES, MAX_CURVES, GET_DEFAULT(ref->value), setRefValue); cust_choice->setTextHandler([](int value) { return getCurveString(value); }); cust_choice->set_lv_LongPressHandler(LongPressHandler, &(ref->value)); diff --git a/radio/src/gui/colorlcd/curve_param.h b/radio/src/gui/colorlcd/curve_param.h index e94344b7e96..576e33adbc0 100644 --- a/radio/src/gui/colorlcd/curve_param.h +++ b/radio/src/gui/colorlcd/curve_param.h @@ -27,7 +27,6 @@ struct CurveRef; class GVarNumberEdit; class Choice; -class ChoiceEx; class CurveParam : public Window { @@ -38,7 +37,7 @@ class CurveParam : public Window // Controls GVarNumberEdit* value_edit; Choice* func_choice; - ChoiceEx* cust_choice; + Choice* cust_choice; Window* act_field = nullptr; diff --git a/radio/src/gui/colorlcd/curveedit.cpp b/radio/src/gui/colorlcd/curveedit.cpp index b0133f981ee..7c58f8bb7dd 100644 --- a/radio/src/gui/colorlcd/curveedit.cpp +++ b/radio/src/gui/colorlcd/curveedit.cpp @@ -20,7 +20,6 @@ */ #include "curveedit.h" -#include "keyboard_curve.h" #include "opentx.h" // TODO for applyCustomCurve #include "libopenui.h" @@ -30,7 +29,7 @@ static const lv_coord_t default_col_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_L static const lv_coord_t default_row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; CurveDataEdit::CurveDataEdit(Window * parent, const rect_t & rect, uint8_t index) : - Window(parent, rect, FORM_FORWARD_FOCUS), + Window(parent, rect), index(index) { lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY3), 0); @@ -43,7 +42,7 @@ CurveDataEdit::CurveDataEdit(Window * parent, const rect_t & rect, uint8_t index #define NUM_BTN_WIDTH 48 #endif -void CurveDataEdit::curvePointsRow(FormGroup::Line* parent, int start, int count, int curvePointsCount, bool isCustom) +void CurveDataEdit::curvePointsRow(FormWindow::Line* parent, int start, int count, int curvePointsCount, bool isCustom) { static const lv_coord_t points_col_dsc[] = {11, LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; @@ -209,138 +208,6 @@ void CurveEdit::updatePreview() invalidate(); } -// #if defined(HARDWARE_TOUCH) -// bool CurveEdit::onTouchEnd(coord_t x, coord_t y) -// { -// if (!hasFocus()) { -// setFocus(SET_FOCUS_DEFAULT); -// } - -// CurveKeyboard::show(this, isCustomCurve()); - -// CurveHeader & curve = g_model.curves[index]; -// for (int i=0; i<5 + curve.points; i++) { -// if (i != current) { -// point_t point = getPoint(index, i); -// if (abs(preview.getPointX(point.x) - x) <= 10 && abs(preview.getPointY(point.y) - y) <= 10) { -// current = i; -// updatePreview(); -// break; -// } -// } -// } - -// return true; -// } - -// void CurveEdit::onFocusLost() -// { -// CurveKeyboard::hide(); -// } -// #endif - -void CurveEdit::next() -{ - CurveHeader & curve = g_model.curves[index]; - if (current++ == 5 + curve.points - 1) { - current = 0; - } - updatePreview(); -} - -void CurveEdit::previous() -{ - CurveHeader & curve = g_model.curves[index]; - if (current-- == 0) { - current = 5 + curve.points - 1; - } - updatePreview(); -} - -void CurveEdit::up() -{ - int8_t & point = curveAddress(index)[current]; - point = min(100, ++point); - storageDirty(EE_MODEL); - invalidate(); -} - -void CurveEdit::down() -{ - int8_t & point = curveAddress(index)[current]; - point = max(-100, --point); - storageDirty(EE_MODEL); - invalidate(); -} - -void CurveEdit::right() -{ - CurveHeader & curve = g_model.curves[index]; - if (curve.type == CURVE_TYPE_CUSTOM && current != 0 && current != curve.points + 5 - 1) { - int8_t * points = curveAddress(index); - int8_t * point = &points[5 + curve.points + current - 1]; - int8_t xmax = (current == (curve.points - 2) ? +100 : *(point + 1)); - *point = min(*point + 1, xmax-1); - storageDirty(EE_MODEL); - invalidate(); - } -} - -void CurveEdit::left() -{ - CurveHeader & curve = g_model.curves[index]; - if (curve.type == CURVE_TYPE_CUSTOM && current != 0 && current != curve.points + 5 - 1) { - int8_t * points = curveAddress(index); - int8_t * point = &points[5 + curve.points + current - 1]; - int8_t xmin = (current == 1 ? -100 : *(point - 1)); - *point = max(xmin+1, *point - 1); - storageDirty(EE_MODEL); - invalidate(); - } -} - -bool CurveEdit::isCustomCurve() const -{ - return g_model.curves[index].type == CURVE_TYPE_CUSTOM; -} - -void CurveEdit::onEvent(event_t event) -{ - TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event); - - switch (event) { -#if defined(HARDWARE_TOUCH) - case EVT_VIRTUAL_KEY_LEFT: - left(); - break; - - case EVT_VIRTUAL_KEY_RIGHT: - right(); - break; - - case EVT_VIRTUAL_KEY_UP: - up(); - break; - - case EVT_VIRTUAL_KEY_DOWN: - down(); - break; - - case EVT_VIRTUAL_KEY_PREVIOUS: - previous(); - break; - - case EVT_VIRTUAL_KEY_NEXT: - next(); - break; -#endif - - default: - FormField::onEvent(event); - break; - } -} - void CurveEdit::checkEvents() { if (!lockSource) { @@ -425,14 +292,12 @@ void CurveEditWindow::buildBody(FormWindow * window) new ModelTextEdit(iLine, rect_t{0, 0, 100, 0}, curve.name, sizeof(curve.name)); // Smooth - auto smooth = new TextButton(iLine, rect_t{}, STR_SMOOTH, [=]() { + auto smooth = new TextButton(iLine, rect_t{0, 0, 70, 0}, STR_SMOOTH, [=]() { g_model.curves[index].smooth = !g_model.curves[index].smooth; curveEdit->updatePreview(); return g_model.curves[index].smooth; }); smooth->check(g_model.curves[index].smooth); - smooth->padAll(2); - smooth->setHeight(26); iLine = form->newLine(&iGrid); iLine->padAll(4); @@ -463,7 +328,7 @@ void CurveEditWindow::buildBody(FormWindow * window) }); // Points count - auto edit = new NumberEdit(iLine, rect_t{}, 2, 17, GET_DEFAULT(g_model.curves[index].points + 5), + auto edit = new NumberEdit(iLine, rect_t{0, 0, 70, 0}, 2, 17, GET_DEFAULT(g_model.curves[index].points + 5), [=](int32_t newValue) { newValue -= 5; CurveHeader &curve = g_model.curves[index]; @@ -492,7 +357,7 @@ void CurveEditWindow::buildBody(FormWindow * window) iLine->padAll(0); lv_obj_set_grid_align(iLine->getLvObj(), LV_GRID_ALIGN_SPACE_BETWEEN, LV_GRID_ALIGN_SPACE_BETWEEN); - curveDataEdit = new CurveDataEdit(iLine, rect_t{ 0, 0, box->width(), box->height() - 67 }, index); + curveDataEdit = new CurveDataEdit(iLine, rect_t{ 0, 0, box->width(), box->height() - 72 }, index); // Curve editor lv_obj_set_flex_align(line->getLvObj(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_AROUND); diff --git a/radio/src/gui/colorlcd/curveedit.h b/radio/src/gui/colorlcd/curveedit.h index 50e7fcf8a31..433059bcf94 100644 --- a/radio/src/gui/colorlcd/curveedit.h +++ b/radio/src/gui/colorlcd/curveedit.h @@ -45,27 +45,14 @@ class CurveEdit: public FormField void updatePreview(); - void onEvent(event_t event) override; void checkEvents(void) override; - // #if defined(HARDWARE_TOUCH) - // bool onTouchEnd(coord_t x, coord_t y) override; - // void onFocusLost() override; - // #endif - protected: Curve preview; uint8_t index; uint8_t current; static mixsrc_t currentSource; static bool lockSource; - void next(); - void previous(); - void up(); - void down(); - void right(); - void left(); - bool isCustomCurve() const; }; class CurveDataEdit : public Window @@ -86,7 +73,7 @@ class CurveDataEdit : public Window CurveEdit * curveEdit; NumberEdit* numEditX[16]; - void curvePointsRow(FormGroup::Line* parent, int start, int count, int curvePointsCount, bool isCustom); + void curvePointsRow(FormWindow::Line* parent, int start, int count, int curvePointsCount, bool isCustom); }; class CurveEditWindow : public Page diff --git a/radio/src/gui/colorlcd/custom_failsafe.cpp b/radio/src/gui/colorlcd/custom_failsafe.cpp index 7dbde06c7fc..c54b0d9a62c 100644 --- a/radio/src/gui/colorlcd/custom_failsafe.cpp +++ b/radio/src/gui/colorlcd/custom_failsafe.cpp @@ -154,13 +154,13 @@ class ChannelFailsafeEdit : public NumberEdit } }; -class ChannelFSCombo : public FormGroup +class ChannelFSCombo : public FormWindow { ChannelFailsafeEdit* edit = nullptr; public: ChannelFSCombo(Window* parent, uint8_t ch, int vmin, int vmax) : - FormGroup(parent, rect_t{}) + FormWindow(parent, rect_t{}) { setFlexLayout(LV_FLEX_FLOW_ROW); lv_obj_set_width(lvobj, LV_SIZE_CONTENT); @@ -211,7 +211,7 @@ FailSafePage::FailSafePage(uint8_t moduleIdx) : { header.setTitle(STR_FAILSAFESET); - auto form = new FormGroup(&body, rect_t{}); + auto form = new FormWindow(&body, rect_t{}); form->setFlexLayout(); form->padAll(lv_dpx(8)); form->padRow(lv_dpx(8)); diff --git a/radio/src/gui/colorlcd/draw_functions.cpp b/radio/src/gui/colorlcd/draw_functions.cpp index 452bab68835..06f9e736473 100644 --- a/radio/src/gui/colorlcd/draw_functions.cpp +++ b/radio/src/gui/colorlcd/draw_functions.cpp @@ -102,7 +102,7 @@ void drawSleepBitmap() lcdInitDirectDrawing(); lcd->clear(bgColor); - const BitmapBuffer* bitmap = OpenTxTheme::instance()->shutdown; + const BitmapBuffer* bitmap = EdgeTxTheme::instance()->shutdown; if (bitmap) { lcd->drawMask((LCD_W - bitmap->width()) / 2, (LCD_H - bitmap->height()) / 2, bitmap, fgColor); @@ -134,7 +134,7 @@ void drawShutdownAnimation(uint32_t duration, uint32_t totalDuration, bgColor = COLOR_THEME_SECONDARY1; } - static const BitmapBuffer* shutdown = OpenTxTheme::instance()->shutdown; + static const BitmapBuffer* shutdown = EdgeTxTheme::instance()->shutdown; lcdInitDirectDrawing(); lcd->clear(bgColor); diff --git a/radio/src/gui/colorlcd/fab_button.cpp b/radio/src/gui/colorlcd/fab_button.cpp index b1ac0563fb8..8fb211b1660 100644 --- a/radio/src/gui/colorlcd/fab_button.cpp +++ b/radio/src/gui/colorlcd/fab_button.cpp @@ -19,7 +19,6 @@ * GNU General Public License for more details. */ -#include "libopenui_config.h" #include "fab_button.h" #include "font.h" #include "theme.h" @@ -34,7 +33,7 @@ const uint8_t __alpha_button_off[] { }; LZ4Bitmap ALPHA_BUTTON_OFF(BMP_ARGB4444, __alpha_button_off); -FabButton::FabButton(FormGroup* parent, coord_t x, coord_t y, uint8_t icon, +FabButton::FabButton(FormWindow* parent, coord_t x, coord_t y, uint8_t icon, std::function pressHandler, WindowFlags windowFlags) : Button(parent, @@ -44,7 +43,7 @@ FabButton::FabButton(FormGroup* parent, coord_t x, coord_t y, uint8_t icon, { } -FabButton::FabButton(FormGroup* parent, uint8_t icon, +FabButton::FabButton(FormWindow* parent, uint8_t icon, std::function pressHandler, WindowFlags windowFlags) : Button(parent, {}, pressHandler, windowFlags), icon(icon) diff --git a/radio/src/gui/colorlcd/fab_button.h b/radio/src/gui/colorlcd/fab_button.h index 6cf65f29b12..5073bb2402a 100644 --- a/radio/src/gui/colorlcd/fab_button.h +++ b/radio/src/gui/colorlcd/fab_button.h @@ -28,11 +28,11 @@ constexpr coord_t FAB_BUTTON_SIZE = 68; class FabButton: public Button { public: - FabButton(FormGroup * parent, coord_t x, coord_t y, + FabButton(FormWindow * parent, coord_t x, coord_t y, uint8_t icon, std::function pressHandler, WindowFlags windowFlags = 0); - FabButton(FormGroup * parent, uint8_t icon, + FabButton(FormWindow * parent, uint8_t icon, std::function pressHandler, WindowFlags windowFlags = 0); diff --git a/radio/src/gui/colorlcd/file_carosell.cpp b/radio/src/gui/colorlcd/file_carosell.cpp index 41e1869ce19..5e103fbba4e 100644 --- a/radio/src/gui/colorlcd/file_carosell.cpp +++ b/radio/src/gui/colorlcd/file_carosell.cpp @@ -27,7 +27,7 @@ extern inline tmr10ms_t getTicks() FileCarosell::FileCarosell(Window *parent, const rect_t &rect, std::vector fileNames) : - FormGroup(parent, rect, NO_FOCUS | FORM_NO_BORDER), + FormWindow(parent, rect, NO_FOCUS), _fileNames(fileNames), fp(new FilePreview(this, {0, 0, rect.w, rect.h}, false)) { @@ -65,7 +65,7 @@ void FileCarosell::setSelected(int n) void FileCarosell::checkEvents() { - FormGroup::checkEvents(); + FormWindow::checkEvents(); uint32_t newTicks = getTicks(); diff --git a/radio/src/gui/colorlcd/file_carosell.h b/radio/src/gui/colorlcd/file_carosell.h index e5006a9b3d0..e11b05ecc65 100644 --- a/radio/src/gui/colorlcd/file_carosell.h +++ b/radio/src/gui/colorlcd/file_carosell.h @@ -27,7 +27,7 @@ #define PAGE_INTERVAL ((1000 / 10) * 2) #define SHORT_PAGE_INTERVAL ((1000 / 20)) // 500 MS -class FileCarosell : public FormGroup +class FileCarosell : public FormWindow { public: FileCarosell(Window *parent, const rect_t &rect, diff --git a/radio/src/gui/colorlcd/file_preview.cpp b/radio/src/gui/colorlcd/file_preview.cpp index da27913eca7..7a4d324734b 100644 --- a/radio/src/gui/colorlcd/file_preview.cpp +++ b/radio/src/gui/colorlcd/file_preview.cpp @@ -24,7 +24,7 @@ FilePreview::FilePreview(Window *parent, const rect_t &rect, bool drawCentered) : - Window(parent, rect, NO_SCROLLBAR), _drawCentered(drawCentered) + Window(parent, rect), _drawCentered(drawCentered) { } diff --git a/radio/src/gui/colorlcd/flysky_settings.cpp b/radio/src/gui/colorlcd/flysky_settings.cpp index 07025ba4d3f..6760e538f09 100644 --- a/radio/src/gui/colorlcd/flysky_settings.cpp +++ b/radio/src/gui/colorlcd/flysky_settings.cpp @@ -44,7 +44,7 @@ static const char* _afhds3_phy_mode[] = { "Lora 12ch", }; -class FSProtoOpts : public FormGroup +class FSProtoOpts : public FormWindow { std::function _getMode; std::function _setMode; @@ -56,7 +56,7 @@ class FSProtoOpts : public FormGroup FSProtoOpts::FSProtoOpts(Window* parent, std::function getMode, std::function setMode) : - FormGroup(parent, rect_t{}), + FormWindow(parent, rect_t{}), _getMode(std::move(getMode)), _setMode(std::move(setMode)) { @@ -83,14 +83,14 @@ FSProtoOpts::FSProtoOpts(Window* parent, std::function getMode, FlySkySettings::FlySkySettings(Window* parent, const FlexGridLayout& g, uint8_t moduleIdx) : - FormGroup(parent, rect_t{}), + FormWindow(parent, rect_t{}), moduleIdx(moduleIdx), md(&g_model.moduleData[moduleIdx]), grid(g) { setFlexLayout(); - FormGroup::Line* line; + FormWindow::Line* line; #if defined(AFHDS2) // RX options: @@ -132,7 +132,7 @@ FlySkySettings::FlySkySettings(Window* parent, const FlexGridLayout& g, line = newLine(&grid); afhds3TypeLabel = new StaticText(line, rect_t{}, STR_TYPE, 0, COLOR_THEME_PRIMARY1); - afhds3TypeForm = new FormGroup(line, rect_t{}); + afhds3TypeForm = new FormWindow(line, rect_t{}); afhds3TypeForm->setFlexLayout(LV_FLEX_FLOW_ROW_WRAP); lv_obj_set_style_grid_cell_x_align(afhds3TypeForm->getLvObj(), LV_GRID_ALIGN_STRETCH, 0); @@ -234,7 +234,7 @@ void FlySkySettings::checkEvents() { if (afhds3::getConfig(moduleIdx)->others.lastUpdated > lastRefresh) { update(); } - FormGroup::checkEvents(); + FormWindow::checkEvents(); } void FlySkySettings::update() diff --git a/radio/src/gui/colorlcd/flysky_settings.h b/radio/src/gui/colorlcd/flysky_settings.h index 0b035a97e76..8c095be3c39 100644 --- a/radio/src/gui/colorlcd/flysky_settings.h +++ b/radio/src/gui/colorlcd/flysky_settings.h @@ -27,7 +27,7 @@ struct ModuleData; -class FlySkySettings : public FormGroup, public ModuleOptions +class FlySkySettings : public FormWindow, public ModuleOptions { uint8_t moduleIdx; ModuleData* md; @@ -49,7 +49,7 @@ class FlySkySettings : public FormGroup, public ModuleOptions Window* afhds3StatusLabel = nullptr; Window* afhds3StatusText = nullptr; Window* afhds3TypeLabel = nullptr; - FormGroup* afhds3TypeForm = nullptr; + FormWindow* afhds3TypeForm = nullptr; Choice *afhds3PhyMode = nullptr; Choice *afhds3Emi = nullptr; Choice *afhds3RfPower = nullptr; diff --git a/radio/src/gui/colorlcd/fm_matrix.cpp b/radio/src/gui/colorlcd/fm_matrix.cpp index c46e46834d1..ad8e7fe426c 100644 --- a/radio/src/gui/colorlcd/fm_matrix.cpp +++ b/radio/src/gui/colorlcd/fm_matrix.cpp @@ -35,8 +35,7 @@ FMMatrix::FMMatrix(Window* parent, const rect_t& r, T* input) : update(); for (int i = 0; i < MAX_FLIGHT_MODES; i++) { - lv_btnmatrix_set_btn_ctrl(lvobj, i, LV_BTNMATRIX_CTRL_RECOLOR); - setTextWithColor(i); + setTextAndState(i); } #if LCD_W > LCD_H @@ -49,20 +48,16 @@ FMMatrix::FMMatrix(Window* parent, const rect_t& r, T* input) : lv_obj_set_height(lvobj, LV_DPI_DEF); #endif - lv_obj_set_style_bg_opa(lvobj, LV_OPA_0, LV_PART_MAIN); - lv_obj_set_style_pad_all(lvobj, lv_dpx(4), LV_PART_MAIN); lv_obj_set_style_pad_row(lvobj, lv_dpx(4), LV_PART_MAIN); lv_obj_set_style_pad_column(lvobj, lv_dpx(4), LV_PART_MAIN); - - lv_obj_remove_style(lvobj, nullptr, LV_PART_MAIN | LV_STATE_FOCUSED); - lv_obj_remove_style(lvobj, nullptr, LV_PART_MAIN | LV_STATE_EDITED); } template -void FMMatrix::setTextWithColor(uint8_t btn_id) +void FMMatrix::setTextAndState(uint8_t btn_id) { - setText(btn_id, makeRecolor(std::to_string(btn_id), isActive(btn_id) ? COLOR_THEME_PRIMARY1 : COLOR_THEME_SECONDARY1).c_str()); + setText(btn_id, std::to_string(btn_id).c_str()); + setChecked(btn_id); } template @@ -70,7 +65,7 @@ void FMMatrix::onPress(uint8_t btn_id) { if (btn_id >= MAX_FLIGHT_MODES) return; BFBIT_FLIP(input->flightModes, bfBit(btn_id)); - setTextWithColor(btn_id); + setTextAndState(btn_id); storageDirty(EE_MODEL); } diff --git a/radio/src/gui/colorlcd/fm_matrix.h b/radio/src/gui/colorlcd/fm_matrix.h index 4e566205c84..382b532c91d 100644 --- a/radio/src/gui/colorlcd/fm_matrix.h +++ b/radio/src/gui/colorlcd/fm_matrix.h @@ -32,7 +32,7 @@ struct FMMatrix : public ButtonMatrix { FMMatrix(Window* parent, const rect_t& rect, T* input); void onPress(uint8_t btn_id); bool isActive(uint8_t btn_id); - void setTextWithColor(uint8_t btn_id); + void setTextAndState(uint8_t btn_id); }; extern template struct FMMatrix; diff --git a/radio/src/gui/colorlcd/fonts.cpp b/radio/src/gui/colorlcd/fonts.cpp index 9d4b9cdd854..6d9d00e5f50 100644 --- a/radio/src/gui/colorlcd/fonts.cpp +++ b/radio/src/gui/colorlcd/fonts.cpp @@ -19,7 +19,7 @@ * GNU General Public License for more details. */ -#include "libopenui_config.h" +#include "libopenui_defines.h" #include "font.h" #if !defined(BOOT) diff --git a/radio/src/gui/colorlcd/fullscreen_dialog.cpp b/radio/src/gui/colorlcd/fullscreen_dialog.cpp index afa745e1cc3..b5306f54f75 100644 --- a/radio/src/gui/colorlcd/fullscreen_dialog.cpp +++ b/radio/src/gui/colorlcd/fullscreen_dialog.cpp @@ -110,20 +110,20 @@ void FullScreenDialog::init() void FullScreenDialog::paint(BitmapBuffer * dc) { - OpenTxTheme::instance()->drawBackground(dc); + EdgeTxTheme::instance()->drawBackground(dc); dc->drawFilledRect(0, ALERT_FRAME_TOP, LCD_W, ALERT_FRAME_HEIGHT, SOLID, COLOR_THEME_PRIMARY2, OPACITY(8)); if (type == WARNING_TYPE_ALERT || type == WARNING_TYPE_ASTERISK) { dc->drawMask(ALERT_BITMAP_LEFT, ALERT_BITMAP_TOP, - OpenTxTheme::instance()->error, COLOR_THEME_WARNING); + EdgeTxTheme::instance()->error, COLOR_THEME_WARNING); } else if (type == WARNING_TYPE_INFO) { dc->drawMask(ALERT_BITMAP_LEFT, ALERT_BITMAP_TOP, - OpenTxTheme::instance()->busy, COLOR_THEME_WARNING); + EdgeTxTheme::instance()->busy, COLOR_THEME_WARNING); } else { // confirmation dc->drawMask(ALERT_BITMAP_LEFT, ALERT_BITMAP_TOP, - OpenTxTheme::instance()->error, COLOR_THEME_WARNING); + EdgeTxTheme::instance()->error, COLOR_THEME_WARNING); } } diff --git a/radio/src/gui/colorlcd/gui.h b/radio/src/gui/colorlcd/gui.h index 2834037f7a5..00b49c06893 100644 --- a/radio/src/gui/colorlcd/gui.h +++ b/radio/src/gui/colorlcd/gui.h @@ -29,7 +29,6 @@ #include "draw_functions.h" #include "bitmaps.h" #include "theme.h" -#include "libopenui_config.h" #define LOAD_MODEL_BITMAP() diff --git a/radio/src/gui/colorlcd/hw_bluetooth.cpp b/radio/src/gui/colorlcd/hw_bluetooth.cpp index 7d54011a5e3..fadef719c1b 100644 --- a/radio/src/gui/colorlcd/hw_bluetooth.cpp +++ b/radio/src/gui/colorlcd/hw_bluetooth.cpp @@ -99,7 +99,7 @@ static void bt_mode_changed(lv_event_t* e) } BluetoothConfigWindow::BluetoothConfigWindow(Window *parent) : - FormGroup(parent, rect_t{}) + FormWindow(parent, rect_t{}) { setFlexLayout(); FlexGridLayout grid(col_dsc, row_dsc, 2); @@ -107,7 +107,7 @@ BluetoothConfigWindow::BluetoothConfigWindow(Window *parent) : auto line = newLine(&grid); new StaticText(line, rect_t{}, STR_MODE, 0, COLOR_THEME_PRIMARY1); - auto box = new FormGroup(line, rect_t{}); + auto box = new FormWindow(line, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW_WRAP, lv_dpx(8)); lv_obj_set_style_grid_cell_x_align(box->getLvObj(), LV_GRID_ALIGN_STRETCH, 0); lv_obj_set_style_flex_cross_place(box->getLvObj(), LV_FLEX_ALIGN_CENTER, 0); diff --git a/radio/src/gui/colorlcd/hw_bluetooth.h b/radio/src/gui/colorlcd/hw_bluetooth.h index 6ae44a8b97a..5e681872d73 100644 --- a/radio/src/gui/colorlcd/hw_bluetooth.h +++ b/radio/src/gui/colorlcd/hw_bluetooth.h @@ -23,7 +23,7 @@ #include "form.h" -class BluetoothConfigWindow : public FormGroup +class BluetoothConfigWindow : public FormWindow { public: BluetoothConfigWindow(Window* parent); diff --git a/radio/src/gui/colorlcd/hw_extmodule.cpp b/radio/src/gui/colorlcd/hw_extmodule.cpp index db58573eced..b18d73df22a 100644 --- a/radio/src/gui/colorlcd/hw_extmodule.cpp +++ b/radio/src/gui/colorlcd/hw_extmodule.cpp @@ -31,14 +31,14 @@ static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(3), static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; ExternalModuleWindow::ExternalModuleWindow(Window *parent) : - FormGroup::Line(parent), lastModule(g_eeGeneral.internalModule) + FormWindow::Line(parent), lastModule(g_eeGeneral.internalModule) { FlexGridLayout grid(col_dsc, row_dsc, 2); setLayout(&grid); new StaticText(this, rect_t{}, STR_SAMPLE_MODE, 0, COLOR_THEME_PRIMARY1); - auto box = new FormGroup(this, rect_t{}); + auto box = new FormWindow(this, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8)); lv_obj_set_style_grid_cell_x_align(box->getLvObj(), LV_GRID_ALIGN_STRETCH, 0); diff --git a/radio/src/gui/colorlcd/hw_extmodule.h b/radio/src/gui/colorlcd/hw_extmodule.h index d8fcd270639..b58510e981e 100644 --- a/radio/src/gui/colorlcd/hw_extmodule.h +++ b/radio/src/gui/colorlcd/hw_extmodule.h @@ -23,7 +23,7 @@ #include "form.h" -class ExternalModuleWindow : public FormGroup::Line +class ExternalModuleWindow : public FormWindow::Line { public: ExternalModuleWindow(Window* parent); diff --git a/radio/src/gui/colorlcd/hw_inputs.cpp b/radio/src/gui/colorlcd/hw_inputs.cpp index 2898bdc5c3f..dfc7d6c1b3d 100644 --- a/radio/src/gui/colorlcd/hw_inputs.cpp +++ b/radio/src/gui/colorlcd/hw_inputs.cpp @@ -39,10 +39,12 @@ struct HWInputEdit : public RadioTextEdit { static const lv_coord_t col_two_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(2), LV_GRID_TEMPLATE_LAST}; +static const lv_coord_t col_three_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(2), + LV_GRID_TEMPLATE_LAST}; static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; -HWSticks::HWSticks(Window* parent) : FormGroup(parent, rect_t{}) +HWSticks::HWSticks(Window* parent) : FormWindow(parent, rect_t{}) { FlexGridLayout grid(col_two_dsc, row_dsc, 2); setFlexLayout(); @@ -67,9 +69,9 @@ HWSticks::HWSticks(Window* parent) : FormGroup(parent, rect_t{}) #endif } -HWPots::HWPots(Window* parent) : FormGroup(parent, rect_t{}) +HWPots::HWPots(Window* parent) : FormWindow(parent, rect_t{}) { - FlexGridLayout grid(col_two_dsc, row_dsc, 2); + FlexGridLayout grid(col_three_dsc, row_dsc, 2); setFlexLayout(); auto max_pots = adcGetMaxInputs(ADC_INPUT_POT); @@ -85,7 +87,7 @@ HWPots::HWPots(Window* parent) : FormGroup(parent, rect_t{}) new StaticText(line, rect_t{}, adcGetInputLabel(ADC_INPUT_POT, i), 0, COLOR_THEME_PRIMARY1); - auto box = new FormGroup(line, rect_t{}); + auto box = new FormWindow(line, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(4)); auto box_obj = box->getLvObj(); @@ -147,24 +149,18 @@ class SwitchDynamicLabel : public StaticText uint8_t lastpos = 0xff; }; -HWSwitches::HWSwitches(Window* parent) : FormGroup(parent, rect_t{}) +HWSwitches::HWSwitches(Window* parent) : FormWindow(parent, rect_t{}) { - FlexGridLayout grid(col_two_dsc, row_dsc, 2); + FlexGridLayout grid(col_three_dsc, row_dsc, 2); setFlexLayout(); for (int i = 0; i < switchGetMaxSwitches(); i++) { auto line = newLine(&grid); new SwitchDynamicLabel(line, i); - auto box = new FormGroup(line, rect_t{}); - box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(4)); - - auto box_obj = box->getLvObj(); - lv_obj_set_style_flex_cross_place(box_obj, LV_FLEX_ALIGN_CENTER, 0); - - new HWInputEdit(box, (char*)switchGetCustomName(i), LEN_SWITCH_NAME); + new HWInputEdit(line, (char*)switchGetCustomName(i), LEN_SWITCH_NAME); new Choice( - box, rect_t{}, STR_SWTYPES, SWITCH_NONE, switchGetMaxType(i), + line, rect_t{}, STR_SWTYPES, SWITCH_NONE, switchGetMaxType(i), [=]() -> int { return SWITCH_CONFIG(i); }, [=](int newValue) { swconfig_t mask = (swconfig_t)SWITCH_CONFIG_MASK(i); diff --git a/radio/src/gui/colorlcd/hw_inputs.h b/radio/src/gui/colorlcd/hw_inputs.h index b4254251e2a..96deae5052f 100644 --- a/radio/src/gui/colorlcd/hw_inputs.h +++ b/radio/src/gui/colorlcd/hw_inputs.h @@ -25,16 +25,15 @@ #include "dialog.h" #include "button.h" -struct HWSticks : public FormGroup { +struct HWSticks : public FormWindow { HWSticks(Window* parent); }; -struct HWPots : public FormGroup { +struct HWPots : public FormWindow { HWPots(Window* parent); }; - -struct HWSwitches : public FormGroup { +struct HWSwitches : public FormWindow { HWSwitches(Window* parent); }; diff --git a/radio/src/gui/colorlcd/hw_intmodule.cpp b/radio/src/gui/colorlcd/hw_intmodule.cpp index f2fc740d627..0a33207ac03 100644 --- a/radio/src/gui/colorlcd/hw_intmodule.cpp +++ b/radio/src/gui/colorlcd/hw_intmodule.cpp @@ -34,7 +34,7 @@ static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(3), static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; InternalModuleWindow::InternalModuleWindow(Window *parent) : - FormGroup::Line(parent), + FormWindow::Line(parent), lastModule(g_eeGeneral.internalModule) { FlexGridLayout grid(col_dsc, row_dsc, 2); @@ -42,7 +42,7 @@ InternalModuleWindow::InternalModuleWindow(Window *parent) : new StaticText(this, rect_t{}, STR_TYPE, 0, COLOR_THEME_PRIMARY1); - auto box = new FormGroup(this, rect_t{}); + auto box = new FormWindow(this, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8)); lv_obj_set_style_grid_cell_x_align(box->getLvObj(), LV_GRID_ALIGN_STRETCH, 0); @@ -55,7 +55,7 @@ InternalModuleWindow::InternalModuleWindow(Window *parent) : [](int module) { return isInternalModuleSupported(module); }); #if defined(INTERNAL_MODULE_PXX1) && defined(EXTERNAL_ANTENNA) - auto pxx1_box = new FormGroup(box, rect_t{}); + auto pxx1_box = new FormWindow(box, rect_t{}); pxx1_box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8)); ant_box = pxx1_box->getLvObj(); @@ -87,7 +87,7 @@ InternalModuleWindow::InternalModuleWindow(Window *parent) : #endif #if defined(CROSSFIRE) - auto crsf_box = new FormGroup(box, rect_t{}); + auto crsf_box = new FormWindow(box, rect_t{}); crsf_box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8)); br_box = crsf_box->getLvObj(); diff --git a/radio/src/gui/colorlcd/hw_intmodule.h b/radio/src/gui/colorlcd/hw_intmodule.h index d94343429d6..ce2f744c9e1 100644 --- a/radio/src/gui/colorlcd/hw_intmodule.h +++ b/radio/src/gui/colorlcd/hw_intmodule.h @@ -23,7 +23,7 @@ #include "form.h" -class InternalModuleWindow : public FormGroup::Line +class InternalModuleWindow : public FormWindow::Line { public: InternalModuleWindow(Window *parent); diff --git a/radio/src/gui/colorlcd/hw_serial.cpp b/radio/src/gui/colorlcd/hw_serial.cpp index 2aa33e48d6c..ade534273ee 100644 --- a/radio/src/gui/colorlcd/hw_serial.cpp +++ b/radio/src/gui/colorlcd/hw_serial.cpp @@ -30,7 +30,7 @@ static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(3), static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; SerialConfigWindow::SerialConfigWindow(Window *parent, const rect_t &rect) : - FormGroup(parent, rect, FORWARD_SCROLL) + FormWindow(parent, rect) { setFlexLayout(); FlexGridLayout grid(col_dsc, row_dsc, 2); @@ -45,7 +45,7 @@ SerialConfigWindow::SerialConfigWindow(Window *parent, const rect_t &rect) : auto line = newLine(&grid); new StaticText(line, rect_t{}, port->name, 0, COLOR_THEME_PRIMARY1); - auto box = new FormGroup(line, rect_t{}); + auto box = new FormWindow(line, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8)); lv_obj_set_style_grid_cell_x_align(box->getLvObj(), LV_GRID_ALIGN_STRETCH, 0); lv_obj_set_style_flex_cross_place(box->getLvObj(), LV_FLEX_ALIGN_CENTER, 0); @@ -64,7 +64,7 @@ SerialConfigWindow::SerialConfigWindow(Window *parent, const rect_t &rect) : if (port->set_pwr != nullptr) { new StaticText(box, rect_t{}, STR_AUX_SERIAL_PORT_POWER, 0, COLOR_THEME_PRIMARY1); - new CheckBox( + new ToggleSwitch( box, rect_t{}, [=] { return serialGetPower(port_nr); }, [=](int8_t newValue) { serialSetPower(port_nr, (bool)newValue); diff --git a/radio/src/gui/colorlcd/hw_serial.h b/radio/src/gui/colorlcd/hw_serial.h index b327b21a311..573111f38f0 100644 --- a/radio/src/gui/colorlcd/hw_serial.h +++ b/radio/src/gui/colorlcd/hw_serial.h @@ -23,7 +23,7 @@ #include "form.h" -class SerialConfigWindow : public FormGroup +class SerialConfigWindow : public FormWindow { public: SerialConfigWindow(Window *parent, const rect_t &rect); diff --git a/radio/src/gui/colorlcd/input_mix_group.cpp b/radio/src/gui/colorlcd/input_mix_group.cpp index 9fb78a22926..7ddc0280c1c 100644 --- a/radio/src/gui/colorlcd/input_mix_group.cpp +++ b/radio/src/gui/colorlcd/input_mix_group.cpp @@ -22,8 +22,6 @@ #include "input_mix_group.h" #include "channel_bar.h" -#include "lvgl_widgets/input_mix_group.h" - #include "opentx.h" #include diff --git a/radio/src/gui/colorlcd/input_source.cpp b/radio/src/gui/colorlcd/input_source.cpp index eab6a2dceb6..050d7318543 100644 --- a/radio/src/gui/colorlcd/input_source.cpp +++ b/radio/src/gui/colorlcd/input_source.cpp @@ -102,7 +102,7 @@ InputSource::InputSource(Window* parent, ExpoData* input) : }); lv_obj_add_event_cb(lvobj, InputSource::value_changed, LV_EVENT_VALUE_CHANGED, nullptr); - sensor_form = new FormGroup(this, rect_t{}); + sensor_form = new FormWindow(this, rect_t{}); sensor_form->setFlexLayout(); FlexGridLayout grid(col_dsc, row_dsc); diff --git a/radio/src/gui/colorlcd/input_source.h b/radio/src/gui/colorlcd/input_source.h index 81670a99903..d3f058d97a3 100644 --- a/radio/src/gui/colorlcd/input_source.h +++ b/radio/src/gui/colorlcd/input_source.h @@ -24,12 +24,12 @@ #include "window.h" struct ExpoData; -class FormGroup; +class FormWindow; class InputSource : public Window { ExpoData* input; - FormGroup* sensor_form; + FormWindow* sensor_form; void update(); static void value_changed(lv_event_t* e); diff --git a/radio/src/gui/colorlcd/keyboard_curve.cpp b/radio/src/gui/colorlcd/keyboard_curve.cpp deleted file mode 100644 index 9bef69e38fc..00000000000 --- a/radio/src/gui/colorlcd/keyboard_curve.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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. - */ - -#include "keyboard_curve.h" -#include "button.h" - -#include "translations/untranslated.h" - -constexpr coord_t KEYBOARD_HEIGHT = 110; - -CurveKeyboard * CurveKeyboard::_instance = nullptr; - -CurveKeyboard::CurveKeyboard() : - Keyboard(KEYBOARD_HEIGHT) -{ - // up - new TextButton(this, {LCD_W / 2 - 20, 5, 40, 40}, STR_CHAR_UP, - [=]() -> uint8_t { - pushEvent(EVT_VIRTUAL_KEY_UP); - return 0; - }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS); - - // down - new TextButton(this, {LCD_W / 2 - 20, 65, 40, 40}, STR_CHAR_DOWN, - [=]() -> uint8_t { - pushEvent(EVT_VIRTUAL_KEY_DOWN); - return 0; - }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS); - - // left - left = new TextButton(this, {LCD_W / 2 - 70, 35, 40, 40}, STR_CHAR_LEFT, - [=]() -> uint8_t { - pushEvent(EVT_VIRTUAL_KEY_LEFT); - return 0; - }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS); - - // right - right = new TextButton(this, {LCD_W / 2 + 30, 35, 40, 40}, STR_CHAR_RIGHT, - [=]() -> uint8_t { - pushEvent(EVT_VIRTUAL_KEY_RIGHT); - return 0; - }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS); - - // next - new TextButton(this, {LCD_W / 2 + 80, 35, 60, 40}, "Next", - [=]() -> uint8_t { - pushEvent(EVT_VIRTUAL_KEY_NEXT); - return 0; - }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS); - - // previous - new TextButton(this, {LCD_W / 2 - 140, 35, 60, 40}, "Prev", - [=]() -> uint8_t { - pushEvent(EVT_VIRTUAL_KEY_PREVIOUS); - return 0; - }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS); - -} - -void CurveKeyboard::enableRightLeft(bool enable) -{ - TRACE("STOP %d", enable); - left->enable(enable); - right->enable(enable); -} - -CurveKeyboard::~CurveKeyboard() -{ - _instance = nullptr; -} - -void CurveKeyboard::paint(BitmapBuffer * dc) -{ - lcdSetColor(RGB(0xE0, 0xE0, 0xE0)); - dc->clear(CUSTOM_COLOR); -} diff --git a/radio/src/gui/colorlcd/keyboard_curve.h b/radio/src/gui/colorlcd/keyboard_curve.h deleted file mode 100644 index 947af546b24..00000000000 --- a/radio/src/gui/colorlcd/keyboard_curve.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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. - */ - -#ifndef _KEYBOARD_CURVE_H_ -#define _KEYBOARD_CURVE_H_ - -#include "keyboard_base.h" - -class Button; - -class CurveKeyboard : public Keyboard { - public: - CurveKeyboard(); - - ~CurveKeyboard() override; - -#if defined(DEBUG_WINDOWS) - std::string getName() const override - { - return "CurveKeyboard"; - } -#endif - - void enableRightLeft(bool enable); - - static void show(FormField * field, bool enableRightLeft) - { - if (!_instance) - _instance = new CurveKeyboard(); - _instance->setField(field); - _instance->enableRightLeft(enableRightLeft); - } - - void paint(BitmapBuffer * dc) override; - - protected: - static CurveKeyboard * _instance; - Button * left = nullptr; - Button * right = nullptr; -}; - -#endif // _KEYBOARD_CURVE_H_ diff --git a/radio/src/gui/colorlcd/layouts/layout_factory_impl.cpp b/radio/src/gui/colorlcd/layouts/layout_factory_impl.cpp index d5a70266a58..b935adb4564 100644 --- a/radio/src/gui/colorlcd/layouts/layout_factory_impl.cpp +++ b/radio/src/gui/colorlcd/layouts/layout_factory_impl.cpp @@ -88,7 +88,7 @@ void Layout::updateFromTheme() // Hack to fix flight mode color on main view // Required because theme is loaded after the main view has been created if (decoration) - decoration->setFlightModeColor(); + decoration->updateFromTheme(); } void Layout::adjustLayout() diff --git a/radio/src/gui/colorlcd/layouts/sliders.cpp b/radio/src/gui/colorlcd/layouts/sliders.cpp index dc98296d5fc..08519a93ba2 100644 --- a/radio/src/gui/colorlcd/layouts/sliders.cpp +++ b/radio/src/gui/colorlcd/layouts/sliders.cpp @@ -25,26 +25,9 @@ #include "hal/adc_driver.h" -enum slider_type { - SLIDER_HORIZ, - SLIDER_6POS, -}; - -static void slider_self_size(lv_event_t* e) -{ - lv_point_t* s = (lv_point_t*)lv_event_get_param(e); - slider_type t = (slider_type)(intptr_t)lv_event_get_user_data(e); - switch(t) { - case SLIDER_HORIZ: - s->x = HORIZONTAL_SLIDERS_WIDTH; - s->y = TRIM_SQUARE_SIZE; - break; - case SLIDER_6POS: - s->x = MULTIPOS_W; - s->y = MULTIPOS_H; - break; - } -} +constexpr coord_t MULTIPOS_H = 18; +constexpr coord_t MULTIPOS_W_SPACING = 12; +constexpr coord_t MULTIPOS_W = (6+1)*MULTIPOS_W_SPACING; MainViewSlider::MainViewSlider(Window* parent, const rect_t& rect, uint8_t idx) : @@ -65,27 +48,21 @@ void MainViewSlider::checkEvents() MainViewHorizontalSlider::MainViewHorizontalSlider(Window* parent, uint8_t idx) : - MainViewSlider(parent, rect_t{}, idx) + MainViewSlider(parent, rect_t{0, 0, HORIZONTAL_SLIDERS_WIDTH, TRIM_SQUARE_SIZE}, idx) { - void* user_data = (void*)SLIDER_HORIZ; - lv_obj_add_event_cb(lvobj, slider_self_size, LV_EVENT_GET_SELF_SIZE, - user_data); - - setWidth(HORIZONTAL_SLIDERS_WIDTH); - setHeight(TRIM_SQUARE_SIZE); } void MainViewHorizontalSlider::paint(BitmapBuffer * dc) { // The ticks - int delta = (width() - TRIM_SQUARE_SIZE) / SLIDER_TICKS_COUNT; + int sliderTicksCount = (width() - TRIM_SQUARE_SIZE) / SLIDER_TICK_SPACING; coord_t x = TRIM_SQUARE_SIZE / 2; - for (uint8_t i = 0; i <= SLIDER_TICKS_COUNT; i++) { - if (i == 0 || i == SLIDER_TICKS_COUNT / 2 || i == SLIDER_TICKS_COUNT) + for (uint8_t i = 0; i <= sliderTicksCount; i++) { + if (i == 0 || i == sliderTicksCount / 2 || i == SLIDER_TICKS_COUNT) dc->drawSolidVerticalLine(x, 2, 13, COLOR_THEME_SECONDARY1); else dc->drawSolidVerticalLine(x, 4, 9, COLOR_THEME_SECONDARY1); - x += delta; + x += SLIDER_TICK_SPACING; } // The square @@ -94,14 +71,8 @@ void MainViewHorizontalSlider::paint(BitmapBuffer * dc) } MainView6POS::MainView6POS(Window* parent, uint8_t idx) : - MainViewSlider(parent, rect_t{}, idx) + MainViewSlider(parent, rect_t{0, 0, MULTIPOS_W, MULTIPOS_H}, idx) { - void* user_data = (void*)SLIDER_6POS; - lv_obj_add_event_cb(lvobj, slider_self_size, LV_EVENT_GET_SELF_SIZE, - user_data); - - setWidth(MULTIPOS_W); - setHeight(MULTIPOS_H); } void MainView6POS::paint(BitmapBuffer * dc) @@ -129,27 +100,22 @@ void MainView6POS::checkEvents() } } -MainViewVerticalSlider::MainViewVerticalSlider(Window* parent, uint8_t idx) : - MainViewSlider(parent, rect_t{}, idx) +MainViewVerticalSlider::MainViewVerticalSlider(Window* parent, const rect_t& rect, uint8_t idx) : + MainViewSlider(parent, rect, idx) { - lv_obj_set_style_max_height(lvobj, VERTICAL_SLIDERS_HEIGHT, 0); - lv_obj_set_style_min_height(lvobj, VERTICAL_SLIDERS_HEIGHT/2, 0); - lv_obj_set_style_flex_grow(lvobj, 1, 0); - setWidth(TRIM_SQUARE_SIZE); } void MainViewVerticalSlider::paint(BitmapBuffer * dc) { // The ticks - int delta = 4; - int sliderTicksCount = (height() - TRIM_SQUARE_SIZE) / delta; + int sliderTicksCount = (height() - TRIM_SQUARE_SIZE) / SLIDER_TICK_SPACING; coord_t y = TRIM_SQUARE_SIZE / 2; for (uint8_t i = 0; i <= sliderTicksCount; i++) { if (i == 0 || i == sliderTicksCount / 2 || i == sliderTicksCount) dc->drawSolidHorizontalLine(2, y, 13, COLOR_THEME_SECONDARY1); else dc->drawSolidHorizontalLine(4, y, 9, COLOR_THEME_SECONDARY1); - y += delta; + y += SLIDER_TICK_SPACING; } // The square diff --git a/radio/src/gui/colorlcd/layouts/sliders.h b/radio/src/gui/colorlcd/layouts/sliders.h index 71138490478..c9f8661fc8c 100644 --- a/radio/src/gui/colorlcd/layouts/sliders.h +++ b/radio/src/gui/colorlcd/layouts/sliders.h @@ -24,17 +24,14 @@ #include "libopenui.h" #include "trims.h" -#if defined(PCBNV14) +#if LCD_H > LCD_W constexpr uint8_t SLIDER_TICKS_COUNT = 30; #else constexpr uint8_t SLIDER_TICKS_COUNT = 40; #endif -constexpr coord_t HMARGIN = 5; -constexpr coord_t HORIZONTAL_SLIDERS_WIDTH = SLIDER_TICKS_COUNT * 4 + TRIM_SQUARE_SIZE; -constexpr coord_t MULTIPOS_H = 18; -constexpr coord_t MULTIPOS_W_SPACING = 12; -constexpr coord_t MULTIPOS_W = (6+1)*MULTIPOS_W_SPACING; -constexpr coord_t VERTICAL_SLIDERS_HEIGHT = SLIDER_TICKS_COUNT * 4 + TRIM_SQUARE_SIZE; +constexpr coord_t SLIDER_TICK_SPACING = 4; +constexpr coord_t HORIZONTAL_SLIDERS_WIDTH = SLIDER_TICKS_COUNT * SLIDER_TICK_SPACING + TRIM_SQUARE_SIZE; +constexpr coord_t VERTICAL_SLIDERS_HEIGHT = SLIDER_TICKS_COUNT * SLIDER_TICK_SPACING + TRIM_SQUARE_SIZE; class MainViewSlider : public Window { @@ -58,7 +55,6 @@ class MainViewHorizontalSlider : public MainViewSlider class MainView6POS : public MainViewSlider { public: - // using MainViewSlider::MainViewSlider; MainView6POS(Window* parent, uint8_t idx); void paint(BitmapBuffer * dc) override; void checkEvents() override; @@ -67,6 +63,6 @@ class MainView6POS : public MainViewSlider class MainViewVerticalSlider : public MainViewSlider { public: - MainViewVerticalSlider(Window* parent, uint8_t idx); + MainViewVerticalSlider(Window* parent, const rect_t & rect, uint8_t idx); void paint(BitmapBuffer * dc) override; }; diff --git a/radio/src/gui/colorlcd/layouts/topbar_impl.cpp b/radio/src/gui/colorlcd/layouts/topbar_impl.cpp index 29bd6481656..a3be4f255de 100644 --- a/radio/src/gui/colorlcd/layouts/topbar_impl.cpp +++ b/radio/src/gui/colorlcd/layouts/topbar_impl.cpp @@ -139,8 +139,7 @@ coord_t TopbarImpl::getVisibleHeight(float visible) const // 0.0 -> 1.0 void TopbarImpl::paint(BitmapBuffer * dc) { - dc->drawSolidFilledRect(0, 0, width(), height(), COLOR_THEME_SECONDARY1); - OpenTxTheme::instance()->drawTopLeftBitmap(dc); + EdgeTxTheme::instance()->drawHeaderIcon(dc, ICON_EDGETX); const TimerOptions timerOptions = {.options = SHOW_TIME}; struct gtm t; gettime(&t); diff --git a/radio/src/gui/colorlcd/layouts/trims.cpp b/radio/src/gui/colorlcd/layouts/trims.cpp index 64b7e2a0e28..48b13a03974 100644 --- a/radio/src/gui/colorlcd/layouts/trims.cpp +++ b/radio/src/gui/colorlcd/layouts/trims.cpp @@ -25,27 +25,6 @@ #include "opentx.h" -enum trim_type { - TRIM_VERT, - TRIM_HORIZ, -}; - -static void trim_self_size(lv_event_t* e) -{ - lv_point_t* s = (lv_point_t*)lv_event_get_param(e); - trim_type t = (trim_type)(intptr_t)lv_event_get_user_data(e); - switch(t) { - case TRIM_VERT: - s->y = VERTICAL_SLIDERS_HEIGHT; - s->x = TRIM_SQUARE_SIZE; - break; - case TRIM_HORIZ: - s->x = HORIZONTAL_SLIDERS_WIDTH; - s->y = TRIM_SQUARE_SIZE; - break; - } -} - MainViewTrim::MainViewTrim(Window * parent, const rect_t & rect, uint8_t idx): Window(parent, rect), idx(idx) @@ -109,13 +88,8 @@ void MainViewTrim::paint(BitmapBuffer * dc) } MainViewHorizontalTrim::MainViewHorizontalTrim(Window* parent, uint8_t idx) : - MainViewTrim(parent, rect_t{}, idx) + MainViewTrim(parent, rect_t{0, 0, HORIZONTAL_SLIDERS_WIDTH, TRIM_SQUARE_SIZE}, idx) { - void* user_data = (void*)TRIM_HORIZ; - lv_obj_add_event_cb(lvobj, trim_self_size, LV_EVENT_GET_SELF_SIZE, user_data); - - setWidth(HORIZONTAL_SLIDERS_WIDTH); - setHeight(TRIM_SQUARE_SIZE); } coord_t MainViewHorizontalTrim::sx() @@ -153,13 +127,8 @@ void MainViewHorizontalTrim::drawValue(BitmapBuffer * dc) } MainViewVerticalTrim::MainViewVerticalTrim(Window* parent, uint8_t idx) : - MainViewTrim(parent, rect_t{}, idx) + MainViewTrim(parent, rect_t{0, 0, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT}, idx) { - void* user_data = (void*)TRIM_VERT; - lv_obj_add_event_cb(lvobj, trim_self_size, LV_EVENT_GET_SELF_SIZE, user_data); - - setWidth(TRIM_SQUARE_SIZE); - setHeight(VERTICAL_SLIDERS_HEIGHT); } coord_t MainViewVerticalTrim::sy() diff --git a/radio/src/gui/colorlcd/libopenui.h b/radio/src/gui/colorlcd/libopenui.h index 76d6a2ada2e..546c4a6c035 100644 --- a/radio/src/gui/colorlcd/libopenui.h +++ b/radio/src/gui/colorlcd/libopenui.h @@ -22,7 +22,7 @@ #pragma once #if !defined(BOOT) -#include "libopenui_config.h" +#include "libopenui_defines.h" #include "libopenui_file.h" #include "font.h" #include "window.h" @@ -30,7 +30,7 @@ #include "static.h" #include "button.h" #include "fab_button.h" -#include "checkbox.h" +#include "toggleswitch.h" #include "numberedit.h" #include "timeedit.h" #include "choice.h" @@ -39,10 +39,8 @@ #include "filechoice.h" #include "textedit.h" #include "slider.h" -#include "progress.h" #include "keyboard_text.h" #include "keyboard_number.h" -#include "keyboard_curve.h" #include "tabsgroup.h" #include "page.h" #include "menu.h" @@ -51,7 +49,6 @@ #include "message_dialog.h" #include "confirm_dialog.h" #include "dialog.h" -#include "gridlayout.h" #include "getset_helpers.h" #include "curveedit.h" #include "draw_functions.h" diff --git a/radio/src/gui/colorlcd/list_line_button.cpp b/radio/src/gui/colorlcd/list_line_button.cpp index 7a449286c3a..cc2687331e8 100644 --- a/radio/src/gui/colorlcd/list_line_button.cpp +++ b/radio/src/gui/colorlcd/list_line_button.cpp @@ -22,8 +22,6 @@ #include "list_line_button.h" #include "opentx.h" -#include "lvgl_widgets/input_mix_line.h" - void ListLineButton::value_changed(lv_event_t* e) { auto obj = lv_event_get_target(e); diff --git a/radio/src/gui/colorlcd/lvgl_widgets/input_mix_group.c b/radio/src/gui/colorlcd/lvgl_widgets/input_mix_group.c deleted file mode 100644 index d91e74118b9..00000000000 --- a/radio/src/gui/colorlcd/lvgl_widgets/input_mix_group.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) EdgeTX - * - * 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 "input_mix_group.h" - -#define MY_CLASS &input_mix_group_class - -const lv_obj_class_t input_mix_group_class = { - .width_def = LV_PCT(100), - .height_def = LV_SIZE_CONTENT, - .editable = LV_OBJ_CLASS_EDITABLE_FALSE, - .group_def = LV_OBJ_CLASS_GROUP_DEF_FALSE, - .instance_size = sizeof(lv_obj_t), - .base_class = &lv_obj_class, -}; - -lv_obj_t* input_mix_group_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; -} diff --git a/radio/src/gui/colorlcd/lvgl_widgets/input_mix_group.h b/radio/src/gui/colorlcd/lvgl_widgets/input_mix_group.h deleted file mode 100644 index e11d4bd0e1b..00000000000 --- a/radio/src/gui/colorlcd/lvgl_widgets/input_mix_group.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) EdgeTX - * - * 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 INPUT_MIX_GROUP_H -#define INPUT_MIX_GROUP_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -extern const lv_obj_class_t input_mix_group_class; -lv_obj_t* input_mix_group_create(lv_obj_t* parent); - -#ifdef __cplusplus -}; -#endif - -#endif diff --git a/radio/src/gui/colorlcd/lvgl_widgets/input_mix_line.c b/radio/src/gui/colorlcd/lvgl_widgets/input_mix_line.c deleted file mode 100644 index 7af9a68ac15..00000000000 --- a/radio/src/gui/colorlcd/lvgl_widgets/input_mix_line.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) EdgeTX - * - * 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 "input_mix_line.h" - -#define MY_CLASS &input_mix_line_class - -const lv_obj_class_t input_mix_line_class = { - .width_def = LV_PCT(100), - .height_def = LV_SIZE_CONTENT, - .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, - .instance_size = sizeof(lv_btn_t), - .base_class = &lv_btn_class, -}; - -lv_obj_t* input_mix_line_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; -} diff --git a/radio/src/gui/colorlcd/lvgl_widgets/input_mix_line.h b/radio/src/gui/colorlcd/lvgl_widgets/input_mix_line.h deleted file mode 100644 index 01068c18d38..00000000000 --- a/radio/src/gui/colorlcd/lvgl_widgets/input_mix_line.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) EdgeTX - * - * 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 INPUT_MIX_LINE_H -#define INPUT_MIX_LINE_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -extern const lv_obj_class_t input_mix_line_class; -lv_obj_t* input_mix_line_create(lv_obj_t* parent); - -#ifdef __cplusplus -}; -#endif - -#endif diff --git a/radio/src/gui/colorlcd/lz4_bitmaps.cpp b/radio/src/gui/colorlcd/lz4_bitmaps.cpp index dfa8594fd06..98c6d64e462 100644 --- a/radio/src/gui/colorlcd/lz4_bitmaps.cpp +++ b/radio/src/gui/colorlcd/lz4_bitmaps.cpp @@ -21,7 +21,7 @@ #include "lz4_bitmaps.h" #include "libopenui/thirdparty/lz4/lz4.h" -#include "libopenui_helpers.h" +#include "opentx_helpers.h" const uint8_t* _decompressed_mask(const uint8_t* lz4_compressed, uint8_t** raw) { diff --git a/radio/src/gui/colorlcd/material-backup.cpp b/radio/src/gui/colorlcd/material-backup.cpp deleted file mode 100644 index 0abca44c070..00000000000 --- a/radio/src/gui/colorlcd/material-backup.cpp +++ /dev/null @@ -1,200 +0,0 @@ -class Window -{ - public: - Window(coord_t x, coord_t y, coord_t width, coord_t height): - x(x), - y(y), - width(width), - height(height), - offsetX(0), - offsetY(0), - innerWidth(width), - innerHeight(height), - focusX(-1), - focusY(-1) - { - } - - coord_t x, y, width, height, offsetX, offsetY, innerWidth, innerHeight, focusX, focusY; - - void scroll() { - if (touchState.Event == TE_SLIDE) { - if (innerHeight > height && touchState.startX >= this->x && touchState.startX <= this->x + this->width) { - this->offsetY = limit(-innerHeight + height, this->offsetY + touchState.Y - touchState.startY, 0); - touchState.startY = touchState.Y; - } - if (innerWidth > width && touchState.startY >= this->y && touchState.startY <= this->y + this->height) { - this->offsetX = limit(-innerWidth + width, this->offsetX + touchState.X - touchState.startX, 0); - touchState.startX = touchState.X; - } - } - } - - bool touchPressed(coord_t x, coord_t y, coord_t w, coord_t h) { - return ::touchPressed(this->x + this->offsetX + x, this->y + this->offsetY + y, w, h); - } - - void setHeight(coord_t height) { - this->height = height; - } - - void setInnerWidth(coord_t value) { - innerWidth = value; - } - - void setInnerHeight(coord_t value) { - innerHeight = value; - } - - void setFocus(coord_t x, coord_t y) { - focusX = x; - focusY = y; - } - - void clearFocus() { - setFocus(-1, -1); - } - - bool hasFocus(coord_t x, coord_t y) { - return (x == focusX && y == focusY); - } - - void drawVerticalScrollbar(); - - void drawSolidFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, LcdFlags flags) - { - setClippingRect(); - lcd->drawSolidFilledRect(this->x + this->offsetX + x, this->y + this->offsetY + y, w, h, flags); - clearLcdLimits(); - } - - template - void drawBitmap(coord_t x, coord_t y, const T * bmp, coord_t srcx=0, coord_t srcy=0, coord_t w=0, coord_t h=0, float scale=0) { - if (this->offsetX + x >= this->width || this->offsetY + y >= this->height) { - return; - } - setClippingRect(); - lcd->drawBitmap(this->x + this->offsetX + x, this->y + this->offsetY + y, bmp, srcx, srcy, w, h, scale); - clearLcdLimits(); - } - - inline void setClippingRect() { - lcd->setClippingRect(this->x, this->x + this->width, this->y, this->y + this->height); - } - - inline void clearLcdLimits() { - lcd->clearClippingRect(); - } - - void drawSizedText(coord_t x, coord_t y, const char * s, uint8_t len, LcdFlags flags) { - setClippingRect(); - lcd->drawSizedText(this->x + this->offsetX + x, this->y + this->offsetY + y, s, len, flags); - clearLcdLimits(); - } - -}; -template -bool Subtitle(W * window, rect_t & rect, const char * label) -{ - rect.h = 14; - drawText(window, rect.x, rect.y, label, FONT(BOLD)); -} - -template -bool CheckBox(W * window, rect_t & rect, const char * label, uint8_t & value, LcdFlags flags=0) -{ - rect.h = 30; - bool hasFocus = (flags & HAS_FOCUS) || window->hasFocus(rect.x, rect.y); - drawText(window, rect.x, rect.y+4, label); - coord_t x = rect.x + rect.w - 20; - if (hasFocus) { - window->drawSolidFilledRect(x-1, rect.y+8, 14, 14, COLOR_THEME_FOCUS); - window->drawSolidFilledRect(x+1, rect.y+10, 10, 10, COLOR_THEME_SECONDARY3); - if (value) { - window->drawSolidFilledRect(x+2, rect.y+11, 8, 8, COLOR_THEME_FOCUS); - } - } - else { - if (value) { - window->drawSolidFilledRect(x+2, rect.y+11, 8, 8, COLOR_THEME_FOCUS); - drawSolidRect(window, x, rect.y+9, 12, 12, 1, COLOR_THEME_PRIMARY3); - } - else { - drawSolidRect(window, x, rect.y+9, 12, 12, 1, COLOR_THEME_PRIMARY3); - } - } - if (window->touchPressed(rect.x, rect.y, rect.w, rect.h)) { - value ^= 1; - window->setFocus(rect.x, rect.y); - return true; - } - else { - return false; - } -} - - -template -void drawWidgetLabel(W * window, rect_t & rect, const char * label) { - drawText(window, rect.x, rect.y, label, TINSIZE); -} - -template -void drawWidgetLine(W * window, rect_t & rect, LcdFlags color) { - window->drawSolidFilledRect(rect.x, rect.y + rect.h, rect.w, 1, color); -} - -template -bool Choice(W * window, rect_t & rect, const char * label, const char * values, uint8_t & value, uint8_t vmin, uint8_t vmax, LcdFlags flags=0) -{ - rect.h = 30; - bool hasFocus = (flags & HAS_FOCUS) || window->hasFocus(rect.x, rect.y); - LcdFlags textColor = 0; - LcdFlags lineColor = COLOR_THEME_DISABLED; - if (hasFocus) { - textColor = COLOR_THEME_FOCUS; - lineColor = COLOR_THEME_FOCUS; - } - drawTextAtIndex(window, rect.x, rect.y + 9, values, value, textColor); - drawWidgetLine(window, rect, lineColor); - drawWidgetLabel(window, rect, label); - if (window->touchPressed(rect.x, rect.y, rect.w, rect.h)) { - // value ^= 1; - window->setFocus(rect.x, rect.y); - return true; - } - else { - return false; - } -} - - -template -bool TextEdit(W * window, rect_t & rect, const char * label, char * value, uint8_t length, LcdFlags flags=0) -{ - rect.h = 30; - bool hasFocus = (flags & HAS_FOCUS) || window->hasFocus(rect.x, rect.y); - LcdFlags textColor = 0; - LcdFlags lineColor = COLOR_THEME_DISABLED; - if (hasFocus) { - textColor = COLOR_THEME_FOCUS; - lineColor = COLOR_THEME_FOCUS; - } - if (!hasFocus && zlen(value, length) == 0) - menuBodyWindow.drawSizedText(rect.x, rect.y + 9, "---", length, textColor); - else - menuBodyWindow.drawSizedText(rect.x, rect.y + 9, value, length, ZCHAR | textColor); - drawWidgetLine(window, rect, lineColor); - drawWidgetLabel(window, rect, label); - if (window->touchPressed(rect.x, rect.y, rect.w, rect.h)) { - // value ^= 1; - window->setFocus(rect.x, rect.y); - return true; - } - else { - return false; - } -} -#define CHECKBOX(X, label, value) { rect.x = X; rect.w = LCD_W - (X) - 20; uint8_t _value = value; CheckBox(window, rect, label, _value); value = _value; rect.y += rect.h + 10; } -#define CHECKBOX_INVERTED(X, label, value) { rect.x = X; rect.w = LCD_W - (X) - 20; uint8_t _value = !value; CheckBox(window, rect, label, _value); value = !_value; rect.y += rect.h + 10; } -#endif \ No newline at end of file diff --git a/radio/src/gui/colorlcd/menu_model.cpp b/radio/src/gui/colorlcd/menu_model.cpp index 1be155bbbba..e2227f6d082 100644 --- a/radio/src/gui/colorlcd/menu_model.cpp +++ b/radio/src/gui/colorlcd/menu_model.cpp @@ -121,7 +121,7 @@ void ModelMenu::onEvent(event_t event) #if defined(PCBNV14) || defined(PCBPL18) void ModelMenu::addGoToMonitorsButton() { - OpenTxTheme::instance()->createTextButton( + new TextButton( &header, {LCD_W / 2 + 6, MENU_TITLE_TOP + 1, LCD_W / 2 - 8, MENU_TITLE_HEIGHT - 2}, STR_OPEN_CHANNEL_MONITORS, [=]() { pushEvent(EVT_KEY_FIRST(KEY_MODEL)); diff --git a/radio/src/gui/colorlcd/menus.h b/radio/src/gui/colorlcd/menus.h index 12fec9d904b..7c338d949f8 100644 --- a/radio/src/gui/colorlcd/menus.h +++ b/radio/src/gui/colorlcd/menus.h @@ -27,7 +27,7 @@ extern uint8_t menuCalibrationState; enum MenuIcons { - ICON_OPENTX, + ICON_EDGETX, #if defined(HARDWARE_TOUCH) ICON_NEXT, ICON_BACK, diff --git a/radio/src/gui/colorlcd/mixer_edit.h b/radio/src/gui/colorlcd/mixer_edit.h index 76ec6e2220f..2c729cbc7cb 100644 --- a/radio/src/gui/colorlcd/mixer_edit.h +++ b/radio/src/gui/colorlcd/mixer_edit.h @@ -25,7 +25,7 @@ #include "form.h" #include "curve.h" -class FormGroup; +class FormWindow; class MixEditWindow : public Page { diff --git a/radio/src/gui/colorlcd/mixer_edit_adv.cpp b/radio/src/gui/colorlcd/mixer_edit_adv.cpp index 53f8d0553f8..c753b5d979a 100644 --- a/radio/src/gui/colorlcd/mixer_edit_adv.cpp +++ b/radio/src/gui/colorlcd/mixer_edit_adv.cpp @@ -77,38 +77,36 @@ void MixEditAdvanced::buildBody(FormWindow* form) // Trim line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_TRIM, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_INVERTED(mix->carryTrim)); + new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(mix->carryTrim)); // Warning new StaticText(line, rect_t{}, STR_MIXWARNING, 0, COLOR_THEME_PRIMARY1); - auto edit = new NumberEdit(line, rect_t{}, 0, 3, GET_SET_DEFAULT(mix->mixWarn)); + auto edit = new NumberEdit(line, rect_t{0, 0, 100, 0}, 0, 3, GET_SET_DEFAULT(mix->mixWarn)); edit->setZeroText(STR_OFF); // Delay up line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_DELAYUP, 0, COLOR_THEME_PRIMARY1); - edit = new NumberEdit(line, rect_t{}, 0, DELAY_MAX, GET_DEFAULT(mix->delayUp), + edit = new NumberEdit(line, rect_t{0, 0, 100, 0}, 0, DELAY_MAX, GET_DEFAULT(mix->delayUp), SET_VALUE(mix->delayUp, newValue), 0, PREC1); edit->setSuffix("s"); // Delay down new StaticText(line, rect_t{}, STR_DELAYDOWN, 0, COLOR_THEME_PRIMARY1); - edit = - new NumberEdit(line, rect_t{}, 0, DELAY_MAX, GET_DEFAULT(mix->delayDown), - SET_VALUE(mix->delayDown, newValue), 0, PREC1); + edit = new NumberEdit(line, rect_t{0, 0, 100, 0}, 0, DELAY_MAX, GET_DEFAULT(mix->delayDown), + SET_VALUE(mix->delayDown, newValue), 0, PREC1); edit->setSuffix("s"); // Slow up line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_SLOWUP, 0, COLOR_THEME_PRIMARY1); - edit = new NumberEdit(line, rect_t{}, 0, DELAY_MAX, GET_DEFAULT(mix->speedUp), + edit = new NumberEdit(line, rect_t{0, 0, 100, 0}, 0, DELAY_MAX, GET_DEFAULT(mix->speedUp), SET_VALUE(mix->speedUp, newValue), 0, PREC1); edit->setSuffix("s"); // Slow down new StaticText(line, rect_t{}, STR_SLOWDOWN, 0, COLOR_THEME_PRIMARY1); - edit = - new NumberEdit(line, rect_t{}, 0, DELAY_MAX, GET_DEFAULT(mix->speedDown), - SET_VALUE(mix->speedDown, newValue), 0, PREC1); + edit = new NumberEdit(line, rect_t{0, 0, 100, 0}, 0, DELAY_MAX, GET_DEFAULT(mix->speedDown), + SET_VALUE(mix->speedDown, newValue), 0, PREC1); edit->setSuffix("s"); } diff --git a/radio/src/gui/colorlcd/mixer_edit_adv.h b/radio/src/gui/colorlcd/mixer_edit_adv.h index 0f299638629..ea4b53f3bb5 100644 --- a/radio/src/gui/colorlcd/mixer_edit_adv.h +++ b/radio/src/gui/colorlcd/mixer_edit_adv.h @@ -25,7 +25,7 @@ #include "form.h" #include "curve.h" -class FormGroup; +class FormWindow; class MixEditAdvanced : public Page { diff --git a/radio/src/gui/colorlcd/model_curves.cpp b/radio/src/gui/colorlcd/model_curves.cpp index 86fdbbebb59..0d414b71335 100644 --- a/radio/src/gui/colorlcd/model_curves.cpp +++ b/radio/src/gui/colorlcd/model_curves.cpp @@ -42,7 +42,7 @@ DEFINE_LZ4_BITMAP(LBM_DOT); class CurveButton : public Button { public: CurveButton(Window * parent, const rect_t &rect, uint8_t index) : - Button(parent, rect, nullptr, 0, 0, lv_btn_create), + Button(parent, rect, nullptr, 0, 0, etx_button_create), index(index) { padAll(0); @@ -207,12 +207,11 @@ void ModelCurvesPage::build(FormWindow * window) FlexGridLayout grid(col_dsc, row_dsc); - FormWindow::Line* line; + FormWindow::Line* line = nullptr; bool hasFocusButton = false; uint8_t curveIndex = 0; - uint8_t firstCurveIndex; CurveButton* firstCurveButton = nullptr; for (uint8_t index = 0; index < MAX_CURVES; index++) { @@ -222,9 +221,6 @@ void ModelCurvesPage::build(FormWindow * window) lv_obj_set_grid_align(line->getLvObj(), LV_GRID_ALIGN_SPACE_BETWEEN, LV_GRID_ALIGN_SPACE_BETWEEN); } - CurveHeader &curve = g_model.curves[index]; - int8_t * points = curveAddress(index); - // Curve drawing auto button = new CurveButton(line, rect_t{0, 0, CURVE_BTN_W, CURVE_BTH_H}, index); button->setPressHandler([=]() -> uint8_t { @@ -260,7 +256,6 @@ void ModelCurvesPage::build(FormWindow * window) }); if (!firstCurveButton) { - firstCurveIndex = index; firstCurveButton = button; } diff --git a/radio/src/gui/colorlcd/model_flightmodes.cpp b/radio/src/gui/colorlcd/model_flightmodes.cpp index 81713088504..b7464b0e55d 100644 --- a/radio/src/gui/colorlcd/model_flightmodes.cpp +++ b/radio/src/gui/colorlcd/model_flightmodes.cpp @@ -22,8 +22,6 @@ #include "model_flightmodes.h" #include "opentx.h" #include "libopenui.h" -#include "lvgl_widgets/input_mix_line.h" -#include "hal/key_driver.h" #define SET_DIRTY() storageDirty(EE_MODEL) @@ -68,11 +66,9 @@ class FlightModeEdit : public Page header.setTitle(STR_MENUFLIGHTMODES); header.setTitle2(title2); - body.padAll(lv_dpx(8)); - lv_obj_set_scrollbar_mode(body.getLvObj(), LV_SCROLLBAR_MODE_AUTO); - FlexGridLayout grid(line_col_dsc, line_row_dsc, 2); auto form = new FormWindow(&body, rect_t{}); + form->padAll(8); form->setFlexLayout(); FlightModeData* p_fm = &g_model.flightModeData[index]; @@ -116,7 +112,7 @@ class FlightModeEdit : public Page line->padLeft(10); } - auto trim = new FormGroup(line, rect_t{}); + auto trim = new FormWindow(line, rect_t{}); trim->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8)); auto trim_obj = trim->getLvObj(); diff --git a/radio/src/gui/colorlcd/model_gvars.cpp b/radio/src/gui/colorlcd/model_gvars.cpp index 0d8b3718da5..8c81591679c 100644 --- a/radio/src/gui/colorlcd/model_gvars.cpp +++ b/radio/src/gui/colorlcd/model_gvars.cpp @@ -23,7 +23,6 @@ #include "model_gvars.h" #include "libopenui.h" #include "numberedit.h" -#include "lvgl_widgets/input_mix_line.h" #define SET_DIRTY() storageDirty(EE_MODEL) @@ -86,7 +85,7 @@ class GVarStyle // Always update colors in case theme changes lv_style_set_bg_color(&fmContStyle, makeLvColor(COLOR_THEME_PRIMARY2)); - lv_style_set_bg_color(&fmContStyleChecked, makeLvColor(COLOR_THEME_SECONDARY3)); + lv_style_set_bg_color(&fmContStyleChecked, makeLvColor(COLOR_THEME_ACTIVE)); lv_style_set_text_color(&fmLabelStyle, makeLvColor(COLOR_THEME_SECONDARY1)); lv_style_set_text_color(&fmValueStyle, makeLvColor(COLOR_THEME_SECONDARY1)); lv_style_set_text_color(&fmNameStyle, makeLvColor(COLOR_THEME_SECONDARY1)); @@ -515,7 +514,7 @@ class GVarEditWindow : public Page } if (flightMode > 0) { - auto cb = new CheckBox( + auto cb = new ToggleSwitch( line, rect_t{}, [=] { return fmData->gvars[index] <= GVAR_MAX; }, [=](uint8_t checked) { fmData->gvars[index] = checked ? 0 : GVAR_MAX + 1; diff --git a/radio/src/gui/colorlcd/model_inputs.cpp b/radio/src/gui/colorlcd/model_inputs.cpp index 3e42c4dd2b5..597aa0503e0 100644 --- a/radio/src/gui/colorlcd/model_inputs.cpp +++ b/radio/src/gui/colorlcd/model_inputs.cpp @@ -23,7 +23,7 @@ #include "opentx.h" #include "gvar_numberedit.h" #include "libopenui.h" -#include "choiceex.h" +#include "choice.h" #include "model_curves.h" #include "input_edit.h" #include "input_mix_group.h" diff --git a/radio/src/gui/colorlcd/model_logical_switches.cpp b/radio/src/gui/colorlcd/model_logical_switches.cpp index 9c74270fce1..eeea054919c 100644 --- a/radio/src/gui/colorlcd/model_logical_switches.cpp +++ b/radio/src/gui/colorlcd/model_logical_switches.cpp @@ -23,7 +23,6 @@ #include "opentx.h" #include "libopenui.h" #include "switches.h" -#include "lvgl_widgets/input_mix_line.h" #define SET_DIRTY() storageDirty(EE_MODEL) @@ -46,7 +45,7 @@ class LogicalSwitchEditPage : public Page protected: uint8_t index; bool active = false; - FormGroup* logicalSwitchOneWindow = nullptr; + FormWindow* logicalSwitchOneWindow = nullptr; StaticText* headerSwitchName = nullptr; NumberEdit* v2Edit = nullptr; diff --git a/radio/src/gui/colorlcd/model_mixer_scripts.cpp b/radio/src/gui/colorlcd/model_mixer_scripts.cpp index d094e893e92..569e896cb74 100644 --- a/radio/src/gui/colorlcd/model_mixer_scripts.cpp +++ b/radio/src/gui/colorlcd/model_mixer_scripts.cpp @@ -28,7 +28,6 @@ #include "translations.h" #include "menus.h" #include "libopenui.h" -#include "lvgl_widgets/input_mix_line.h" #define SET_DIRTY() storageDirty(EE_MODEL) @@ -99,7 +98,7 @@ class ScriptEditWindow : public Page { // File auto line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_SCRIPT, 0, COLOR_THEME_PRIMARY1); - auto fc = new FileChoice( + new FileChoice( line, rect_t{}, SCRIPTS_MIXES_PATH, SCRIPTS_EXT, LEN_SCRIPT_FILENAME, [=]() { return stringFromNtString(sd->file); }, @@ -121,7 +120,7 @@ class ScriptEditWindow : public Page { if (sio->inputsCount > 0) { line = form->newLine(&grid); - new Subtitle(line, rect_t{}, STR_INPUTS, 0, COLOR_THEME_PRIMARY1); + new Subtitle(line, STR_INPUTS); for (int i = 0; i < sio->inputsCount; i++) { line = form->newLine(&grid); @@ -140,7 +139,7 @@ class ScriptEditWindow : public Page { if (sio->outputsCount > 0) { line = form->newLine(&grid); - new Subtitle(line, rect_t{}, STR_OUTPUTS, 0, COLOR_THEME_PRIMARY1); + new Subtitle(line, STR_OUTPUTS); for (int i = 0; i < sio->outputsCount; i++) { line = form->newLine(&grid); @@ -173,9 +172,9 @@ class ScriptLineButton : public Button const ScriptInternalData* runtimeData, uint8_t index) : Button(parent, rect, nullptr, 0, 0, input_mix_line_create), + index(index), scriptData(scriptData), - runtimeData(runtimeData), - index(index) + runtimeData(runtimeData) { #if LCD_H > LCD_W padTop(5); @@ -294,8 +293,6 @@ void ModelMixerScriptsPage::build(FormWindow * window, int8_t focusIdx) FlexGridLayout grid(col_dsc, row_dsc, 2); - FormWindow::Line* line; - int8_t scriptIdx = 0; for (int8_t idx = 0; idx < MAX_SCRIPTS; idx++) { auto line = window->newLine(&grid); diff --git a/radio/src/gui/colorlcd/model_mixes.cpp b/radio/src/gui/colorlcd/model_mixes.cpp index b8558f23fca..8385fcb4e3f 100644 --- a/radio/src/gui/colorlcd/model_mixes.cpp +++ b/radio/src/gui/colorlcd/model_mixes.cpp @@ -22,7 +22,7 @@ #include "model_mixes.h" #include "opentx.h" #include "libopenui.h" -#include "choiceex.h" +#include "choice.h" #include "bitfield.h" #include "model_inputs.h" #include "gvar_numberedit.h" @@ -532,7 +532,7 @@ void ModelMixesPage::build(FormWindow * window) lv_obj_set_style_flex_cross_place(box_obj, LV_FLEX_ALIGN_CENTER, 0); new StaticText(box, rect_t{}, STR_SHOW_MIXER_MONITORS, 0, COLOR_THEME_PRIMARY1); - new CheckBox( + new ToggleSwitch( box, rect_t{}, [=]() { return showMonitors; }, [=](uint8_t val) { enableMonitors(val); }); diff --git a/radio/src/gui/colorlcd/model_outputs.cpp b/radio/src/gui/colorlcd/model_outputs.cpp index 2793fcc0ef2..e40cd37d1ec 100644 --- a/radio/src/gui/colorlcd/model_outputs.cpp +++ b/radio/src/gui/colorlcd/model_outputs.cpp @@ -314,7 +314,7 @@ void ModelOutputsPage::build(FormWindow *window) lv_obj_set_style_flex_cross_place(box2->getLvObj(), LV_FLEX_ALIGN_CENTER, 0); new StaticText(box2, rect_t{}, STR_ELIMITS, 0, COLOR_THEME_PRIMARY1); - auto cb = new CheckBox(box2, rect_t{}, GET_SET_DEFAULT(g_model.extendedLimits)); + new ToggleSwitch(box2, rect_t{}, GET_SET_DEFAULT(g_model.extendedLimits)); for (uint8_t ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++) { diff --git a/radio/src/gui/colorlcd/model_select.cpp b/radio/src/gui/colorlcd/model_select.cpp index ff998636297..bad8f4166d9 100644 --- a/radio/src/gui/colorlcd/model_select.cpp +++ b/radio/src/gui/colorlcd/model_select.cpp @@ -78,7 +78,7 @@ constexpr coord_t MODEL_SELECT_CELL_WIDTH = class ToolbarButton : public Button { public: - ToolbarButton(FormGroup *parent, const rect_t &rect, const uint8_t *bitmap, + ToolbarButton(FormWindow *parent, const rect_t &rect, const uint8_t *bitmap, std::function pressHandler = nullptr) : Button(parent, rect, pressHandler, 0), _bitmap(bitmap) { @@ -240,7 +240,7 @@ class ButtonHolder : public FormWindow class ModelButton : public Button { public: - ModelButton(FormGroup *parent, const rect_t &rect, ModelCell *modelCell, std::function setSelected) : + ModelButton(FormWindow *parent, const rect_t &rect, ModelCell *modelCell, std::function setSelected) : Button(parent, rect), modelCell(modelCell) { m_setSelected = std::move(setSelected); @@ -606,7 +606,7 @@ class LabelDialog : public Dialog new TextEdit(form, rect_t{}, label, LABEL_LENGTH); - auto box = new FormGroup(form, rect_t{}); + auto box = new FormWindow(form, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW); auto box_obj = box->getLvObj(); @@ -738,7 +738,8 @@ void ModelLabelsWindow::newModel() #if defined(LUA) // If there is a wizard Lua script, fire it up - snprintf(path, LEN_BUFFER, "%s/%s%s", path, name.c_str(), SCRIPT_EXT); + int len = strlen(path); + snprintf(path+len, LEN_BUFFER-len, "/%s%s", name.c_str(), SCRIPT_EXT); if (f_stat(path, 0) == FR_OK) { luaExec(path); StandaloneLuaWindow::instance()->attach(); @@ -898,7 +899,10 @@ void ModelLabelsWindow::buildBody(FormWindow *window) new ProgressDialog(this, STR_RENAME_LABEL, [=]() {}); modelslabels.renameLabel( oldLabel, newLabel, [=](const char *name, int percentage) { - rndialog->updateProgress(name, percentage); + rndialog->setTitle(std::string(STR_RENAME_LABEL) + " " + name); + rndialog->updateProgress(percentage); + if (percentage >= 100) + rndialog->closeDialog(); }); auto labels = getLabels(); lblselector->setNames(labels); @@ -915,7 +919,10 @@ void ModelLabelsWindow::buildBody(FormWindow *window) new ProgressDialog(this, STR_DELETE_LABEL, [=]() {}); modelslabels.removeLabel( labelToDelete, [=](const char *name, int percentage) { - deldialog->updateProgress(name, percentage); + deldialog->setTitle(std::string(STR_RENAME_LABEL) + " " + name); + deldialog->updateProgress(percentage); + if (percentage >= 100) + deldialog->closeDialog(); }); auto labels = getLabels(); std::set newset; @@ -989,39 +996,3 @@ void ModelLabelsWindow::setTitle() header.setTitle(STR_MANAGE_MODELS); header.setTitle2(title2); } - -//----------------------------------------------------------------------------- - -ProgressDialog::ProgressDialog(Window *parent, std::string title, - std::function onClose) : - Dialog(parent, title, rect_t{}), - progress(new Progress(&content->form, rect_t{})), - onClose(std::move(onClose)), - _title(title) -{ - 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(const char *filename, int percentage) -{ - content->setTitle(_title + " " + filename); - progress->setValue(percentage); - if (percentage >= 100) { - deleteLater(); - onClose(); - } else { - lv_refr_now(nullptr); - } -} - -// disable keys -void ProgressDialog::onEvent(event_t) { return; } diff --git a/radio/src/gui/colorlcd/model_select.h b/radio/src/gui/colorlcd/model_select.h index 36421a5abbe..8702c5dcdd9 100644 --- a/radio/src/gui/colorlcd/model_select.h +++ b/radio/src/gui/colorlcd/model_select.h @@ -106,24 +106,4 @@ class ModelLabelsWindow : public Page void setTitle(); }; -class ProgressDialog : public Dialog -{ - uint32_t lastUpdate = 0; - Progress *progress; - - std::function onClose; - - public: - ProgressDialog(Window *parent, std::string title, - std::function onClose); - - void updateProgress(const char *filename, int percentage); - - // disable keys - void onEvent(event_t) override; - - protected: - std::string _title; -}; - #endif // _MODEL_SELECT_H_ diff --git a/radio/src/gui/colorlcd/model_setup.cpp b/radio/src/gui/colorlcd/model_setup.cpp index 72699f05f5c..169b0911726 100644 --- a/radio/src/gui/colorlcd/model_setup.cpp +++ b/radio/src/gui/colorlcd/model_setup.cpp @@ -110,7 +110,7 @@ SubScreenButton::SubScreenButton(Window* parent, const char* text, Button(parent, rect_t{}, [=]() -> uint8_t { pressHandler(); return 0; - }, 0, 0, lv_btn_create), + }, 0, 0, etx_vbutton_create), text(text) { lv_obj_add_event_cb(lvobj, SubScreenButton::event_cb, LV_EVENT_ALL, nullptr); @@ -404,12 +404,12 @@ void ModelSetupPage::build(FormWindow * window) static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; - auto oform = new FormGroup(window, rect_t{}); + auto oform = new FormWindow(window, rect_t{}); oform->setFlexLayout(LV_FLEX_FLOW_COLUMN, lv_dpx(PAGE_PADDING)); oform->padAll(PAGE_PADDING); // Modules - auto form = new FormGroup(oform, rect_t{}); + auto form = new FormWindow(oform, rect_t{}); form->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(PAGE_PADDING)); lv_obj_set_grid_dsc_array(form->getLvObj(), col_dsc, row_dsc); @@ -423,7 +423,7 @@ void ModelSetupPage::build(FormWindow * window) lv_obj_set_grid_cell(btn->getLvObj(), LV_GRID_ALIGN_STRETCH, 2, 1, LV_GRID_ALIGN_CENTER, 0, 1); // Timer buttons - form = new FormGroup(oform, rect_t{}); + form = new FormWindow(oform, rect_t{}); form->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(PAGE_PADDING)); lv_obj_set_grid_dsc_array(form->getLvObj(), col_dsc, row_dsc); @@ -436,7 +436,7 @@ void ModelSetupPage::build(FormWindow * window) btn = new SubScreenButton(form, TR_TIMER "3", []() { new TimerWindow(2); }); lv_obj_set_grid_cell(btn->getLvObj(), LV_GRID_ALIGN_STRETCH, 2, 1, LV_GRID_ALIGN_CENTER, 0, 1); - form = new FormGroup(oform, rect_t{}); + form = new FormWindow(oform, rect_t{}); form->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(PAGE_PADDING)); lv_obj_set_grid_dsc_array(form->getLvObj(), col_dsc, row_dsc); @@ -449,7 +449,7 @@ void ModelSetupPage::build(FormWindow * window) btn = new SubScreenButton(form, STR_THROTTLE_LABEL, []() { new ThrottleParams(); }); lv_obj_set_grid_cell(btn->getLvObj(), LV_GRID_ALIGN_STRETCH, 2, 1, LV_GRID_ALIGN_CENTER, 0, 1); - form = new FormGroup(oform, rect_t{}); + form = new FormWindow(oform, rect_t{}); form->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(PAGE_PADDING)); lv_obj_set_grid_dsc_array(form->getLvObj(), col_dsc, row_dsc); diff --git a/radio/src/gui/colorlcd/model_telemetry.cpp b/radio/src/gui/colorlcd/model_telemetry.cpp index d364b781e72..e38bb624a77 100644 --- a/radio/src/gui/colorlcd/model_telemetry.cpp +++ b/radio/src/gui/colorlcd/model_telemetry.cpp @@ -24,7 +24,6 @@ #include "model_telemetry.h" #include "opentx.h" #include "libopenui.h" -#include "lvgl_widgets/input_mix_line.h" #define SET_DIRTY() storageDirty(EE_MODEL) @@ -696,19 +695,19 @@ class SensorEditWindow : public Page { paramLines[P_AUTOOFFSET] = form->newLine(&grid); new StaticText(paramLines[P_AUTOOFFSET], rect_t{}, STR_AUTOOFFSET, 0, COLOR_THEME_PRIMARY1); - new CheckBox(paramLines[P_AUTOOFFSET], rect_t{}, GET_SET_DEFAULT(sensor->autoOffset)); + new ToggleSwitch(paramLines[P_AUTOOFFSET], rect_t{}, GET_SET_DEFAULT(sensor->autoOffset)); paramLines[P_ONLYPOS] = form->newLine(&grid); new StaticText(paramLines[P_ONLYPOS], rect_t{}, STR_ONLYPOSITIVE, 0, COLOR_THEME_PRIMARY1); - new CheckBox(paramLines[P_ONLYPOS], rect_t{}, GET_SET_DEFAULT(sensor->onlyPositive)); + new ToggleSwitch(paramLines[P_ONLYPOS], rect_t{}, GET_SET_DEFAULT(sensor->onlyPositive)); paramLines[P_FILTER] = form->newLine(&grid); new StaticText(paramLines[P_FILTER], rect_t{}, STR_FILTER, 0, COLOR_THEME_PRIMARY1); - new CheckBox(paramLines[P_FILTER], rect_t{}, GET_SET_DEFAULT(sensor->filter)); + new ToggleSwitch(paramLines[P_FILTER], rect_t{}, GET_SET_DEFAULT(sensor->filter)); paramLines[P_PERSISTENT] = form->newLine(&grid); new StaticText(paramLines[P_PERSISTENT], rect_t{}, STR_PERSISTENT, 0, COLOR_THEME_PRIMARY1); - new CheckBox(paramLines[P_PERSISTENT], rect_t{}, GET_DEFAULT(sensor->persistent), [=](int32_t newValue) { + new ToggleSwitch(paramLines[P_PERSISTENT], rect_t{}, GET_DEFAULT(sensor->persistent), [=](int32_t newValue) { sensor->persistent = newValue; if (!sensor->persistent) sensor->persistentValue = 0; @@ -718,7 +717,7 @@ class SensorEditWindow : public Page { // Logs line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_LOGS, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_DEFAULT(sensor->logs), [=](int32_t newValue) { + new ToggleSwitch(line, rect_t{}, GET_DEFAULT(sensor->logs), [=](int32_t newValue) { sensor->logs = newValue; logsClose(); SET_DIRTY(); @@ -804,7 +803,7 @@ void ModelTelemetryPage::buildSensorList(int8_t focusSensorIndex) return; } } - for (uint8_t i = idx - 1; i >= 0; i -= 1) { + for (int8_t i = idx - 1; i >= 0; i -= 1) { if (g_model.telemetrySensors[i].isAvailable()) { rebuild(window, i); return; @@ -836,6 +835,12 @@ void ModelTelemetryPage::buildSensorList(int8_t focusSensorIndex) } } +#if LCD_W > LCD_H +#define NUM_EDIT_W 100 +#else +#define NUM_EDIT_W 65 +#endif + void ModelTelemetryPage::build(FormWindow * window) { window->padAll(4); @@ -844,7 +849,7 @@ void ModelTelemetryPage::build(FormWindow * window) this->window = window; // Sensors - new Subtitle(window, rect_t{}, STR_TELEMETRY_SENSORS, 0, COLOR_THEME_PRIMARY1); + new Subtitle(window, STR_TELEMETRY_SENSORS); sensorWindow = new FormWindow(window, rect_t{}); sensorWindow->padAll(0); @@ -906,34 +911,34 @@ void ModelTelemetryPage::build(FormWindow * window) line = window->newLine(&grid); line->padLeft(10); new StaticText(line, rect_t{}, STR_SHOW_INSTANCE_ID, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_model.showInstanceIds)); + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(g_model.showInstanceIds)); // Ignore instance button line = window->newLine(&grid); line->padLeft(10); new StaticText(line, rect_t{}, STR_IGNORE_INSTANCE, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_model.ignoreSensorIds)); + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(g_model.ignoreSensorIds)); // RX stat - new Subtitle(window, rect_t{}, getRxStatLabels()->label, 0, COLOR_THEME_PRIMARY1); + new Subtitle(window, getRxStatLabels()->label); line = window->newLine(&grid); line->padLeft(10); new StaticText(line, rect_t{}, STR_LOWALARM, 0, COLOR_THEME_PRIMARY1); - new NumberEdit(line, rect_t{}, 0, 100, GET_SET_DEFAULT(g_model.rfAlarms.warning)); + new NumberEdit(line, rect_t{0, 0, NUM_EDIT_W, 0}, 0, 100, GET_SET_DEFAULT(g_model.rfAlarms.warning)); line = window->newLine(&grid); line->padLeft(10); new StaticText(line, rect_t{}, STR_CRITICALALARM, 0, COLOR_THEME_PRIMARY1); - new NumberEdit(line, rect_t{}, 0, 100, GET_SET_DEFAULT(g_model.rfAlarms.critical)); + new NumberEdit(line, rect_t{0, 0, NUM_EDIT_W, 0}, 0, 100, GET_SET_DEFAULT(g_model.rfAlarms.critical)); line = window->newLine(&grid); line->padLeft(10); new StaticText(line, rect_t{}, STR_DISABLE_ALARM, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_model.disableTelemetryWarning)); + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(g_model.disableTelemetryWarning)); // Vario - new Subtitle(window, rect_t{}, STR_VARIO, 0, COLOR_THEME_PRIMARY1); + new Subtitle(window, STR_VARIO); FlexGridLayout grid5(col_dsc5, row_dsc, 4); @@ -956,20 +961,20 @@ void ModelTelemetryPage::build(FormWindow * window) line->padLeft(10); new StaticText(line, rect_t{}, STR_RANGE, 0, COLOR_THEME_PRIMARY1); - auto vMin = new NumberEdit(line, rect_t{}, -17, 17, GET_SET_WITH_OFFSET(g_model.varioData.min, -10)); + auto vMin = new NumberEdit(line, rect_t{0, 0, NUM_EDIT_W, 0}, -17, 17, GET_SET_WITH_OFFSET(g_model.varioData.min, -10)); vMin->setAvailableHandler([](int val) { return val < g_model.varioData.max + 10; }); - auto vMax = new NumberEdit(line, rect_t{}, -17, 17, GET_SET_WITH_OFFSET(g_model.varioData.max, 10)); + auto vMax = new NumberEdit(line, rect_t{0, 0, NUM_EDIT_W, 0}, -17, 17, GET_SET_WITH_OFFSET(g_model.varioData.max, 10)); vMax->setAvailableHandler([](int val) { return g_model.varioData.min - 10 < val; }); line = window->newLine(&grid5); line->padLeft(10); new StaticText(line, rect_t{}, STR_CENTER, 0, COLOR_THEME_PRIMARY1); - auto cMin = new NumberEdit(line, rect_t{}, -15, 15, GET_SET_WITH_OFFSET(g_model.varioData.centerMin, -5), 0, PREC1); + auto cMin = new NumberEdit(line, rect_t{0, 0, NUM_EDIT_W, 0}, -15, 15, GET_SET_WITH_OFFSET(g_model.varioData.centerMin, -5), 0, PREC1); cMin->setAvailableHandler([](int val) { return val < g_model.varioData.centerMax + 5; }); - auto cMax = new NumberEdit(line, rect_t{}, -15, 15, GET_SET_WITH_OFFSET(g_model.varioData.centerMax, 5), 0, PREC1); + auto cMax = new NumberEdit(line, rect_t{0, 0, NUM_EDIT_W, 0}, -15, 15, GET_SET_WITH_OFFSET(g_model.varioData.centerMax, 5), 0, PREC1); cMax->setAvailableHandler([](int val) { return g_model.varioData.centerMin - 5 < val; }); new Choice(line, rect_t{}, STR_VVARIOCENTER, 0, 1, GET_SET_DEFAULT(g_model.varioData.centerSilent)); diff --git a/radio/src/gui/colorlcd/model_templates.cpp b/radio/src/gui/colorlcd/model_templates.cpp index 9d24db9cbed..d2c46ef2090 100644 --- a/radio/src/gui/colorlcd/model_templates.cpp +++ b/radio/src/gui/colorlcd/model_templates.cpp @@ -30,8 +30,6 @@ static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; TemplatePage::TemplatePage() : Page(ICON_MODEL_SELECT) { - body.padAll(0); - auto form = new FormWindow(&body, rect_t{}); form->setFlexLayout(); form->padAll(4); diff --git a/radio/src/gui/colorlcd/model_usbjoystick.cpp b/radio/src/gui/colorlcd/model_usbjoystick.cpp index b431cbc3f55..9738b5ef3cc 100644 --- a/radio/src/gui/colorlcd/model_usbjoystick.cpp +++ b/radio/src/gui/colorlcd/model_usbjoystick.cpp @@ -23,7 +23,6 @@ #include "usb_joystick.h" #include "channel_bar.h" #include "button_matrix.h" -#include "lvgl_widgets/input_mix_line.h" #include "opentx.h" @@ -111,6 +110,15 @@ class USBChannelButtonSel : public ButtonMatrix m_channel(channel), m_setValue(std::move(_setValue)) { + bg_color[0] = makeLvColor(COLOR_THEME_PRIMARY2); // Unused + fg_color[0] = makeLvColor(COLOR_THEME_SECONDARY1); + bg_color[1] = makeLvColor(COLOR_THEME_DISABLED); // Used by other channel_bar + fg_color[1] = makeLvColor(COLOR_THEME_PRIMARY1); + bg_color[2] = makeLvColor(COLOR_THEME_ACTIVE); // Used by this channel + fg_color[2] = makeLvColor(COLOR_THEME_PRIMARY1); + bg_color[3] = makeLvColor(COLOR_THEME_WARNING); // Collision + fg_color[3] = makeLvColor(COLOR_THEME_PRIMARY2); + initBtnMap(USBCH_BTNMX_COL, USBJ_BUTTON_SIZE); char snum[5]; for (uint8_t btn = 0; btn < USBJ_BUTTON_SIZE; btn++) { @@ -119,6 +127,8 @@ class USBChannelButtonSel : public ButtonMatrix } update(); + lv_obj_set_style_radius(lvobj, LV_RADIUS_CIRCLE, LV_PART_ITEMS); + lv_obj_add_event_cb(lvobj, btnsel_event_cb, LV_EVENT_DRAW_PART_BEGIN, this); memset(m_btns, 0, USBJ_BUTTON_SIZE); @@ -137,16 +147,11 @@ class USBChannelButtonSel : public ButtonMatrix updateState(); } - void setValue(int val) + void onPress(uint8_t btn_id) override { if (m_setValue) { - m_setValue(val); + m_setValue(btn_id); } - } - - void onPress(uint8_t btn_id) override - { - setValue(btn_id); updateState(); } @@ -161,16 +166,29 @@ class USBChannelButtonSel : public ButtonMatrix void updateState() { USBJoystickChData * cch = usbJChAddress(m_channel); - - for(uint8_t i = 0; i < USBJ_BUTTON_SIZE; i++) m_btns[i] &= 1; uint8_t last = cch->lastBtnNum(); - for(uint8_t b = cch->btn_num; b <= last; b++) m_btns[b] |= 2; + uint8_t i; + + for (i = 0; i < USBJ_BUTTON_SIZE; i++) + m_btns[i] &= 1; + + for(i = cch->btn_num; i <= last; i++) + m_btns[i] |= 2; + } + + void setColor(lv_obj_draw_part_dsc_t* dsc) + { + uint8_t state = getBtnState((uint8_t)dsc->id); + dsc->rect_dsc->bg_color = bg_color[state]; + dsc->label_dsc->color = fg_color[state]; } protected: uint8_t m_channel = 0; std::function m_setValue; uint8_t m_btns[USBJ_BUTTON_SIZE]; + lv_color_t bg_color[4]; + lv_color_t fg_color[4]; }; static void btnsel_event_cb(lv_event_t* e) @@ -181,26 +199,8 @@ static void btnsel_event_cb(lv_event_t* e) lv_obj_draw_part_dsc_t* dsc = lv_event_get_draw_part_dsc(e); if(dsc->class_p == &lv_btnmatrix_class && dsc->type == LV_BTNMATRIX_DRAW_PART_BTN) { - dsc->rect_dsc->radius = LV_RADIUS_CIRCLE; auto btsel = (USBChannelButtonSel*)lv_event_get_user_data(e); - - uint8_t state = btsel->getBtnState((uint8_t)dsc->id); - if (state == 1) { - dsc->rect_dsc->bg_color = makeLvColor(COLOR_THEME_DISABLED); - dsc->label_dsc->color = makeLvColor(COLOR_THEME_PRIMARY1); - } - else if (state == 2) { - dsc->rect_dsc->bg_color = makeLvColor(COLOR_THEME_EDIT); - dsc->label_dsc->color = makeLvColor(COLOR_THEME_PRIMARY2); - } - else if (state == 3) { - dsc->rect_dsc->bg_color = makeLvColor(COLOR_THEME_WARNING); - 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); - } + btsel->setColor(dsc); } } } @@ -298,13 +298,6 @@ class USBChannelEditWindow : public Page auto line = form->newLine(&grid); - line->padTop(0); - line->padBottom(0); - collisionText = new StaticText(line, rect_t{}, "", OPAQUE, FONT(BOLD) | COLOR_THEME_PRIMARY2 | CENTERED); - collisionText->setBackgroundColor(COLOR_THEME_WARNING); - lv_obj_set_grid_cell(collisionText->getLvObj(), LV_GRID_ALIGN_STRETCH, 0, USBCH_COLS, LV_GRID_ALIGN_CENTER, 0, 1); - - line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_USBJOYSTICK_CH_MODE, 0, COLOR_THEME_PRIMARY1); new Choice(line, rect_t{}, STR_VUSBJOYSTICK_CH_MODE, 0, USBJOYS_CH_LAST, GET_DEFAULT(cch->mode), SET_VALUE_WUPDATE(cch->mode)); @@ -314,7 +307,7 @@ class USBChannelEditWindow : public Page #endif new StaticText(line, rect_t{}, STR_USBJOYSTICK_CH_INVERSION, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(cch->inversion)); + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(cch->inversion)); line = form->newLine(&grid); m_btnModeFrame = new FormWindow(line, rect_t{}); @@ -359,6 +352,13 @@ class USBChannelEditWindow : public Page new Choice(m_simModeLine, rect_t{}, STR_VUSBJOYSTICK_CH_SIM, 0, USBJOYS_SIM_LAST, GET_DEFAULT(cch->param), SET_VALUE_WUPDATE(cch->param)); + line = form->newLine(&grid); + line->padTop(0); + line->padBottom(0); + collisionText = new StaticText(line, rect_t{}, "", OPAQUE, FONT(BOLD) | COLOR_THEME_PRIMARY2 | CENTERED); + collisionText->setBackgroundColor(COLOR_THEME_WARNING); + lv_obj_set_grid_cell(collisionText->getLvObj(), LV_GRID_ALIGN_STRETCH, 0, USBCH_COLS, LV_GRID_ALIGN_CENTER, 0, 1); + update(); } }; @@ -546,7 +546,7 @@ ModelUSBJoystickPage::ModelUSBJoystickPage() : _ApplyBtn = new TextButton(line, rect_t{}, STR_USBJOYSTICK_APPLY_CHANGES, [=]() { onUSBJoystickModelChanged(); this->update(); return 0; }); - auto btngrp = new FormGroup(form, rect_t{}); + auto btngrp = new FormWindow(form, rect_t{}); _ChannelsGroup = btngrp; btngrp->setFlexLayout(); btngrp->padRow(lv_dpx(4)); diff --git a/radio/src/gui/colorlcd/model_usbjoystick.h b/radio/src/gui/colorlcd/model_usbjoystick.h index 9d5e13cad31..0d6ab5d24e8 100644 --- a/radio/src/gui/colorlcd/model_usbjoystick.h +++ b/radio/src/gui/colorlcd/model_usbjoystick.h @@ -23,7 +23,7 @@ #include "page.h" -class FormGroup; +class FormWindow; class USBChannelLineButton; class ModelUSBJoystickPage : public Page diff --git a/radio/src/gui/colorlcd/module_setup.cpp b/radio/src/gui/colorlcd/module_setup.cpp index 98450e1b1e1..30f2c95d5e4 100644 --- a/radio/src/gui/colorlcd/module_setup.cpp +++ b/radio/src/gui/colorlcd/module_setup.cpp @@ -69,7 +69,7 @@ static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, struct FailsafeChoice; -class ModuleWindow : public FormGroup +class ModuleWindow : public FormWindow { public: ModuleWindow(Window* parent, uint8_t moduleIdx); @@ -99,7 +99,7 @@ class ModuleWindow : public FormGroup void updateIDStaticText(int mdIdx); }; -struct FailsafeChoice : public FormGroup { +struct FailsafeChoice : public FormWindow { FailsafeChoice(Window* parent, uint8_t moduleIdx); void update() const; @@ -124,7 +124,7 @@ static void fs_changed(lv_event_t* e) } FailsafeChoice::FailsafeChoice(Window* parent, uint8_t moduleIdx) : - FormGroup(parent, rect_t{}) + FormWindow(parent, rect_t{}) { setFlexLayout(LV_FLEX_FLOW_ROW); lv_obj_set_width(lvobj, LV_SIZE_CONTENT); @@ -163,7 +163,7 @@ static void mw_refresh_cb(lv_event_t* e) } ModuleWindow::ModuleWindow(Window* parent, uint8_t moduleIdx) : - FormGroup(parent, rect_t{}), + FormWindow(parent, rect_t{}), moduleIdx(moduleIdx) { setFlexLayout(); @@ -260,7 +260,7 @@ void ModuleWindow::updateModule() if(isModuleModelIndexAvailable(moduleIdx)) { auto line = newLine(&grid); new StaticText(line, rect_t{},""); - auto box = new FormGroup(line, rect_t{}); + auto box = new FormWindow(line, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8)); lv_obj_set_width(box->getLvObj(), LV_SIZE_CONTENT); idUnique = new StaticText(box, rect_t{}, "", 0, 0); @@ -270,7 +270,7 @@ void ModuleWindow::updateModule() auto line = newLine(&grid); new StaticText(line, rect_t{}, STR_RECEIVER, 0, COLOR_THEME_PRIMARY1); - auto box = new FormGroup(line, rect_t{}); + auto box = new FormWindow(line, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8)); lv_obj_set_width(box->getLvObj(), LV_SIZE_CONTENT); @@ -397,7 +397,7 @@ void ModuleWindow::updateModule() auto line = newLine(&grid); new StaticText(line, rect_t{}, STR_MODULE, 0, COLOR_THEME_PRIMARY1); - auto box = new FormGroup(line, rect_t{}); + auto box = new FormWindow(line, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8)); registerButton = new TextButton(box, rect_t{}, STR_REGISTER); @@ -460,7 +460,7 @@ void ModuleWindow::updateModule() auto line = newLine(&grid); new StaticText(line, rect_t{}, STR_REFRESHRATE, 0, COLOR_THEME_PRIMARY1); - auto box = new FormGroup(line, rect_t{}); + auto box = new FormWindow(line, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW); auto edit = new NumberEdit( @@ -483,7 +483,7 @@ void ModuleWindow::updateModule() if (isModuleGhost(moduleIdx)) { auto line = newLine(&grid); new StaticText(line, rect_t{}, "Raw 12 bits", 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(md->ghost.raw12bits)); + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(md->ghost.raw12bits)); } updateSubType(); @@ -746,10 +746,7 @@ ModulePage::ModulePage(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP) header.setTitle(STR_MENU_MODEL_SETUP); header.setTitle2(title2); - body.padAll(0); - lv_obj_set_scrollbar_mode(body.getLvObj(), LV_SCROLLBAR_MODE_AUTO); - - auto form = new FormGroup(&body, rect_t{}); + auto form = new FormWindow(&body, rect_t{}); form->setFlexLayout(); form->padAll(lv_dpx(8)); @@ -759,7 +756,7 @@ ModulePage::ModulePage(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP) auto line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_MODE, 0, COLOR_THEME_PRIMARY1); - auto box = new FormGroup(line, rect_t{}); + auto box = new FormWindow(line, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW); lv_obj_set_width(box->getLvObj(), LV_SIZE_CONTENT); diff --git a/radio/src/gui/colorlcd/mpm_settings.cpp b/radio/src/gui/colorlcd/mpm_settings.cpp index 84fc94f7e38..5b561f41152 100644 --- a/radio/src/gui/colorlcd/mpm_settings.cpp +++ b/radio/src/gui/colorlcd/mpm_settings.cpp @@ -36,20 +36,20 @@ static void update_mpm_settings(lv_event_t* e) lv_event_send(ms->getParent()->getLvObj(), LV_EVENT_REFRESH, nullptr); } -struct MPMProtoOption : public FormGroup::Line +struct MPMProtoOption : public FormWindow::Line { StaticText* label; Choice* choice; NumberEdit* edit; - CheckBox* cb; + ToggleSwitch* cb; DynamicNumber* rssi; - MPMProtoOption(FormGroup* form, FlexGridLayout *layout); + MPMProtoOption(FormWindow* form, FlexGridLayout *layout); void update(const MultiRfProtocols::RfProto* rfProto, ModuleData* md, uint8_t moduleIdx); }; -MPMProtoOption::MPMProtoOption(FormGroup* form, FlexGridLayout *layout) : - FormGroup::Line(form, layout) +MPMProtoOption::MPMProtoOption(FormWindow* form, FlexGridLayout *layout) : + FormWindow::Line(form, layout) { if (layout) layout->resetPos(); label = new StaticText(this, rect_t{}, "", 0, COLOR_THEME_PRIMARY1); @@ -60,7 +60,7 @@ MPMProtoOption::MPMProtoOption(FormGroup* form, FlexGridLayout *layout) : choice = new Choice(box, rect_t{}, 0, 0, nullptr); edit = new NumberEdit(box, rect_t{}, 0, 0, nullptr); - cb = new CheckBox(box, rect_t{}, nullptr, nullptr); + cb = new ToggleSwitch(box, rect_t{}, nullptr, nullptr); rssi = new DynamicNumber( box, rect_t{}, [] { return (uint16_t)TELEMETRY_RSSI(); }, 0, getRxStatLabels()->label, getRxStatLabels()->unit); rssi->padTop(5); @@ -148,11 +148,11 @@ void MPMProtoOption::update(const MultiRfProtocols::RfProto* rfProto, ModuleData } } -struct MPMSubtype : public FormGroup::Line +struct MPMSubtype : public FormWindow::Line { Choice* choice; - MPMSubtype(FormGroup* form, FlexGridLayout *layout, uint8_t moduleIdx); + MPMSubtype(FormWindow* form, FlexGridLayout *layout, uint8_t moduleIdx); void update(const MultiRfProtocols::RfProto* rfProto, uint8_t moduleIdx); void checkEvents(); @@ -187,8 +187,8 @@ static void subtype_event_cb(lv_event_t* e) if (obj) lv_event_send(obj, LV_EVENT_VALUE_CHANGED, nullptr); } -MPMSubtype::MPMSubtype(FormGroup* form, FlexGridLayout *layout, uint8_t moduleIdx) : - FormGroup::Line(form, layout) +MPMSubtype::MPMSubtype(FormWindow* form, FlexGridLayout *layout, uint8_t moduleIdx) : + FormWindow::Line(form, layout) { this->moduleIdx = moduleIdx; this->DSM2lastSubType = g_model.moduleData[this->moduleIdx].subType; @@ -227,16 +227,16 @@ void MPMSubtype::update(const MultiRfProtocols::RfProto* rfProto, uint8_t module lv_event_send(choice->getLvObj(), LV_EVENT_VALUE_CHANGED, &stop); } -struct MPMServoRate : public FormGroup::Line { - MPMServoRate(FormGroup* form, FlexGridLayout* layout, uint8_t moduleIdx); +struct MPMServoRate : public FormWindow::Line { + MPMServoRate(FormWindow* form, FlexGridLayout* layout, uint8_t moduleIdx); void update() const { lv_event_send(choice->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr); } private: Choice* choice; }; -MPMServoRate::MPMServoRate(FormGroup* form, FlexGridLayout *layout, uint8_t moduleIdx) : - FormGroup::Line(form, layout) +MPMServoRate::MPMServoRate(FormWindow* form, FlexGridLayout *layout, uint8_t moduleIdx) : + FormWindow::Line(form, layout) { if (layout) layout->resetPos(); new StaticText(this, rect_t{}, STR_MULTI_SERVOFREQ, 0, COLOR_THEME_PRIMARY1); @@ -249,40 +249,40 @@ MPMServoRate::MPMServoRate(FormGroup* form, FlexGridLayout *layout, uint8_t modu md->multi.optionValue, (md->multi.optionValue & 0xFD) + (newValue << 1))); } -struct MPMAutobind : public FormGroup::Line { - MPMAutobind(FormGroup* form, FlexGridLayout* layout, uint8_t moduleIdx); +struct MPMAutobind : public FormWindow::Line { + MPMAutobind(FormWindow* form, FlexGridLayout* layout, uint8_t moduleIdx); void update() const { cb->update(); } private: - CheckBox* cb; + ToggleSwitch* cb; }; -MPMAutobind::MPMAutobind(FormGroup* form, FlexGridLayout *layout, uint8_t moduleIdx) : - FormGroup::Line(form, layout) +MPMAutobind::MPMAutobind(FormWindow* form, FlexGridLayout *layout, uint8_t moduleIdx) : + FormWindow::Line(form, layout) { if (layout) layout->resetPos(); new StaticText(this, rect_t{}, STR_MULTI_AUTOBIND, 0, COLOR_THEME_PRIMARY1); auto md = &g_model.moduleData[moduleIdx]; - cb = new CheckBox(this, rect_t{}, GET_SET_DEFAULT(md->multi.autoBindMode)); + cb = new ToggleSwitch(this, rect_t{}, GET_SET_DEFAULT(md->multi.autoBindMode)); } -struct MPMChannelMap : public FormGroup::Line +struct MPMChannelMap : public FormWindow::Line { - MPMChannelMap(FormGroup* form, FlexGridLayout *layout, uint8_t moduleIdx); + MPMChannelMap(FormWindow* form, FlexGridLayout *layout, uint8_t moduleIdx); void update(const MultiRfProtocols::RfProto* rfProto); private: - CheckBox* cb; + ToggleSwitch* cb; }; -MPMChannelMap::MPMChannelMap(FormGroup* form, FlexGridLayout *layout, uint8_t moduleIdx) : - FormGroup::Line(form, layout) +MPMChannelMap::MPMChannelMap(FormWindow* form, FlexGridLayout *layout, uint8_t moduleIdx) : + FormWindow::Line(form, layout) { if (layout) layout->resetPos(); new StaticText(this, rect_t{}, STR_DISABLE_CH_MAP, 0, COLOR_THEME_PRIMARY1); auto md = &g_model.moduleData[moduleIdx]; - cb = new CheckBox(this, rect_t{}, GET_SET_DEFAULT(md->multi.disableMapping)); + cb = new ToggleSwitch(this, rect_t{}, GET_SET_DEFAULT(md->multi.disableMapping)); } void MPMChannelMap::update(const MultiRfProtocols::RfProto* rfProto) @@ -298,7 +298,7 @@ void MPMChannelMap::update(const MultiRfProtocols::RfProto* rfProto) MultimoduleSettings::MultimoduleSettings(Window *parent, const FlexGridLayout &g, uint8_t moduleIdx) : - FormGroup(parent, rect_t{}), md(&g_model.moduleData[moduleIdx]), + FormWindow(parent, rect_t{}), md(&g_model.moduleData[moduleIdx]), moduleIdx(moduleIdx) { FlexGridLayout grid(g); @@ -336,13 +336,13 @@ MultimoduleSettings::MultimoduleSettings(Window *parent, // Low power mode line = newLine(&grid); new StaticText(line, rect_t{}, STR_MULTI_LOWPOWER, 0, COLOR_THEME_PRIMARY1); - lp_mode = new CheckBox(line, rect_t{}, GET_SET_DEFAULT(md->multi.lowPowerMode)); + lp_mode = new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(md->multi.lowPowerMode)); #if defined(MANUFACTURER_FRSKY) // Disable telemetry line = newLine(&grid); new StaticText(line, rect_t{}, STR_DISABLE_TELEM, 0, COLOR_THEME_PRIMARY1); - disable_telem = new CheckBox(line, rect_t{}, GET_SET_DEFAULT(md->multi.disableTelemetry)); + disable_telem = new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(md->multi.disableTelemetry)); #endif cm_line = new MPMChannelMap(this, &grid, moduleIdx); diff --git a/radio/src/gui/colorlcd/mpm_settings.h b/radio/src/gui/colorlcd/mpm_settings.h index ac73360a64f..15692e1f8da 100644 --- a/radio/src/gui/colorlcd/mpm_settings.h +++ b/radio/src/gui/colorlcd/mpm_settings.h @@ -22,9 +22,10 @@ #pragma once #include "form.h" -#include "checkbox.h" #include "module_setup.h" +class ToggleSwitch; + struct ModuleData; struct MPMProtoOption; struct MPMSubtype; @@ -32,7 +33,7 @@ struct MPMServoRate; struct MPMAutobind; struct MPMChannelMap; -class MultimoduleSettings : public FormGroup, public ModuleOptions +class MultimoduleSettings : public FormWindow, public ModuleOptions { ModuleData* md; uint8_t moduleIdx; @@ -41,9 +42,9 @@ class MultimoduleSettings : public FormGroup, public ModuleOptions MPMProtoOption* opt_line; MPMServoRate* sr_line; MPMAutobind* ab_line; - CheckBox* lp_mode; + ToggleSwitch* lp_mode; #if defined(MANUFACTURER_FRSKY) - CheckBox* disable_telem; + ToggleSwitch* disable_telem; #endif MPMChannelMap* cm_line; diff --git a/radio/src/gui/colorlcd/multi_rfprotos.cpp b/radio/src/gui/colorlcd/multi_rfprotos.cpp index 1f5abdaf1fe..1ea47c020c6 100644 --- a/radio/src/gui/colorlcd/multi_rfprotos.cpp +++ b/radio/src/gui/colorlcd/multi_rfprotos.cpp @@ -23,8 +23,6 @@ #include "multi_rfprotos.h" #include "strhelpers.h" -#include "progress.h" - // TODO: format for LCD_WIDTH > LCD_HEIGHT // TODO: translation @@ -32,37 +30,20 @@ const char* RFSCAN_TITLE = "MPM: Scanning protocols..."; RfScanDialog::RfScanDialog(Window* parent, MultiRfProtocols* protos, std::function onClose) : - Dialog(parent, RFSCAN_TITLE, rect_t{}), - protos(protos), - progress(new Progress(&content->form, rect_t{})), - onClose(std::move(onClose)) + ProgressDialog(parent, RFSCAN_TITLE, onClose), + protos(protos) { - 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); - // setFocus(); } void RfScanDialog::showProgress() { - progress->setValue((int)(protos->getProgress() * 100.0)); + updateProgress((int)(protos->getProgress() * 100.0)); } - - // disable keys -void RfScanDialog::onEvent(event_t) { return; } void RfScanDialog::checkEvents() { if (!protos->isScanning()) { - deleteLater(); - onClose(); + closeDialog(); } else if (RTOS_GET_MS() - lastUpdate >= 200) { showProgress(); lastUpdate = RTOS_GET_MS(); diff --git a/radio/src/gui/colorlcd/multi_rfprotos.h b/radio/src/gui/colorlcd/multi_rfprotos.h index 1397ce34e1f..7a08192e1a1 100644 --- a/radio/src/gui/colorlcd/multi_rfprotos.h +++ b/radio/src/gui/colorlcd/multi_rfprotos.h @@ -24,23 +24,17 @@ class MultiRfProtocols; -class RfScanDialog : public Dialog +class RfScanDialog : public ProgressDialog { MultiRfProtocols* protos; uint32_t lastUpdate = 0; - Progress* progress; - std::function onClose; - public: RfScanDialog(Window* parent, MultiRfProtocols* protos, std::function onClose); void showProgress(); - // disable keys - void onEvent(event_t) override; - void checkEvents() override; }; diff --git a/radio/src/gui/colorlcd/output_edit.cpp b/radio/src/gui/colorlcd/output_edit.cpp index 66d040a7a11..041e7eec1fa 100644 --- a/radio/src/gui/colorlcd/output_edit.cpp +++ b/radio/src/gui/colorlcd/output_edit.cpp @@ -182,7 +182,7 @@ void OutputEditWindow::buildBody(FormWindow* form) // Direction line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_INVERTED, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_DEFAULT(output->revert), + new ToggleSwitch(line, rect_t{}, GET_DEFAULT(output->revert), [output, this](uint8_t newValue) { output->revert = newValue; SET_DIRTY(); diff --git a/radio/src/gui/colorlcd/page.cpp b/radio/src/gui/colorlcd/page.cpp index 724ad2e63db..a75966db427 100644 --- a/radio/src/gui/colorlcd/page.cpp +++ b/radio/src/gui/colorlcd/page.cpp @@ -25,7 +25,7 @@ #include "opentx.h" PageHeader::PageHeader(Page * parent, uint8_t icon): - FormGroup(parent, { 0, 0, LCD_W, MENU_HEADER_HEIGHT }, OPAQUE), + FormWindow(parent, { 0, 0, LCD_W, MENU_HEADER_HEIGHT }, OPAQUE), icon(icon) { #if defined(HARDWARE_TOUCH) @@ -33,7 +33,7 @@ PageHeader::PageHeader(Page * parent, uint8_t icon): [=]() -> uint8_t { parent->onCancel(); return 0; - }, NO_FOCUS | FORM_NO_BORDER); + }, NO_FOCUS); #endif title = new StaticText(this, {PAGE_TITLE_LEFT, PAGE_TITLE_TOP, @@ -55,7 +55,7 @@ StaticText* PageHeader::setTitle2(std::string txt) void PageHeader::paint(BitmapBuffer * dc) { - OpenTxTheme::instance()->drawPageHeaderBackground(dc, getIcon(), ""); + EdgeTxTheme::instance()->drawPageHeaderBackground(dc, getIcon(), nullptr); dc->drawSolidFilledRect(MENU_HEADER_HEIGHT, 0, LCD_W - MENU_HEADER_HEIGHT, MENU_HEADER_HEIGHT, COLOR_THEME_SECONDARY1); } @@ -68,11 +68,14 @@ static constexpr rect_t _get_body_rect() Page::Page(unsigned icon): Window(Layer::back(), {0, 0, LCD_W, LCD_H}, OPAQUE), header(this, icon), - body(this, _get_body_rect(), FORM_FORWARD_FOCUS) + body(this, _get_body_rect()) { Layer::push(this); lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY3), 0); + + body.padAll(0); + lv_obj_set_scrollbar_mode(body.getLvObj(), LV_SCROLLBAR_MODE_AUTO); } void Page::deleteLater(bool detach, bool trash) diff --git a/radio/src/gui/colorlcd/page.h b/radio/src/gui/colorlcd/page.h index 6ff2bb88fd3..4185297b1b5 100644 --- a/radio/src/gui/colorlcd/page.h +++ b/radio/src/gui/colorlcd/page.h @@ -28,7 +28,7 @@ class Page; -class PageHeader : public FormGroup +class PageHeader : public FormWindow { public: PageHeader(Page* parent, uint8_t icon); diff --git a/radio/src/gui/colorlcd/ppm_settings.cpp b/radio/src/gui/colorlcd/ppm_settings.cpp index 4e5c23936cb..0233c142b72 100644 --- a/radio/src/gui/colorlcd/ppm_settings.cpp +++ b/radio/src/gui/colorlcd/ppm_settings.cpp @@ -26,7 +26,7 @@ template PpmFrameSettings::PpmFrameSettings(Window* parent, T* ppm) : - FormGroup(parent, rect_t{}) + FormWindow(parent, rect_t{}) { setFlexLayout(LV_FLEX_FLOW_ROW); diff --git a/radio/src/gui/colorlcd/ppm_settings.h b/radio/src/gui/colorlcd/ppm_settings.h index af9a23ea53c..4d55cdfe763 100644 --- a/radio/src/gui/colorlcd/ppm_settings.h +++ b/radio/src/gui/colorlcd/ppm_settings.h @@ -25,7 +25,7 @@ #include "numberedit.h" template -struct PpmFrameSettings : public FormGroup { +struct PpmFrameSettings : public FormWindow { private: NumberEdit* ppmFrameLenEditObject = nullptr; diff --git a/radio/src/gui/colorlcd/preflight_checks.cpp b/radio/src/gui/colorlcd/preflight_checks.cpp index d605a1c190f..781067687bc 100644 --- a/radio/src/gui/colorlcd/preflight_checks.cpp +++ b/radio/src/gui/colorlcd/preflight_checks.cpp @@ -46,7 +46,7 @@ static void cb_changed(lv_event_t* e) } } -static void make_conditional(Window* w, CheckBox* cb) +static void make_conditional(Window* w, ToggleSwitch* cb) { lv_obj_t* w_obj = w->getLvObj(); if (!cb->getValue()) { lv_obj_add_flag(w_obj, LV_OBJ_FLAG_HIDDEN); } @@ -81,7 +81,7 @@ struct SwitchWarnMatrix : public ButtonMatrix { SwitchWarnMatrix(Window* parent, const rect_t& rect); void onPress(uint8_t btn_id); bool isActive(uint8_t btn_id); - void setTextWithColor(uint8_t btn_id); + void setTextAndState(uint8_t btn_id); private: uint8_t sw_idx[MAX_SWITCHES]; }; @@ -90,7 +90,7 @@ struct PotWarnMatrix : public ButtonMatrix { PotWarnMatrix(Window* parent, const rect_t& rect); void onPress(uint8_t btn_id); bool isActive(uint8_t btn_id); - void setTextWithColor(uint8_t btn_id); + void setTextAndState(uint8_t btn_id); private: uint8_t pot_idx[MAX_POTS]; }; @@ -99,7 +99,7 @@ struct CenterBeepsMatrix : public ButtonMatrix { CenterBeepsMatrix(Window* parent, const rect_t& rect); void onPress(uint8_t btn_id); bool isActive(uint8_t btn_id); - void setTextWithColor(uint8_t btn_id); + void setTextAndState(uint8_t btn_id); private: uint8_t max_analogs; uint8_t ana_idx[MAX_ANALOG_INPUTS]; @@ -110,33 +110,31 @@ PreflightChecks::PreflightChecks() : Page(ICON_MODEL_SETUP) header.setTitle(STR_MENU_MODEL_SETUP); header.setTitle2(STR_PREFLIGHT); - body.padAll(8); - auto form = new FormWindow(&body, rect_t{}); form->setFlexLayout(); - form->padAll(4); + form->padAll(8); FlexGridLayout grid(line_col_dsc, line_row_dsc, 2); // Display checklist auto line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_CHECKLIST, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_model.displayChecklist)); + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(g_model.displayChecklist)); // Throttle warning line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_THROTTLE_WARNING, 0, COLOR_THEME_PRIMARY1); - auto tw = new CheckBox(line, rect_t{}, GET_SET_INVERTED(g_model.disableThrottleWarning)); + auto tw = new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_model.disableThrottleWarning)); // Custom Throttle warning (conditional on previous field) line = form->newLine(&grid); make_conditional(line, tw); new StaticText(line, rect_t{}, STR_CUSTOM_THROTTLE_WARNING, 0, COLOR_THEME_PRIMARY1); - auto box = new FormGroup::Line(line, window_create(line->getLvObj())); + auto box = new FormWindow::Line(line, window_create(line->getLvObj())); lv_obj_set_layout(box->getLvObj(), LV_LAYOUT_FLEX); box->setWidth(LCD_W /2 - 15); - auto cst_tw = new CheckBox( + auto cst_tw = new ToggleSwitch( box, rect_t{}, GET_SET_DEFAULT(g_model.enableCustomThrottleWarning)); // Custom Throttle warning value @@ -147,7 +145,10 @@ PreflightChecks::PreflightChecks() : Page(ICON_MODEL_SETUP) // Switch warnings (TODO: add display switch?) line = form->newLine(&grid); + new StaticText(line, rect_t{}, STR_SWITCHES, 0, COLOR_THEME_PRIMARY1); + line = form->newLine(&grid); line->padTop(0); + line->padLeft(4); new SwitchWarnMatrix(line, rect_t{}); // Pots and sliders warning @@ -160,6 +161,7 @@ PreflightChecks::PreflightChecks() : Page(ICON_MODEL_SETUP) // Pot warnings line = form->newLine(&grid); line->padTop(0); + line->padLeft(4); auto pwm = new PotWarnMatrix(line, rect_t{}); make_conditional(pwm, pots_wm); } @@ -169,6 +171,7 @@ PreflightChecks::PreflightChecks() : Page(ICON_MODEL_SETUP) line->padTop(0); new StaticText(line, rect_t{}, STR_BEEPCTR, 0, COLOR_THEME_PRIMARY1); line = form->newLine(&grid); + line->padLeft(4); new CenterBeepsMatrix(line, rect_t{}); } @@ -204,8 +207,7 @@ SwitchWarnMatrix::SwitchWarnMatrix(Window* parent, const rect_t& r) : uint8_t btn_id = 0; for (uint8_t i = 0; i < MAX_SWITCHES; i++) { if (SWITCH_EXISTS(i)) { - lv_btnmatrix_set_btn_ctrl(lvobj, btn_id, LV_BTNMATRIX_CTRL_RECOLOR); - setTextWithColor(i); + setTextAndState(i); btn_id++; } } @@ -214,23 +216,17 @@ SwitchWarnMatrix::SwitchWarnMatrix(Window* parent, const rect_t& r) : uint8_t rows = ((btn_cnt - 1) / SW_BTNS) + 1; lv_obj_set_height(lvobj, (rows * LV_DPI_DEF) / 3); - - lv_obj_set_style_bg_opa(lvobj, LV_OPA_0, LV_PART_MAIN); lv_obj_set_style_pad_all(lvobj, 4, LV_PART_MAIN); - lv_obj_set_style_pad_left(lvobj, LV_DPI_DEF / 10, LV_PART_MAIN); lv_obj_set_style_pad_row(lvobj, 4, LV_PART_MAIN); lv_obj_set_style_pad_column(lvobj, 4, LV_PART_MAIN); - - lv_obj_remove_style(lvobj, nullptr, LV_PART_MAIN | LV_STATE_FOCUSED); - lv_obj_remove_style(lvobj, nullptr, LV_PART_MAIN | LV_STATE_EDITED); } -void SwitchWarnMatrix::setTextWithColor(uint8_t btn_id) +void SwitchWarnMatrix::setTextAndState(uint8_t btn_id) { - auto color = isActive(btn_id) ? COLOR_THEME_PRIMARY1 : COLOR_THEME_SECONDARY1; - setText(btn_id, makeRecolor(switchWarninglabel(sw_idx[btn_id]), color).c_str()); + setText(btn_id, switchWarninglabel(sw_idx[btn_id]).c_str()); + setChecked(btn_id); } void SwitchWarnMatrix::onPress(uint8_t btn_id) @@ -249,7 +245,7 @@ void SwitchWarnMatrix::onPress(uint8_t btn_id) SET_DIRTY(); // TODO: save state in object - setTextWithColor(sw); + setTextAndState(sw); } bool SwitchWarnMatrix::isActive(uint8_t btn_id) @@ -276,8 +272,7 @@ PotWarnMatrix::PotWarnMatrix(Window* parent, const rect_t& r) : uint8_t btn_id = 0; for (uint16_t i = 0; i < MAX_POTS; i++) { if (IS_POT_AVAILABLE(i)) { - lv_btnmatrix_set_btn_ctrl(lvobj, btn_id, LV_BTNMATRIX_CTRL_RECOLOR); - setTextWithColor(btn_id); + setTextAndState(btn_id); btn_id++; } } @@ -287,23 +282,16 @@ PotWarnMatrix::PotWarnMatrix(Window* parent, const rect_t& r) : uint8_t rows = ((btn_cnt - 1) / SW_BTNS) + 1; lv_obj_set_height(lvobj, (rows * LV_DPI_DEF) / 3); - lv_obj_set_style_bg_opa(lvobj, LV_OPA_0, LV_PART_MAIN); - lv_obj_set_style_pad_all(lvobj, 4, LV_PART_MAIN); - lv_obj_set_style_pad_left(lvobj, LV_DPI_DEF / 10, LV_PART_MAIN); lv_obj_set_style_pad_row(lvobj, 4, LV_PART_MAIN); lv_obj_set_style_pad_column(lvobj, 4, LV_PART_MAIN); - - lv_obj_remove_style(lvobj, nullptr, LV_PART_MAIN | LV_STATE_FOCUSED); - lv_obj_remove_style(lvobj, nullptr, LV_PART_MAIN | LV_STATE_EDITED); } -void PotWarnMatrix::setTextWithColor(uint8_t btn_id) +void PotWarnMatrix::setTextAndState(uint8_t btn_id) { - auto idx = pot_idx[btn_id]; - auto color = isActive(btn_id) ? COLOR_THEME_PRIMARY1 : COLOR_THEME_SECONDARY1; - setText(btn_id, makeRecolor(getPotLabel(idx), color).c_str()); + setText(btn_id, getPotLabel(pot_idx[btn_id])); + setChecked(btn_id); } void PotWarnMatrix::onPress(uint8_t btn_id) @@ -316,7 +304,7 @@ void PotWarnMatrix::onPress(uint8_t btn_id) (g_model.potsWarnEnabled & (1 << pot))) { SAVE_POT_POSITION(pot); } - setTextWithColor(btn_id); + setTextAndState(btn_id); SET_DIRTY(); } @@ -352,8 +340,7 @@ CenterBeepsMatrix::CenterBeepsMatrix(Window* parent, const rect_t& r) : for (uint8_t i = 0; i < max_analogs; i++) { if (i < max_sticks || (IS_POT_SLIDER_AVAILABLE(i - max_sticks) && !IS_POT_MULTIPOS(i - max_sticks))) { - lv_btnmatrix_set_btn_ctrl(lvobj, btn_id, LV_BTNMATRIX_CTRL_RECOLOR); - setTextWithColor(btn_id); + setTextAndState(btn_id); btn_id++; } } @@ -363,31 +350,20 @@ CenterBeepsMatrix::CenterBeepsMatrix(Window* parent, const rect_t& r) : uint8_t rows = ((btn_cnt - 1) / SW_BTNS) + 1; lv_obj_set_height(lvobj, (rows * LV_DPI_DEF) / 3); - lv_obj_set_style_bg_opa(lvobj, LV_OPA_0, LV_PART_MAIN); - lv_obj_set_style_pad_all(lvobj, 4, LV_PART_MAIN); - lv_obj_set_style_pad_left(lvobj, LV_DPI_DEF / 10, LV_PART_MAIN); lv_obj_set_style_pad_row(lvobj, 4, LV_PART_MAIN); lv_obj_set_style_pad_column(lvobj, 4, LV_PART_MAIN); - - lv_obj_remove_style(lvobj, nullptr, LV_PART_MAIN | LV_STATE_FOCUSED); - lv_obj_remove_style(lvobj, nullptr, LV_PART_MAIN | LV_STATE_EDITED); } -void CenterBeepsMatrix::setTextWithColor(uint8_t btn_id) +void CenterBeepsMatrix::setTextAndState(uint8_t btn_id) { auto max_sticks = adcGetMaxInputs(ADC_INPUT_MAIN); if (ana_idx[btn_id] < max_sticks) - setText(btn_id, makeRecolor(getAnalogShortLabel(ana_idx[btn_id]), - isActive(btn_id) ? COLOR_THEME_PRIMARY1 - : COLOR_THEME_SECONDARY1) - .c_str()); + setText(btn_id, getAnalogShortLabel(ana_idx[btn_id])); else - setText(btn_id, makeRecolor(getAnalogLabel(ADC_INPUT_POT, ana_idx[btn_id] - max_sticks), - isActive(btn_id) ? COLOR_THEME_PRIMARY1 - : COLOR_THEME_SECONDARY1) - .c_str()); + setText(btn_id, getAnalogLabel(ADC_INPUT_POT, ana_idx[btn_id] - max_sticks)); + setChecked(btn_id); } void CenterBeepsMatrix::onPress(uint8_t btn_id) @@ -395,7 +371,7 @@ void CenterBeepsMatrix::onPress(uint8_t btn_id) if (btn_id >= max_analogs) return; uint8_t i = ana_idx[btn_id]; BFBIT_FLIP(g_model.beepANACenter, bfBit(i)); - setTextWithColor(btn_id); + setTextAndState(btn_id); SET_DIRTY(); } diff --git a/radio/src/gui/colorlcd/preview_window.h b/radio/src/gui/colorlcd/preview_window.h index 4c22e3286f8..abd1f03a43d 100644 --- a/radio/src/gui/colorlcd/preview_window.h +++ b/radio/src/gui/colorlcd/preview_window.h @@ -72,7 +72,7 @@ extern ColorMaintainer colorMaintainer; class ThemedStaticText : public StaticText { public: - ThemedStaticText(FormGroup *window, const rect_t &rect, std::string text, LcdColorIndex colorIndex) : + ThemedStaticText(FormWindow *window, const rect_t &rect, std::string text, LcdColorIndex colorIndex) : StaticText(window, rect, text, 0, COLOR(colorIndex)), _colorIndex(colorIndex) { @@ -90,11 +90,11 @@ class ThemedStaticText : public StaticText LcdColorIndex _colorIndex; }; -class ThemedCheckBox : public CheckBox +class ThemedCheckBox : public ToggleSwitch { public: ThemedCheckBox(Window *parent, rect_t rect, bool checked) : - CheckBox(parent, rect, [=]() { return checked; }, [](uint8_t value) {}, NO_FOCUS), + ToggleSwitch(parent, rect, [=]() { return checked; }, [](uint8_t value) {}, NO_FOCUS), checked(checked) { enable(false); @@ -112,7 +112,7 @@ class ThemedCheckBox : public CheckBox void paint(BitmapBuffer *dc) override { colorMaintainer.applyColorValues(); - CheckBox::paint(dc); + ToggleSwitch::paint(dc); colorMaintainer.restoreColorValues(); } @@ -147,7 +147,7 @@ class ThemedMainViewHorizontalSlider : public MainViewHorizontalSlider class ThemedButton : public TextButton { public: - ThemedButton(FormGroup *window, const rect_t &rect, std::string text, bool isChecked, WindowFlags windowFlags, + ThemedButton(FormWindow *window, const rect_t &rect, std::string text, bool isChecked, WindowFlags windowFlags, LcdColorIndex colorIndex) : TextButton(window, rect, text, nullptr, windowFlags | NO_FOCUS), _colorIndex(colorIndex), @@ -219,31 +219,31 @@ class ThemedTextEdit : public TextEdit }; // display controls using the appropriate theme. -class PreviewWindow : public FormGroup +class PreviewWindow : public FormWindow { public: PreviewWindow(Window *window, rect_t rect, std::vector colorList) : - FormGroup(window, rect, NO_FOCUS), _colorList(colorList) + FormWindow(window, rect, NO_FOCUS), _colorList(colorList) { // reset default group to avoid focus lv_group_t* def_group = lv_group_get_default(); lv_group_set_default(nullptr); - new ThemedStaticText(this, {5, 40, 100, LINE_HEIGHT}, STR_THEME_CHECKBOX, COLOR_THEME_PRIMARY1_INDEX); - new ThemedCheckBox(this, {100 + 15, 40, 20, LINE_HEIGHT}, true); - new ThemedCheckBox(this, {140 + 15, 40, 20, LINE_HEIGHT}, false); - new ThemedButton(this, {190, 40, 100, LINE_HEIGHT + 10}, STR_THEME_ACTIVE, true, BUTTON_CHECKED, COLOR_THEME_PRIMARY1_INDEX); - new ThemedButton(this, {190, 75, 100, LINE_HEIGHT + 10}, STR_THEME_REGULAR, false, 0, COLOR_THEME_PRIMARY1_INDEX); - new ThemedMainViewHorizontalTrim(this, {5, 65, HORIZONTAL_SLIDERS_WIDTH, 20}, 0); - new ThemedMainViewHorizontalSlider(this, {5, 87, HORIZONTAL_SLIDERS_WIDTH, 20}, 0); - new ThemedStaticText(this, {5, 115, 100, LINE_HEIGHT}, STR_THEME_WARNING, COLOR_THEME_WARNING_INDEX); - new ThemedStaticText(this, {5, 140, 100, LINE_HEIGHT}, STR_THEME_DISABLED, COLOR_THEME_DISABLED_INDEX); - - new ThemedTextEdit(this, {5, 160, 100, LINE_HEIGHT + 1}, STR_THEME_EDIT, + new ThemedStaticText(this, {5, 44, 100, PAGE_LINE_HEIGHT}, STR_THEME_CHECKBOX, COLOR_THEME_PRIMARY1_INDEX); + new ThemedCheckBox(this, {100, 40, 40, 28}, true); + new ThemedCheckBox(this, {150, 40, 40, 28}, false); + new ThemedButton(this, {210, 40, 100, PAGE_LINE_HEIGHT + 10}, STR_THEME_ACTIVE, true, BUTTON_CHECKED, COLOR_THEME_PRIMARY1_INDEX); + new ThemedButton(this, {210, 75, 100, PAGE_LINE_HEIGHT + 10}, STR_THEME_REGULAR, false, 0, COLOR_THEME_PRIMARY1_INDEX); + new ThemedMainViewHorizontalTrim(this, {5, 75, HORIZONTAL_SLIDERS_WIDTH, 20}, 0); + new ThemedMainViewHorizontalSlider(this, {5, 97, HORIZONTAL_SLIDERS_WIDTH, 20}, 0); + new ThemedStaticText(this, {5, 122, 100, PAGE_LINE_HEIGHT}, STR_THEME_WARNING, COLOR_THEME_WARNING_INDEX); + new ThemedStaticText(this, {5, 144, 100, PAGE_LINE_HEIGHT}, STR_THEME_DISABLED, COLOR_THEME_DISABLED_INDEX); + + new ThemedTextEdit(this, {5, 170, 100, 32}, STR_THEME_EDIT, COLOR_THEME_EDIT_INDEX, COLOR_THEME_PRIMARY2_INDEX); - new ThemedTextEdit(this, {110, 160, 100, LINE_HEIGHT + 1}, STR_THEME_FOCUS, + new ThemedTextEdit(this, {110, 170, 100, 32}, STR_THEME_FOCUS, COLOR_THEME_FOCUS_INDEX, COLOR_THEME_PRIMARY2_INDEX); ticks = 0; @@ -336,7 +336,7 @@ class PreviewWindow : public FormGroup protected: std::vector _colorList; - CheckBox *checkBox; + ToggleSwitch *checkBox; tmr10ms_t ticks; }; diff --git a/radio/src/gui/colorlcd/pxx1_settings.cpp b/radio/src/gui/colorlcd/pxx1_settings.cpp index f69bb32d8d5..ce17c4ef39f 100644 --- a/radio/src/gui/colorlcd/pxx1_settings.cpp +++ b/radio/src/gui/colorlcd/pxx1_settings.cpp @@ -29,7 +29,7 @@ PXX1AntennaSettings::PXX1AntennaSettings(Window* parent, const FlexGridLayout& g, uint8_t moduleIdx) : - FormGroup(parent, rect_t{}), md(&g_model.moduleData[moduleIdx]) + FormWindow(parent, rect_t{}), md(&g_model.moduleData[moduleIdx]) { FlexGridLayout grid(g); setFlexLayout(); diff --git a/radio/src/gui/colorlcd/pxx1_settings.h b/radio/src/gui/colorlcd/pxx1_settings.h index 3709b5d51b8..936c1df14b9 100644 --- a/radio/src/gui/colorlcd/pxx1_settings.h +++ b/radio/src/gui/colorlcd/pxx1_settings.h @@ -26,7 +26,7 @@ struct ModuleData; -class PXX1AntennaSettings : public FormGroup, public ModuleOptions +class PXX1AntennaSettings : public FormWindow, public ModuleOptions { ModuleData* md; diff --git a/radio/src/gui/colorlcd/radio_calibration.cpp b/radio/src/gui/colorlcd/radio_calibration.cpp index ac8da07f65f..9c54cbea837 100644 --- a/radio/src/gui/colorlcd/radio_calibration.cpp +++ b/radio/src/gui/colorlcd/radio_calibration.cpp @@ -98,7 +98,7 @@ void RadioCalibrationPage::buildBody(FormWindow * window) [=]() -> uint8_t { nextStep(); return 0; - }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS); + }, OPAQUE | NO_FOCUS); #endif } diff --git a/radio/src/gui/colorlcd/radio_ghost_module_config.cpp b/radio/src/gui/colorlcd/radio_ghost_module_config.cpp index 61e80f973f0..a328687ef3a 100644 --- a/radio/src/gui/colorlcd/radio_ghost_module_config.cpp +++ b/radio/src/gui/colorlcd/radio_ghost_module_config.cpp @@ -29,8 +29,7 @@ class GhostModuleConfigWindow: public Window { public: GhostModuleConfigWindow(Window * parent, const rect_t & rect) : - Window(parent, rect, FORWARD_SCROLL // | FORM_FORWARD_FOCUS - | REFRESH_ALWAYS) + Window(parent, rect, REFRESH_ALWAYS) { // setFocus(SET_FOCUS_DEFAULT); } diff --git a/radio/src/gui/colorlcd/radio_hardware.cpp b/radio/src/gui/colorlcd/radio_hardware.cpp index 5901daf241c..f7f24c61b15 100644 --- a/radio/src/gui/colorlcd/radio_hardware.cpp +++ b/radio/src/gui/colorlcd/radio_hardware.cpp @@ -65,18 +65,18 @@ void RadioHardwarePage::build(FormWindow * window) auto line = window->newLine(&grid); new StaticText(line, rect_t{}, STR_BATTERY_RANGE, 0, COLOR_THEME_PRIMARY1); - auto box = new FormGroup(line, rect_t{}); + auto box = new FormWindow(line, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(4)); lv_obj_set_style_grid_cell_x_align(box->getLvObj(), LV_GRID_ALIGN_STRETCH, 0); lv_obj_set_flex_align(box->getLvObj(), LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_AROUND); auto batMin = - new NumberEdit(box, rect_t{}, -60 + 90, g_eeGeneral.vBatMax + 29 + 90, + new NumberEdit(box, rect_t{0, 0, 80, 0}, -60 + 90, g_eeGeneral.vBatMax + 29 + 90, GET_SET_WITH_OFFSET(g_eeGeneral.vBatMin, 90), 0, PREC1); batMin->setSuffix("V"); new StaticText(box, rect_t{}, "-"); auto batMax = - new NumberEdit(box, rect_t{}, g_eeGeneral.vBatMin - 29 + 120, 40 + 120, + new NumberEdit(box, rect_t{0, 0, 80, 0}, g_eeGeneral.vBatMin - 29 + 120, 40 + 120, GET_SET_WITH_OFFSET(g_eeGeneral.vBatMax, 120), 0, PREC1); batMax->setSuffix("V"); @@ -98,7 +98,7 @@ void RadioHardwarePage::build(FormWindow * window) line = window->newLine(&grid); new StaticText(line, rect_t{}, STR_BATT_CALIB, 0, COLOR_THEME_PRIMARY1); auto batCal = - new NumberEdit(line, rect_t{}, -127, 127, + new NumberEdit(line, rect_t{0, 0, 80, 0}, -127, 127, GET_SET_DEFAULT(g_eeGeneral.txVoltageCalibration)); batCal->setDisplayHandler([](int32_t value) { return formatNumberAsString(getBatteryVoltage(), PREC2, 0, nullptr, "V"); @@ -109,11 +109,11 @@ void RadioHardwarePage::build(FormWindow * window) line = window->newLine(&grid); new StaticText(line, rect_t{}, STR_RTC_CHECK, 0, COLOR_THEME_PRIMARY1); - box = new FormGroup(line, rect_t{}); + box = new FormWindow(line, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8)); lv_obj_set_style_grid_cell_x_align(box->getLvObj(), LV_GRID_ALIGN_STRETCH, 0); lv_obj_set_style_flex_cross_place(box->getLvObj(), LV_FLEX_ALIGN_CENTER, 0); - new CheckBox(box, rect_t{}, GET_SET_INVERTED(g_eeGeneral.disableRtcWarning )); + new ToggleSwitch(box, rect_t{}, GET_SET_INVERTED(g_eeGeneral.disableRtcWarning )); // RTC Batt display new StaticText(box, rect_t{}, STR_VALUE, 0, COLOR_THEME_PRIMARY1); @@ -124,41 +124,41 @@ void RadioHardwarePage::build(FormWindow * window) // ADC filter line = window->newLine(&grid); new StaticText(line, rect_t{}, STR_JITTER_FILTER, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.noJitterFilter)); + new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.noJitterFilter)); #if defined(AUDIO_MUTE_GPIO) // Mute audio line = window->newLine(&grid); new StaticText(line, rect_t{}, STR_AUDIO_MUTE, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_eeGeneral.audioMuteEnable)); + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(g_eeGeneral.audioMuteEnable)); #endif #if defined(HARDWARE_INTERNAL_MODULE) - new Subtitle(window, rect_t{}, STR_INTERNALRF, 0, COLOR_THEME_PRIMARY1); + new Subtitle(window, STR_INTERNALRF); auto intMod = new InternalModuleWindow(window); intMod->padLeft(lv_dpx(8)); #endif #if defined(HARDWARE_EXTERNAL_MODULE) - new Subtitle(window, rect_t{}, STR_EXTERNALRF, 0, COLOR_THEME_PRIMARY1); + new Subtitle(window, STR_EXTERNALRF); auto extMod = new ExternalModuleWindow(window); extMod->padLeft(lv_dpx(8)); #endif #if defined(BLUETOOTH) - new Subtitle(window, rect_t{}, STR_BLUETOOTH, 0, COLOR_THEME_PRIMARY1); + new Subtitle(window, STR_BLUETOOTH); auto bt = new BluetoothConfigWindow(window); bt->padLeft(lv_dpx(8)); #endif - new Subtitle(window, rect_t{}, STR_AUX_SERIAL_MODE, 0, COLOR_THEME_PRIMARY1); + new Subtitle(window, STR_AUX_SERIAL_MODE); auto serial = new SerialConfigWindow(window, rect_t{}); serial->padLeft(lv_dpx(8)); // Calibration - new Subtitle(window, rect_t{}, STR_INPUTS, 0, COLOR_THEME_PRIMARY1); + new Subtitle(window, STR_INPUTS); - box = new FormGroup(window, rect_t{}); + box = new FormWindow(window, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW_WRAP, lv_dpx(8)); lv_obj_set_style_flex_main_place(box->getLvObj(), LV_FLEX_ALIGN_SPACE_EVENLY, 0); box->padRow(lv_dpx(8)); @@ -184,9 +184,9 @@ void RadioHardwarePage::build(FormWindow * window) lv_obj_set_style_min_width(btn->getLvObj(), LV_DPI_DEF, 0); // Debugs - new Subtitle(window, rect_t{}, STR_DEBUG, 0, COLOR_THEME_PRIMARY1); + new Subtitle(window, STR_DEBUG); - box = new FormGroup(window, rect_t{}); + box = new FormWindow(window, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW_WRAP, lv_dpx(8)); lv_obj_set_style_flex_main_place(box->getLvObj(), LV_FLEX_ALIGN_SPACE_EVENLY, 0); box->padRow(lv_dpx(8)); diff --git a/radio/src/gui/colorlcd/radio_sdmanager.cpp b/radio/src/gui/colorlcd/radio_sdmanager.cpp index 42efff17416..6ff1de9f3bf 100644 --- a/radio/src/gui/colorlcd/radio_sdmanager.cpp +++ b/radio/src/gui/colorlcd/radio_sdmanager.cpp @@ -31,6 +31,7 @@ #include "view_text.h" #include "file_preview.h" #include "file_browser.h" +#include "progress.h" constexpr int WARN_FILE_LENGTH = 40 * 1024; @@ -60,8 +61,13 @@ class FileNameEditWindow : public Page void buildBody(Window *window) { - GridLayout grid(window); - grid.spacer(8); + window->padAll(0); + + auto form = new FormWindow(window, rect_t()); + form->setFlexLayout(LV_FLEX_FLOW_COLUMN, 4); + form->padAll(4); + form->padTop(12); + uint8_t nameLength; uint8_t extLength; char extension[LEN_FILE_EXTENSION_MAX + 1]; @@ -81,7 +87,7 @@ class FileNameEditWindow : public Page reusableBuffer.sdManager.originalName[nameLength] = '\0'; auto newFileName = new TextEdit( - window, grid.getSlot(), reusableBuffer.sdManager.originalName, + form, rect_t{0, 0, LCD_W-8, 0}, reusableBuffer.sdManager.originalName, SD_SCREEN_FILE_LENGTH - extLength, LcdFlags(0)); newFileName->setChangeHandler([=]() { char *newValue = reusableBuffer.sdManager.originalName; @@ -287,7 +293,7 @@ void RadioSdManagerPage::build(FormWindow * window) FlexGridLayout grid(col_dsc, row_dsc, 0); window->padAll(0); - FormGroup* form = new FormGroup(window, rect_t{}); + FormWindow* form = new FormWindow(window, rect_t{}); form->setWidth(window->width()); form->setHeight(window->height()); grid.apply(form); diff --git a/radio/src/gui/colorlcd/radio_setup.cpp b/radio/src/gui/colorlcd/radio_setup.cpp index c067b3f3e47..e81e7823bcb 100644 --- a/radio/src/gui/colorlcd/radio_setup.cpp +++ b/radio/src/gui/colorlcd/radio_setup.cpp @@ -38,17 +38,17 @@ static const lv_coord_t col_four_dsc[] = {LV_GRID_FR(19), LV_GRID_FR(7), LV_GRID static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; -class DateTimeWindow : public FormGroup { +class DateTimeWindow : public FormWindow { public: DateTimeWindow(Window* parent, const rect_t & rect) : - FormGroup(parent, rect) + FormWindow(parent, rect) { build(); } void checkEvents() override { - FormGroup::checkEvents(); + FormWindow::checkEvents(); if (seconds && (get_tmr10ms() - lastRefresh >= 10)) { lastRefresh = get_tmr10ms(); @@ -211,7 +211,7 @@ class DateTimeWindow : public FormGroup { } }; -class WindowButtonGroup : public FormGroup +class WindowButtonGroup : public FormWindow { public: typedef std::function PageFct; @@ -220,9 +220,10 @@ class WindowButtonGroup : public FormGroup WindowButtonGroup( Window* parent, const rect_t& rect, PageDefs pages) : - FormGroup(parent, rect), + FormWindow(parent, rect), pages(pages) { + padBottom(4); setFlexLayout(LV_FLEX_FLOW_ROW_WRAP, lv_dpx(8)); lv_obj_set_style_flex_main_place(lvobj, LV_FLEX_ALIGN_SPACE_EVENLY, 0); padRow(lv_dpx(8)); @@ -244,43 +245,49 @@ class WindowButtonGroup : public FormGroup class SubPage : public Page { public: - SubPage(MenuIcons icon, const char* title) : Page(icon) + SubPage(MenuIcons icon, const char* title, bool isFlex = true) : Page(icon) { header.setTitle(STR_RADIO_SETUP); header.setTitle2(title); - body.setFlexLayout(); + if (isFlex) + body.setFlexLayout(); + body.padAll(8); } }; class SoundPage : public SubPage { public: - SoundPage() : SubPage(ICON_RADIO_SETUP, STR_SOUND_LABEL) + SoundPage() : SubPage(ICON_RADIO_SETUP, STR_SOUND_LABEL, false) { FlexGridLayout grid(col_two_dsc, row_dsc, 2); - auto line = body.newLine(&grid); + auto form = new FormWindow(&body, rect_t{}); + form->setFlexLayout(); + form->padAll(0); + + auto line = form->newLine(&grid); // Beeps mode new StaticText(line, rect_t{}, STR_SPEAKER, 0, COLOR_THEME_PRIMARY1); new Choice(line, rect_t{}, STR_VBEEPMODE, -2, 1, GET_SET_DEFAULT(g_eeGeneral.beepMode)); - line = body.newLine(&grid); + line = form->newLine(&grid); // Main volume new StaticText(line, rect_t{}, STR_VOLUME, 0, COLOR_THEME_PRIMARY1); - new Slider(line, rect_t{0,0,lv_pct(50), PAGE_LINE_HEIGHT}, -VOLUME_LEVEL_DEF, VOLUME_LEVEL_MAX-VOLUME_LEVEL_DEF, GET_SET_DEFAULT(g_eeGeneral.speakerVolume)); - line = body.newLine(&grid); + new Slider(line, lv_pct(50), -VOLUME_LEVEL_DEF, VOLUME_LEVEL_MAX-VOLUME_LEVEL_DEF, GET_SET_DEFAULT(g_eeGeneral.speakerVolume)); + line = form->newLine(&grid); // Beeps volume new StaticText(line, rect_t{}, STR_BEEP_VOLUME, 0, COLOR_THEME_PRIMARY1); - new Slider(line, rect_t{0,0,lv_pct(50),PAGE_LINE_HEIGHT}, -2, +2, GET_SET_DEFAULT(g_eeGeneral.beepVolume)); - line = body.newLine(&grid); + new Slider(line, lv_pct(50), -2, +2, GET_SET_DEFAULT(g_eeGeneral.beepVolume)); + line = form->newLine(&grid); // Beeps length new StaticText(line, rect_t{}, STR_BEEP_LENGTH, 0, COLOR_THEME_PRIMARY1); - new Slider(line, rect_t{0,0,lv_pct(50),PAGE_LINE_HEIGHT}, -2, +2, GET_SET_DEFAULT(g_eeGeneral.beepLength)); - line = body.newLine(&grid); + new Slider(line, lv_pct(50), -2, +2, GET_SET_DEFAULT(g_eeGeneral.beepLength)); + line = form->newLine(&grid); // Beeps pitch new StaticText(line, rect_t{}, STR_BEEP_PITCH, 0, COLOR_THEME_PRIMARY1); @@ -293,16 +300,16 @@ class SoundPage : public SubPage { edit->setStep(15); edit->setPrefix("+"); edit->setSuffix("Hz"); - line = body.newLine(&grid); + line = form->newLine(&grid); // Wav volume new StaticText(line, rect_t{}, STR_WAV_VOLUME, 0, COLOR_THEME_PRIMARY1); - new Slider(line, rect_t{0,0,lv_pct(50),PAGE_LINE_HEIGHT}, -2, +2, GET_SET_DEFAULT(g_eeGeneral.wavVolume)); - line = body.newLine(&grid); + new Slider(line, lv_pct(50), -2, +2, GET_SET_DEFAULT(g_eeGeneral.wavVolume)); + line = form->newLine(&grid); // Background volume new StaticText(line, rect_t{}, STR_BG_VOLUME, 0, COLOR_THEME_PRIMARY1); - new Slider(line, rect_t{0,0,lv_pct(50),PAGE_LINE_HEIGHT}, -2, +2, GET_SET_DEFAULT(g_eeGeneral.backgroundVolume)); + new Slider(line, lv_pct(50), -2, +2, GET_SET_DEFAULT(g_eeGeneral.backgroundVolume)); } }; @@ -318,7 +325,7 @@ class VarioPage : public SubPage { // Vario volume new StaticText(line, rect_t{}, STR_VOLUME, 0, COLOR_THEME_PRIMARY1); - new Slider(line, rect_t{0,0,lv_pct(50),PAGE_LINE_HEIGHT}, -2, +2, GET_SET_DEFAULT(g_eeGeneral.varioVolume)); + new Slider(line, lv_pct(50), -2, +2, GET_SET_DEFAULT(g_eeGeneral.varioVolume)); line = body.newLine(&grid); new StaticText(line, rect_t{}, STR_PITCH_AT_ZERO, 0, COLOR_THEME_PRIMARY1); @@ -364,12 +371,12 @@ class HapticPage : public SubPage { // Haptic duration new StaticText(line, rect_t{}, STR_LENGTH, 0, COLOR_THEME_PRIMARY1); - new Slider(line, rect_t{0,0,lv_pct(50),PAGE_LINE_HEIGHT}, -2, +2, GET_SET_DEFAULT(g_eeGeneral.hapticLength)); + new Slider(line, lv_pct(50), -2, +2, GET_SET_DEFAULT(g_eeGeneral.hapticLength)); line = body.newLine(&grid); // Haptic strength new StaticText(line, rect_t{}, STR_STRENGTH, 0, COLOR_THEME_PRIMARY1); - new Slider(line, rect_t{0,0,lv_pct(50),PAGE_LINE_HEIGHT}, -2, +2, GET_SET_DEFAULT(g_eeGeneral.hapticStrength)); + new Slider(line, lv_pct(50), -2, +2, GET_SET_DEFAULT(g_eeGeneral.hapticStrength)); line = body.newLine(&grid); } }; @@ -385,14 +392,12 @@ class AlarmsPage : public SubPage { // Battery warning new StaticText(line, rect_t{}, STR_BATTERYWARNING, 0, COLOR_THEME_PRIMARY1); auto edit = new NumberEdit(line, rect_t{}, 30, 120, GET_SET_DEFAULT(g_eeGeneral.vBatWarn), 0, PREC1); - lv_obj_set_style_grid_cell_x_align(edit->getLvObj(), LV_GRID_ALIGN_STRETCH, 0); edit->setSuffix("V"); line = body.newLine(&grid); // Inactivity alarm new StaticText(line, rect_t{}, STR_INACTIVITYALARM, 0, COLOR_THEME_PRIMARY1); edit = new NumberEdit(line, rect_t{}, 0, 250, GET_SET_DEFAULT(g_eeGeneral.inactivityTimer)); - lv_obj_set_style_grid_cell_x_align(edit->getLvObj(), LV_GRID_ALIGN_STRETCH, 0); edit->setDisplayHandler([=](int value) -> std::string { std::string suffix(STR_MINUTE_PLURAL2); @@ -420,14 +425,14 @@ class AlarmsPage : public SubPage { // Alarms warning new StaticText(line, rect_t{}, STR_ALARMWARNING, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, + new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.disableAlarmWarning)); line = body.newLine(&grid); // RSSI shutdown alarm new StaticText(line, rect_t{}, STR_RSSI_SHUTDOWN_ALARM, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, + new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.disableRssiPoweroffAlarm)); line = body.newLine(&grid); } @@ -470,7 +475,7 @@ class BacklightPage : public SubPage { // Backlight ON bright new StaticText(backlightOnBright, rect_t{}, STR_BLONBRIGHTNESS, 0, COLOR_THEME_PRIMARY1); - new Slider(backlightOnBright, rect_t{0,0,lv_pct(50),PAGE_LINE_HEIGHT}, BACKLIGHT_LEVEL_MIN, BACKLIGHT_LEVEL_MAX, + new Slider(backlightOnBright, lv_pct(50), BACKLIGHT_LEVEL_MIN, BACKLIGHT_LEVEL_MAX, [=]() -> int32_t { return BACKLIGHT_LEVEL_MAX - g_eeGeneral.backlightBright; }, @@ -486,7 +491,7 @@ class BacklightPage : public SubPage { // Backlight OFF bright new StaticText(backlightOffBright, rect_t{}, STR_BLOFFBRIGHTNESS, 0, COLOR_THEME_PRIMARY1); - new Slider(backlightOffBright, rect_t{0,0,lv_pct(50),PAGE_LINE_HEIGHT}, BACKLIGHT_LEVEL_MIN, BACKLIGHT_LEVEL_MAX, GET_DEFAULT(g_eeGeneral.blOffBright), + new Slider(backlightOffBright, lv_pct(50), BACKLIGHT_LEVEL_MIN, BACKLIGHT_LEVEL_MAX, GET_DEFAULT(g_eeGeneral.blOffBright), [=](int32_t newValue) { int32_t onBright = BACKLIGHT_LEVEL_MAX - g_eeGeneral.backlightBright; if(newValue <= onBright || g_eeGeneral.backlightMode == e_backlight_mode_off) @@ -501,13 +506,13 @@ class BacklightPage : public SubPage { #if defined(KEYS_BACKLIGHT_GPIO) // Keys backlight new StaticText(line, rect_t{}, STR_KEYS_BACKLIGHT, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_eeGeneral.keysBacklight)); + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(g_eeGeneral.keysBacklight)); line = body.newLine(&grid); #endif // Flash beep new StaticText(line, rect_t{}, STR_ALARM, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_eeGeneral.alarmsFlash)); + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(g_eeGeneral.alarmsFlash)); line = body.newLine(&grid); updateBacklightControls(); @@ -576,7 +581,7 @@ class GpsPage : public SubPage { // Adjust RTC (from telemetry) new StaticText(line, rect_t{}, STR_ADJUST_RTC, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_eeGeneral.adjustRTC)); + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(g_eeGeneral.adjustRTC)); line = body.newLine(&grid); // GPS format @@ -589,18 +594,13 @@ class GpsPage : public SubPage { int tzIndex; }; -class ViewOptionsPage : public Page +class ViewOptionsPage : public SubPage { public: const lv_coord_t opt_col_two_dsc[3] = {LV_GRID_FR(7), LV_GRID_FR(3), LV_GRID_TEMPLATE_LAST}; - ViewOptionsPage() : Page(ICON_RADIO_SETUP) + ViewOptionsPage() : SubPage(ICON_RADIO_SETUP, STR_ENABLED_FEATURES, false) { - header.setTitle(STR_RADIO_SETUP); - header.setTitle2(STR_ENABLED_FEATURES); - - body.padAll(8); - FlexGridLayout grid(opt_col_two_dsc, row_dsc, 2); auto form = new FormWindow(&body, rect_t{}); @@ -613,17 +613,17 @@ class ViewOptionsPage : public Page line = form->newLine(&grid); line->padLeft(10); new StaticText(line, rect_t{}, STR_THEME_EDITOR, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.radioThemesDisabled)); + new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.radioThemesDisabled)); line = form->newLine(&grid); line->padLeft(10); new StaticText(line, rect_t{}, STR_MENUSPECIALFUNCS, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.radioGFDisabled)); + new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.radioGFDisabled)); line = form->newLine(&grid); line->padLeft(10); new StaticText(line, rect_t{}, STR_MENUTRAINER, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.radioTrainerDisabled)); + new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.radioTrainerDisabled)); line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_MODEL_MENU_TABS, 0, COLOR_THEME_PRIMARY1); @@ -632,49 +632,49 @@ class ViewOptionsPage : public Page line = form->newLine(&grid); line->padLeft(10); new StaticText(line, rect_t{}, STR_MENUHELISETUP, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelHeliDisabled)); + new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelHeliDisabled)); #endif #if defined(FLIGHT_MODES) line = form->newLine(&grid); line->padLeft(10); new StaticText(line, rect_t{}, STR_MENUFLIGHTMODES, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelFMDisabled)); + new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelFMDisabled)); #endif #if defined(GVARS) line = form->newLine(&grid); line->padLeft(10); new StaticText(line, rect_t{}, STR_MENU_GLOBAL_VARS, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelGVDisabled)); + new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelGVDisabled)); #endif line = form->newLine(&grid); line->padLeft(10); new StaticText(line, rect_t{}, STR_MENUCURVES, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelCurvesDisabled)); + new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelCurvesDisabled)); line = form->newLine(&grid); line->padLeft(10); new StaticText(line, rect_t{}, STR_MENULOGICALSWITCHES, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelLSDisabled)); + new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelLSDisabled)); line = form->newLine(&grid); line->padLeft(10); new StaticText(line, rect_t{}, STR_MENUCUSTOMFUNC, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelSFDisabled)); + new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelSFDisabled)); #if defined(LUA_MODEL_SCRIPTS) line = form->newLine(&grid); line->padLeft(10); new StaticText(line, rect_t{}, STR_MENUCUSTOMSCRIPTS, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelCustomScriptsDisabled)); + new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelCustomScriptsDisabled)); #endif line = form->newLine(&grid); line->padLeft(10); new StaticText(line, rect_t{}, STR_MENUTELEMETRY, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelTelemetryDisabled)); + new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelTelemetryDisabled)); } }; @@ -721,7 +721,7 @@ void RadioSetupPage::build(FormWindow * window) // Play startup sound line = window->newLine(&grid); new StaticText(line, rect_t{}, STR_PLAY_HELLO, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.dontPlayHello)); + new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.dontPlayHello)); #if defined(PWR_BUTTON_PRESS) // Pwr Off Delay @@ -851,5 +851,5 @@ void RadioSetupPage::build(FormWindow * window) // Model quick select line = window->newLine(&grid); new StaticText(line, rect_t{}, STR_MODEL_QUICK_SELECT, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_eeGeneral.modelQuickSelect)); + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(g_eeGeneral.modelQuickSelect)); } diff --git a/radio/src/gui/colorlcd/radio_spectrum_analyser.cpp b/radio/src/gui/colorlcd/radio_spectrum_analyser.cpp index 9ec0d2ab0eb..7397f872dd0 100644 --- a/radio/src/gui/colorlcd/radio_spectrum_analyser.cpp +++ b/radio/src/gui/colorlcd/radio_spectrum_analyser.cpp @@ -45,7 +45,7 @@ coord_t getAverage(uint8_t number, const uint8_t * value) class SpectrumFooterWindow: public FormWindow { public: - SpectrumFooterWindow(FormGroup * parent, const rect_t & rect, int moduleIdx) : + SpectrumFooterWindow(FormWindow * parent, const rect_t & rect, int moduleIdx) : FormWindow(parent, rect) { setFlexLayout(); diff --git a/radio/src/gui/colorlcd/radio_theme.cpp b/radio/src/gui/colorlcd/radio_theme.cpp index 73179835b9d..aeeac8b8be1 100644 --- a/radio/src/gui/colorlcd/radio_theme.cpp +++ b/radio/src/gui/colorlcd/radio_theme.cpp @@ -340,6 +340,8 @@ class ColorEditPage : public Page auto t2 = header.setTitle2(ThemePersistance::getColorNames()[(int)_indexOfColor]); #if LCD_H > LCD_W t2->setFont(FONT(XS)); +#else + LV_UNUSED(t2); #endif // page tabs @@ -413,7 +415,7 @@ class ThemeEditPage : public Page }); } - void buildHeader(FormGroup *window) + void buildHeader(FormWindow *window) { // page title header.setTitle(STR_EDIT_THEME); @@ -438,7 +440,7 @@ class ThemeEditPage : public Page }); } - void buildBody(FormGroup *window) + void buildBody(FormWindow *window) { window->padAll(4); FormWindow *form = new FormWindow(window, {0, 0, window->width() - 8, window->height() - 8}); diff --git a/radio/src/gui/colorlcd/radio_trainer.cpp b/radio/src/gui/colorlcd/radio_trainer.cpp index cfcc60a4c40..061620ed6a5 100644 --- a/radio/src/gui/colorlcd/radio_trainer.cpp +++ b/radio/src/gui/colorlcd/radio_trainer.cpp @@ -39,10 +39,12 @@ static const lv_coord_t col_dsc[] = {LV_GRID_FR(7), LV_GRID_FR(13), LV_GRID_FR(1 LV_GRID_TEMPLATE_LAST}; #define MULT_COL_CNT 3 +#define NUM_EDIT_W 80 #else static const lv_coord_t col_dsc[] = {LV_GRID_FR(7), LV_GRID_FR(15), LV_GRID_FR(9), LV_GRID_FR(9), LV_GRID_TEMPLATE_LAST}; #define MULT_COL_CNT 2 +#define NUM_EDIT_W 65 #endif static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; @@ -73,7 +75,7 @@ void RadioTrainerPage::build(FormWindow * form) new Choice(line, rect_t{}, STR_TRNMODE, 0, 2, GET_SET_DEFAULT(td->mode)); new Choice(line, rect_t{}, STR_TRNCHN, 0, 3, GET_SET_DEFAULT(td->srcChn)); - auto weight = new NumberEdit(line, rect_t{}, -125, 125, + auto weight = new NumberEdit(line, rect_t{0, 0, NUM_EDIT_W, 0}, -125, 125, GET_SET_DEFAULT(td->studWeight)); weight->setSuffix("%"); @@ -83,7 +85,7 @@ void RadioTrainerPage::build(FormWindow * form) line->padBottom(8); #endif - auto d = new DynamicNumber(line, rect_t{}, + new DynamicNumber(line, rect_t{}, [=]() { return (ppmInput[i] - g_eeGeneral.trainer.calib[i]) * 2; }, LEFT | PPM_PRECISION | COLOR_THEME_PRIMARY1); } @@ -95,7 +97,7 @@ void RadioTrainerPage::build(FormWindow * form) auto lbl = new StaticText(line, rect_t{}, STR_MULTIPLIER, 0, COLOR_THEME_PRIMARY1); lbl->padRight(4); lv_obj_set_grid_cell(lbl->getLvObj(), LV_GRID_ALIGN_END, 0, MULT_COL_CNT, LV_GRID_ALIGN_CENTER, 0, 1); - auto multiplier = new NumberEdit(line, rect_t{}, -10, 40, + auto multiplier = new NumberEdit(line, rect_t{0, 0, NUM_EDIT_W, 0}, -10, 40, GET_SET_DEFAULT(g_eeGeneral.PPM_Multiplier)); multiplier->setDisplayHandler( [](int32_t value) { return formatNumberAsString(value + 10, PREC1); }); diff --git a/radio/src/gui/colorlcd/screen_setup.cpp b/radio/src/gui/colorlcd/screen_setup.cpp index 245a79180c0..0f312314e34 100644 --- a/radio/src/gui/colorlcd/screen_setup.cpp +++ b/radio/src/gui/colorlcd/screen_setup.cpp @@ -40,7 +40,7 @@ class LayoutChoice : public Button typedef std::function LayoutFactorySetter; LayoutChoice(Window* parent, LayoutFactoryGetter getValue, LayoutFactorySetter setValue) : - Button(parent, rect_t{}, nullptr, 0, 0, lv_btn_create), + Button(parent, rect_t{}, nullptr, 0, 0, etx_button_create), getValue(std::move(getValue)), _setValue(std::move(setValue)) { @@ -170,8 +170,13 @@ void ScreenAddPage::build(FormWindow * window) }); } +#if LCD_W > LCD_H +static const lv_coord_t line_col_dsc[] = {LV_GRID_FR(2), LV_GRID_FR(1), LV_GRID_FR(2), + LV_GRID_TEMPLATE_LAST}; +#else static const lv_coord_t line_col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; +#endif static const lv_coord_t line_row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; @@ -227,8 +232,7 @@ void ScreenSetupPage::build(FormWindow * window) auto line = window->newLine(&grid); auto label = new StaticText(line, rect_t{}, STR_LAYOUT, 0, COLOR_THEME_PRIMARY1); - auto obj = label->getLvObj(); - lv_obj_set_style_grid_cell_y_align(obj, LV_GRID_ALIGN_START, 0); + lv_obj_set_style_grid_cell_y_align(label->getLvObj(), LV_GRID_ALIGN_CENTER, 0); // Dynamic options window... auto idx = customScreenIndex; @@ -248,47 +252,35 @@ void ScreenSetupPage::build(FormWindow * window) buildLayoutOptions(); }; - auto layoutForm = new FormGroup(line, rect_t{}, FORWARD_SCROLL | FORM_FORWARD_FOCUS); - layoutForm->setFlexLayout(LV_FLEX_FLOW_ROW_WRAP, 8); + Window* btn = new LayoutChoice(line, getFactory, setLayout); + auto obj = btn->getLvObj(); + lv_obj_set_style_min_width(obj, LV_DPI_DEF / 2, LV_PART_MAIN); + lv_obj_set_style_min_height(obj, LV_DPI_DEF / 3, LV_PART_MAIN); + lv_obj_set_style_pad_all(obj, 8, LV_PART_MAIN); + lv_obj_set_style_radius(obj, 8, LV_PART_MAIN); - obj = layoutForm->getLvObj(); - lv_obj_set_style_grid_cell_x_align(obj, LV_GRID_ALIGN_STRETCH, 0); +#if LCD_H > LCD_W + line = window->newLine(&grid); + grid.nextCell(); +#endif + btn = new TextButton(line, rect_t{}, STR_SETUP_WIDGETS, + startWidgetsSetup(menu, idx)); + lv_obj_set_style_grid_cell_y_align(btn->getLvObj(), LV_GRID_ALIGN_CENTER, 0); + lv_group_focus_obj(btn->getLvObj()); line = window->newLine(); - layoutOptions = new FormGroup(line, rect_t{}, FORWARD_SCROLL | FORM_FORWARD_FOCUS); + layoutOptions = new FormWindow(line, rect_t{}); buildLayoutOptions(); // Prevent removing the last page if (customScreens[1] != nullptr) { line = window->newLine(); Window* btn = new TextButton(line, rect_t{}, STR_REMOVE_SCREEN, removeScreen(menu, idx)); - obj = btn->getLvObj(); - lv_obj_set_style_min_width(obj, LV_DPI_DEF / 2, LV_PART_MAIN); - lv_obj_set_style_min_height(obj, LV_DPI_DEF / 3, LV_PART_MAIN); - lv_obj_set_style_pad_all(obj, 8, LV_PART_MAIN); - lv_obj_set_style_radius(obj, 8, LV_PART_MAIN); - + auto obj = btn->getLvObj(); lv_obj_set_width(obj, lv_pct(50)); lv_obj_center(obj); } - Window* btn = new LayoutChoice(layoutForm, getFactory, setLayout); - obj = btn->getLvObj(); - lv_obj_set_style_min_width(obj, LV_DPI_DEF / 2, LV_PART_MAIN); - lv_obj_set_style_min_height(obj, LV_DPI_DEF / 3, LV_PART_MAIN); - lv_obj_set_style_pad_all(obj, 8, LV_PART_MAIN); - lv_obj_set_style_radius(obj, 8, LV_PART_MAIN); - lv_group_focus_obj(obj); - - btn = new TextButton(layoutForm, rect_t{}, STR_SETUP_WIDGETS, - startWidgetsSetup(menu, idx)); - obj = btn->getLvObj(); - lv_obj_set_style_min_width(obj, LV_DPI_DEF / 2, LV_PART_MAIN); - lv_obj_set_style_min_height(obj, LV_DPI_DEF / 3, LV_PART_MAIN); - lv_obj_set_style_pad_all(obj, 8, LV_PART_MAIN); - lv_obj_set_style_radius(obj, 8, LV_PART_MAIN); - lv_group_focus_obj(obj); - window->updateSize(); } @@ -325,7 +317,7 @@ void ScreenSetupPage::buildLayoutOptions() // Option value switch (option->type) { case ZoneOption::Bool: - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(value->boolValue)); + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(value->boolValue)); break; case ZoneOption::Color: diff --git a/radio/src/gui/colorlcd/screen_setup.h b/radio/src/gui/colorlcd/screen_setup.h index b93d568690a..a87f9a4d4d4 100644 --- a/radio/src/gui/colorlcd/screen_setup.h +++ b/radio/src/gui/colorlcd/screen_setup.h @@ -49,7 +49,7 @@ class ScreenSetupPage : public PageTab ScreenMenu* menu; unsigned pageIndex; unsigned customScreenIndex; - FormGroup* layoutOptions = nullptr; + FormWindow* layoutOptions = nullptr; void clearLayoutOptions(); void buildLayoutOptions(); diff --git a/radio/src/gui/colorlcd/select_fab_button.cpp b/radio/src/gui/colorlcd/select_fab_button.cpp index 561cdb97b2e..832ff289632 100644 --- a/radio/src/gui/colorlcd/select_fab_button.cpp +++ b/radio/src/gui/colorlcd/select_fab_button.cpp @@ -21,7 +21,7 @@ #include "select_fab_button.h" -SelectFabButton::SelectFabButton(FormGroup* parent, +SelectFabButton::SelectFabButton(FormWindow* parent, uint8_t icon, const char* title, std::function pressHandler, WindowFlags windowFlags) : diff --git a/radio/src/gui/colorlcd/select_fab_button.h b/radio/src/gui/colorlcd/select_fab_button.h index ce4b29642b8..c190f492030 100644 --- a/radio/src/gui/colorlcd/select_fab_button.h +++ b/radio/src/gui/colorlcd/select_fab_button.h @@ -28,7 +28,7 @@ constexpr coord_t SELECT_BUTTON_BORDER = 12; class SelectFabButton : public FabButton { public: - SelectFabButton(FormGroup* parent, uint8_t icon, const char* title, + SelectFabButton(FormWindow* parent, uint8_t icon, const char* title, std::function pressHandler, WindowFlags windowFlags = 0); diff --git a/radio/src/gui/colorlcd/select_fab_carousel.cpp b/radio/src/gui/colorlcd/select_fab_carousel.cpp index 59b9e9c1a82..9f0bc37612f 100644 --- a/radio/src/gui/colorlcd/select_fab_carousel.cpp +++ b/radio/src/gui/colorlcd/select_fab_carousel.cpp @@ -22,7 +22,7 @@ #include "select_fab_carousel.h" SelectFabCarousel::SelectFabCarousel(Window* parent) : - FormGroup(parent, {}, FORM_FORWARD_FOCUS | NO_SCROLLBAR) + FormWindow(parent, {}) { setFlexLayout(LV_FLEX_FLOW_ROW_WRAP); diff --git a/radio/src/gui/colorlcd/select_fab_carousel.h b/radio/src/gui/colorlcd/select_fab_carousel.h index f457dcc8bea..f8741ca3c7e 100644 --- a/radio/src/gui/colorlcd/select_fab_carousel.h +++ b/radio/src/gui/colorlcd/select_fab_carousel.h @@ -23,7 +23,7 @@ #include "select_fab_button.h" -class SelectFabCarousel : public FormGroup +class SelectFabCarousel : public FormWindow { public: explicit SelectFabCarousel(Window* parent); diff --git a/radio/src/gui/colorlcd/sourcechoice.cpp b/radio/src/gui/colorlcd/sourcechoice.cpp index 5acb4357482..c884206ac3a 100644 --- a/radio/src/gui/colorlcd/sourcechoice.cpp +++ b/radio/src/gui/colorlcd/sourcechoice.cpp @@ -19,7 +19,6 @@ * GNU General Public License for more details. */ -#include "libopenui_config.h" #include "sourcechoice.h" #include "menutoolbar.h" #include "menu.h" @@ -68,7 +67,7 @@ SourceChoice::SourceChoice(Window* parent, const rect_t &rect, int16_t vmin, int16_t vmax, std::function getValue, std::function setValue, WindowFlags windowFlags, LcdFlags textFlags) : - ChoiceEx(parent, rect, vmin, vmax, getValue, setValue) + Choice(parent, rect, vmin, vmax, getValue, setValue) { setBeforeDisplayMenuHandler([=](Menu *menu) { auto tb = new SourceChoiceMenuToolbar(this, menu); diff --git a/radio/src/gui/colorlcd/sourcechoice.h b/radio/src/gui/colorlcd/sourcechoice.h index ca9b1904e93..3b2e8592dc9 100644 --- a/radio/src/gui/colorlcd/sourcechoice.h +++ b/radio/src/gui/colorlcd/sourcechoice.h @@ -22,12 +22,12 @@ #ifndef _SOURCECHOICE_H_ #define _SOURCECHOICE_H_ -#include "choiceex.h" +#include "choice.h" #include "form.h" bool isSourceAvailable(int source); -class SourceChoice : public ChoiceEx +class SourceChoice : public Choice { public: SourceChoice(Window* parent, const rect_t& rect, int16_t vmin, diff --git a/radio/src/gui/colorlcd/special_functions.cpp b/radio/src/gui/colorlcd/special_functions.cpp index 94b792f149f..6a0e46bea5b 100644 --- a/radio/src/gui/colorlcd/special_functions.cpp +++ b/radio/src/gui/colorlcd/special_functions.cpp @@ -23,7 +23,6 @@ #include "opentx.h" #include "libopenui.h" #include "view_main.h" -#include "lvgl_widgets/input_mix_line.h" #include "hal/adc_driver.h" #include "strhelpers.h" @@ -90,13 +89,13 @@ class SpecialFunctionEditPage : public Page lv_obj_set_style_text_font(headerSF->getLvObj(), getFont(FONT(BOLD)), LV_STATE_USER_1); } - void addSourceChoice(FormGroup::Line* line, const char* title, CustomFunctionData* cfn, int16_t vmax) + void addSourceChoice(FormWindow::Line* line, const char* title, CustomFunctionData* cfn, int16_t vmax) { new StaticText(line, rect_t{}, title, 0, COLOR_THEME_PRIMARY1); new SourceChoice(line, rect_t{}, 0, vmax, GET_SET_DEFAULT(CFN_PARAM(cfn))); } - NumberEdit* addNumberEdit(FormGroup::Line* line, const char* title, CustomFunctionData* cfn, int16_t vmin, int16_t vmax) + NumberEdit* addNumberEdit(FormWindow::Line* line, const char* title, CustomFunctionData* cfn, int16_t vmin, int16_t vmax) { new StaticText(line, rect_t{}, title, 0, COLOR_THEME_PRIMARY1); return new NumberEdit(line, rect_t{}, vmin, vmax, GET_SET_DEFAULT(CFN_PARAM(cfn))); @@ -329,7 +328,7 @@ class SpecialFunctionEditPage : public Page if (HAS_ENABLE_PARAM(func)) { line = specialFunctionOneWindow->newLine(&grid); new StaticText(line, rect_t{}, STR_ENABLE, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(CFN_ACTIVE(cfn))); } else if (HAS_REPEAT_PARAM(func)) { // !1x 1x 1s 2s 3s ... line = specialFunctionOneWindow->newLine(&grid); @@ -513,13 +512,19 @@ class SpecialFunctionButton : public Button lv_obj_set_grid_cell(sfRepeat, LV_GRID_ALIGN_CENTER, FUNC_COL+1, 1, LV_GRID_ALIGN_CENTER, 0, NM_ROW_CNT); sfEnable = lv_obj_create(lvobj); - lv_obj_set_size(sfEnable, 16, 16); + lv_obj_set_size(sfEnable, 22, 22); lv_obj_add_flag(sfEnable, LV_OBJ_FLAG_HIDDEN); - lv_obj_set_style_border_width(sfEnable, 2, 0); - lv_obj_set_style_border_color(sfEnable, makeLvColor(COLOR_THEME_SECONDARY1), 0); + lv_obj_set_style_border_width(sfEnable, 3, 0); + lv_obj_set_style_border_color(sfEnable, makeLvColor(COLOR_THEME_PRIMARY2), 0); lv_obj_set_style_border_opa(sfEnable, LV_OPA_100, 0); lv_obj_set_style_bg_color(sfEnable, makeLvColor(COLOR_THEME_ACTIVE), LV_STATE_CHECKED); lv_obj_set_style_bg_opa(sfEnable, LV_OPA_100, 0); + auto sfEnableInner = lv_obj_create(sfEnable); + lv_obj_set_size(sfEnableInner, 16, 16); + lv_obj_set_style_border_width(sfEnableInner, 2, 0); + lv_obj_set_style_border_color(sfEnableInner, makeLvColor(COLOR_THEME_SECONDARY1), 0); + lv_obj_set_style_border_opa(sfEnableInner, LV_OPA_100, 0); + lv_obj_set_style_bg_opa(sfEnableInner, LV_OPA_0, 0); lv_obj_set_grid_cell(sfEnable, LV_GRID_ALIGN_CENTER, FUNC_COL+2, 1, LV_GRID_ALIGN_CENTER, 0, NM_ROW_CNT); init = true; @@ -694,7 +699,7 @@ class SpecialFunctionButton : public Button }; #if LCD_W > LCD_H -#define SF_BUTTON_H 36 +#define SF_BUTTON_H 34 #else #define SF_BUTTON_H 45 #endif diff --git a/radio/src/gui/colorlcd/switch_warn_dialog.h b/radio/src/gui/colorlcd/switch_warn_dialog.h index 47a5c549b8f..c76d220fa97 100644 --- a/radio/src/gui/colorlcd/switch_warn_dialog.h +++ b/radio/src/gui/colorlcd/switch_warn_dialog.h @@ -25,7 +25,6 @@ #include "fullscreen_dialog.h" #include "mainwindow.h" #include "opentx.h" -#include "gridlayout.h" class SwitchWarnDialog : public FullScreenDialog { diff --git a/radio/src/gui/colorlcd/switchchoice.cpp b/radio/src/gui/colorlcd/switchchoice.cpp index 81cc81e4566..c13a5c74b3a 100644 --- a/radio/src/gui/colorlcd/switchchoice.cpp +++ b/radio/src/gui/colorlcd/switchchoice.cpp @@ -22,7 +22,6 @@ #include "dataconstants.h" #include "draw_functions.h" -#include "libopenui_config.h" #include "menu.h" #include "menutoolbar.h" #include "opentx.h" @@ -56,7 +55,7 @@ void SwitchChoice::LongPressHandler(void* data) SwitchChoice::SwitchChoice(Window* parent, const rect_t& rect, int vmin, int vmax, std::function getValue, std::function setValue) : - ChoiceEx(parent, rect, vmin, vmax, getValue, setValue) + Choice(parent, rect, vmin, vmax, getValue, setValue) { setBeforeDisplayMenuHandler([=](Menu* menu) { auto tb = new SwitchChoiceMenuToolbar(this, menu); diff --git a/radio/src/gui/colorlcd/switchchoice.h b/radio/src/gui/colorlcd/switchchoice.h index 01677846125..f58dfbe38c1 100644 --- a/radio/src/gui/colorlcd/switchchoice.h +++ b/radio/src/gui/colorlcd/switchchoice.h @@ -22,10 +22,10 @@ #ifndef _SWITCHCHOICE_H_ #define _SWITCHCHOICE_H_ -#include "choiceex.h" +#include "choice.h" #include "form.h" -class SwitchChoice : public ChoiceEx +class SwitchChoice : public Choice { public: SwitchChoice(Window* parent, const rect_t& rect, int vmin, int vmax, diff --git a/radio/src/gui/colorlcd/tabsgroup.cpp b/radio/src/gui/colorlcd/tabsgroup.cpp index 6702ae9de6f..b9be76edae3 100644 --- a/radio/src/gui/colorlcd/tabsgroup.cpp +++ b/radio/src/gui/colorlcd/tabsgroup.cpp @@ -45,11 +45,7 @@ TabCarouselButton::TabCarouselButton(Window* parent, const rect_t& rect, void TabCarouselButton::paint(BitmapBuffer * dc) { - if(checked()) { - OpenTxTheme::instance()->drawCurrentMenuBackground(dc); - } - - dc->drawBitmap(2, 7, theme->getIcon(tabs[index]->getIcon(), checked() ? STATE_PRESSED : STATE_DEFAULT)); + EdgeTxTheme::instance()->drawMenuIcon(dc, tabs[index]->getIcon(), checked()); } void TabCarouselButton::check(bool checked) @@ -61,7 +57,7 @@ void TabCarouselButton::check(bool checked) } TabsGroupHeader::TabsGroupHeader(TabsGroup* parent, uint8_t icon) : - FormGroup(parent, {0, 0, LCD_W, MENU_BODY_TOP}, NO_FOCUS | OPAQUE), + FormWindow(parent, {0, 0, LCD_W, MENU_BODY_TOP}, NO_FOCUS | OPAQUE), #if defined(HARDWARE_TOUCH) back( this, @@ -70,7 +66,7 @@ TabsGroupHeader::TabsGroupHeader(TabsGroup* parent, uint8_t icon) : parent->deleteLater(); return 1; }, - NO_FOCUS | FORM_NO_BORDER, + NO_FOCUS, 0, window_create), #endif icon(icon), @@ -81,7 +77,7 @@ TabsGroupHeader::TabsGroupHeader(TabsGroup* parent, uint8_t icon) : void TabsGroupHeader::paint(BitmapBuffer* dc) { - OpenTxTheme::instance()->drawPageHeaderBackground(dc, icon, title.c_str()); + EdgeTxTheme::instance()->drawPageHeaderBackground(dc, icon, title.c_str()); } TabsCarousel::TabsCarousel(Window* parent, TabsGroup* menu) : @@ -144,7 +140,7 @@ TabsGroup* TabsGroup::activeTabsGroup = nullptr; TabsGroup::TabsGroup(uint8_t icon): Window(Layer::back(), { 0, 0, LCD_W, LCD_H }, OPAQUE), header(this, icon), - body(this, _get_body_rect(), NO_FOCUS | FORM_FORWARD_FOCUS) + body(this, _get_body_rect(), NO_FOCUS) { Layer::push(this); diff --git a/radio/src/gui/colorlcd/tabsgroup.h b/radio/src/gui/colorlcd/tabsgroup.h index b182fcb2e3e..35b6631ad6e 100644 --- a/radio/src/gui/colorlcd/tabsgroup.h +++ b/radio/src/gui/colorlcd/tabsgroup.h @@ -131,7 +131,7 @@ class TabsCarousel: public Window { #endif }; -class TabsGroupHeader: public FormGroup { +class TabsGroupHeader: public FormWindow { friend class TabsGroup; public: @@ -153,7 +153,7 @@ class TabsGroupHeader: public FormGroup { back.deleteLater(true, false); #endif carousel.deleteLater(true, false); - FormGroup::deleteLater(detach, trash); + FormWindow::deleteLater(detach, trash); } void paint(BitmapBuffer * dc) override; diff --git a/radio/src/gui/colorlcd/theme.cpp b/radio/src/gui/colorlcd/theme.cpp index ee1137b8a43..319a905a2e4 100644 --- a/radio/src/gui/colorlcd/theme.cpp +++ b/radio/src/gui/colorlcd/theme.cpp @@ -22,13 +22,10 @@ #include "opentx.h" #include "libopenui.h" -//#include "checkbox.h" -//#include "modal_window.h" - -extern OpenTxTheme * defaultTheme; -const BitmapBuffer * OpenTxTheme::error = nullptr; -const BitmapBuffer * OpenTxTheme::busy = nullptr; -const BitmapBuffer * OpenTxTheme::shutdown = nullptr; +extern EdgeTxTheme * defaultTheme; +const BitmapBuffer * EdgeTxTheme::error = nullptr; +const BitmapBuffer * EdgeTxTheme::busy = nullptr; +const BitmapBuffer * EdgeTxTheme::shutdown = nullptr; constexpr coord_t LBM_USB_PLUGGED_W = 211; constexpr coord_t LBM_USB_PLUGGED_H = 110; @@ -50,21 +47,21 @@ const uint8_t shutdown_bitmap[] = { #include "mask_shutdown.lbm" }; -std::list & getRegisteredThemes() +std::list & getRegisteredThemes() { - static std::list themes; + static std::list themes; return themes; } -void registerTheme(OpenTxTheme * theme) +void registerTheme(EdgeTxTheme * theme) { TRACE("register theme %s", theme->getName()); getRegisteredThemes().push_back(theme); } -void OpenTxTheme::init() const +void EdgeTxTheme::init() const { - memset(&g_eeGeneral.themeData, 0, sizeof(OpenTxTheme::PersistentData)); + memset(&g_eeGeneral.themeData, 0, sizeof(EdgeTxTheme::PersistentData)); if (options) { int i = 0; for (const ZoneOption * option = options; option->name; option++, i++) { @@ -75,7 +72,7 @@ void OpenTxTheme::init() const } } -void OpenTxTheme::load() const +void EdgeTxTheme::load() const { if (!error) error = BitmapBuffer::load8bitMaskLZ4(error_bitmap); @@ -85,12 +82,12 @@ void OpenTxTheme::load() const shutdown = BitmapBuffer::load8bitMaskLZ4(shutdown_bitmap); } -ZoneOptionValue * OpenTxTheme::getOptionValue(unsigned int index) const +ZoneOptionValue * EdgeTxTheme::getOptionValue(unsigned int index) const { return &g_eeGeneral.themeData.options[index].value; } -const char * OpenTxTheme::getFilePath(const char * filename) const +const char * EdgeTxTheme::getFilePath(const char * filename) const { static char path[FF_MAX_LFN+1] = THEMES_PATH "/"; strcpy(path + sizeof(THEMES_PATH), getName()); @@ -100,7 +97,7 @@ const char * OpenTxTheme::getFilePath(const char * filename) const return path; } -void OpenTxTheme::drawThumb(BitmapBuffer * dc, coord_t x, coord_t y, uint32_t flags) +void EdgeTxTheme::drawThumb(BitmapBuffer * dc, coord_t x, coord_t y, uint32_t flags) { #define THUMB_WIDTH 51 #define THUMB_HEIGHT 31 @@ -113,12 +110,12 @@ void OpenTxTheme::drawThumb(BitmapBuffer * dc, coord_t x, coord_t y, uint32_t fl } } -void OpenTxTheme::drawBackground(BitmapBuffer * dc) const +void EdgeTxTheme::drawBackground(BitmapBuffer * dc) const { dc->drawSolidFilledRect(0, 0, LCD_W, LCD_H, COLOR_THEME_SECONDARY3); } -//void OpenTxTheme::drawMessageBox(const char *title, const char *text, +//void EdgeTxTheme::drawMessageBox(const char *title, const char *text, // const char *action, uint32_t type) const //{ // //if (flags & MESSAGEBOX_TYPE_ALERT) { @@ -159,7 +156,7 @@ void OpenTxTheme::drawBackground(BitmapBuffer * dc) const // } //} -void OpenTxTheme::drawCheckBox(BitmapBuffer *dc, bool checked, coord_t x, +void EdgeTxTheme::drawCheckBox(BitmapBuffer *dc, bool checked, coord_t x, coord_t y, bool focus) const { dc->drawSolidFilledRect(x, y, 16, 16, COLOR_THEME_PRIMARY2); @@ -174,7 +171,7 @@ void OpenTxTheme::drawCheckBox(BitmapBuffer *dc, bool checked, coord_t x, } } -void OpenTxTheme::drawUsbPluggedScreen(BitmapBuffer * dc) const +void EdgeTxTheme::drawUsbPluggedScreen(BitmapBuffer * dc) const { // draw USB icon dc->clear(COLOR_THEME_SECONDARY3); @@ -184,9 +181,9 @@ void OpenTxTheme::drawUsbPluggedScreen(BitmapBuffer * dc) const } -OpenTxTheme * getTheme(const char * name) +EdgeTxTheme * getTheme(const char * name) { - std::list::const_iterator it = getRegisteredThemes().cbegin(); + std::list::const_iterator it = getRegisteredThemes().cbegin(); for (; it != getRegisteredThemes().cend(); ++it) { if (!strcmp(name, (*it)->getName())) { return (*it); @@ -195,7 +192,7 @@ OpenTxTheme * getTheme(const char * name) return nullptr; } -void loadTheme(OpenTxTheme * newTheme) +void loadTheme(EdgeTxTheme * newTheme) { TRACE("load theme %s", newTheme->getName()); theme = newTheme; @@ -207,20 +204,9 @@ void loadTheme() char name[THEME_NAME_LEN + 1]; memset(name, 0, sizeof(name)); strncpy(name, g_eeGeneral.themeName, THEME_NAME_LEN); - OpenTxTheme * newTheme = getTheme(name); + EdgeTxTheme * newTheme = getTheme(name); if (newTheme) loadTheme(newTheme); else loadTheme(defaultTheme); } - -MenuWindowContent * createMenuWindow(Menu * menu) -{ - return new MenuWindowContent(menu); -} - -DialogWindowContent * createDialogWindow(Dialog * dialog, const rect_t & rect) -{ - TRACE("createDialogWindow [%d, %d, %d, %d]", rect.x, rect.y, rect.w, rect.h); - return new DialogWindowContent(dialog, rect); -} diff --git a/radio/src/gui/colorlcd/theme.h b/radio/src/gui/colorlcd/theme.h index a701eab2658..df99cad2fdb 100644 --- a/radio/src/gui/colorlcd/theme.h +++ b/radio/src/gui/colorlcd/theme.h @@ -25,7 +25,11 @@ #include #include #include "zone.h" -#include "thirdparty/libopenui/src/theme.h" + +enum IconState { + STATE_DEFAULT, + STATE_PRESSED, +}; // TODO: hotfix, through FatFS out of libopenui instead #if !defined(YAML_GENERATOR) @@ -39,22 +43,25 @@ class PageTab; #define MAX_THEME_OPTIONS 5 -class OpenTxTheme; -void registerTheme(OpenTxTheme * theme); +class EdgeTxTheme; +void registerTheme(EdgeTxTheme * theme); // YAML_GENERATOR defs #if !defined(USE_IDX) #define USE_IDX #endif -class OpenTxTheme: public Theme +class EdgeTxTheme; +extern EdgeTxTheme * theme; + +class EdgeTxTheme { public: struct PersistentData { ZoneOptionValueTyped options[MAX_THEME_OPTIONS] USE_IDX; }; - explicit OpenTxTheme(const char * name, const ZoneOption * options = nullptr): + explicit EdgeTxTheme(const char * name, const ZoneOption * options = nullptr): name(name), options(options), thumb(nullptr) @@ -62,9 +69,9 @@ class OpenTxTheme: public Theme registerTheme(this); } - static OpenTxTheme * instance() + static EdgeTxTheme * instance() { - return static_cast(theme); + return theme; } inline const char * getName() const @@ -102,15 +109,18 @@ class OpenTxTheme: public Theme virtual void drawPageHeaderBackground(BitmapBuffer *dc, uint8_t icon, const char *title) const = 0; - virtual void drawCurrentMenuBackground(BitmapBuffer *dc) const = 0; + virtual void drawMenuIcon(BitmapBuffer *dc, uint8_t icon, bool checked) const = 0; - void drawCheckBox(BitmapBuffer * dc, bool checked, coord_t x, coord_t y, bool focus) const override; + virtual void drawCheckBox(BitmapBuffer * dc, bool checked, coord_t x, coord_t y, bool focus) const; - virtual void drawTopLeftBitmap(BitmapBuffer * dc) const = 0; + virtual void drawHeaderIcon(BitmapBuffer * dc, uint8_t icon) const = 0; virtual void drawUsbPluggedScreen(BitmapBuffer * dc) const; - + virtual const BitmapBuffer * getIconMask(uint8_t index) const = 0; + + virtual uint16_t* getDefaultColors() const = 0; + protected: const char * name; const ZoneOption * options; @@ -123,10 +133,10 @@ class OpenTxTheme: public Theme static const BitmapBuffer * shutdown; }; -OpenTxTheme * getTheme(const char * name); -void loadTheme(OpenTxTheme * theme); +EdgeTxTheme * getTheme(const char * name); +void loadTheme(EdgeTxTheme * theme); void loadTheme(); -std::list & getRegisteredThemes(); +std::list & getRegisteredThemes(); #endif // _COLORLCD_THEME_H_ diff --git a/radio/src/gui/colorlcd/theme_manager.cpp b/radio/src/gui/colorlcd/theme_manager.cpp index 9eabf7eee55..7e442fe67e0 100644 --- a/radio/src/gui/colorlcd/theme_manager.cpp +++ b/radio/src/gui/colorlcd/theme_manager.cpp @@ -235,7 +235,7 @@ void ThemeFile::applyColors() void ThemeFile::applyBackground() { - auto instance = OpenTxTheme::instance(); + auto instance = EdgeTxTheme::instance(); std::string backgroundImageFileName(getPath()); auto pos = backgroundImageFileName.rfind('/'); if (pos != std::string::npos) { @@ -264,7 +264,7 @@ void ThemeFile::applyTheme() { applyColors(); applyBackground(); - OpenTxTheme::instance()->update(false); + EdgeTxTheme::instance()->update(false); // Update views with new theme // Currently, on startup, active theme is loaded after ViewMain is created so ViewMain instance is defined @@ -465,19 +465,12 @@ class DefaultEdgeTxTheme : public ThemeFile setName("EdgeTX Default"); setAuthor("EdgeTX Team"); setInfo("Default EdgeTX Color Scheme"); - + // initializze the default color table - colorList.emplace_back(ColorEntry { COLOR_THEME_PRIMARY1_INDEX, RGB(0, 0, 0) }); - colorList.emplace_back(ColorEntry { COLOR_THEME_PRIMARY2_INDEX, RGB(255, 255, 255) }); - colorList.emplace_back(ColorEntry { COLOR_THEME_PRIMARY3_INDEX, RGB(12, 63, 102) }); - colorList.emplace_back(ColorEntry { COLOR_THEME_SECONDARY1_INDEX, RGB(18, 94, 153) }); - colorList.emplace_back(ColorEntry { COLOR_THEME_SECONDARY2_INDEX, RGB(182, 224, 242) }); - colorList.emplace_back(ColorEntry { COLOR_THEME_SECONDARY3_INDEX, RGB(228, 238, 242) }); - colorList.emplace_back(ColorEntry { COLOR_THEME_FOCUS_INDEX, RGB(20, 161, 229) }); - colorList.emplace_back(ColorEntry { COLOR_THEME_EDIT_INDEX, RGB(0, 153, 9) }); - colorList.emplace_back(ColorEntry { COLOR_THEME_ACTIVE_INDEX, RGB(255, 222, 0) }); - colorList.emplace_back(ColorEntry { COLOR_THEME_WARNING_INDEX, RGB(224, 0, 0) }); - colorList.emplace_back(ColorEntry { COLOR_THEME_DISABLED_INDEX, RGB(140, 140, 140) }); + extern EdgeTxTheme * defaultTheme; + uint16_t* defaultColors = defaultTheme->getDefaultColors(); + for (uint8_t i = COLOR_THEME_PRIMARY1_INDEX; i <= COLOR_THEME_DISABLED_INDEX; i += 1) + colorList.emplace_back(ColorEntry { (LcdColorIndex)i, defaultColors[i] }); } }; diff --git a/radio/src/gui/colorlcd/themes/480_default.cpp b/radio/src/gui/colorlcd/themes/480_default.cpp index 9ccf5e5423a..97d2d8a2b0b 100644 --- a/radio/src/gui/colorlcd/themes/480_default.cpp +++ b/radio/src/gui/colorlcd/themes/480_default.cpp @@ -46,11 +46,11 @@ const uint8_t mask_currentmenu_shadow[] = { #include "mask_currentmenu_shadow.lbm" }; -class Theme480: public OpenTxTheme +class Theme480: public EdgeTxTheme { public: Theme480(): - OpenTxTheme("EdgeTX", OPTIONS_THEME_DEFAULT) + EdgeTxTheme("EdgeTX", OPTIONS_THEME_DEFAULT) { loadColors(); } @@ -58,90 +58,40 @@ class Theme480: public OpenTxTheme void loadColors() const { TRACE("Load EdgeTX theme colors"); - - lcdColorTable[DEFAULT_COLOR_INDEX] = RGB(18, 94, 153); - - lcdColorTable[COLOR_THEME_PRIMARY1_INDEX] = RGB(0, 0, 0); - lcdColorTable[COLOR_THEME_PRIMARY2_INDEX] = RGB(255, 255, 255); - lcdColorTable[COLOR_THEME_PRIMARY3_INDEX] = RGB(12, 63, 102); - lcdColorTable[COLOR_THEME_SECONDARY1_INDEX] = RGB(18, 94, 153); - lcdColorTable[COLOR_THEME_SECONDARY2_INDEX] = RGB(182, 224, 242); - lcdColorTable[COLOR_THEME_SECONDARY3_INDEX] = RGB(228, 238, 242); - lcdColorTable[COLOR_THEME_FOCUS_INDEX] = RGB(20, 161, 229); - lcdColorTable[COLOR_THEME_EDIT_INDEX] = RGB(0, 153, 9); - lcdColorTable[COLOR_THEME_ACTIVE_INDEX] = RGB(255, 222, 0); - lcdColorTable[COLOR_THEME_WARNING_INDEX] = RGB(224, 0, 0); - lcdColorTable[COLOR_THEME_DISABLED_INDEX] = RGB(140, 140, 140); - lcdColorTable[CUSTOM_COLOR_INDEX] = RGB(170, 85, 0); - } - - void createMenuIcon(uint8_t index, const uint8_t * lbm, bool reload) const - { - auto mask = BitmapBuffer::load8bitMaskLZ4(lbm); - - if (mask) { - iconMask[index] = mask; - menuIconNormal[index] = new BitmapBuffer(BMP_RGB565, mask->width(), mask->height()); - menuIconSelected[index] = new BitmapBuffer(BMP_RGB565, mask->width(), mask->height()); - } + memcpy(lcdColorTable, defaultColors, sizeof(defaultColors)); } void createIcons() const { - if (!iconsLoaded) { - iconsLoaded = true; + if (iconsLoaded) + return; - for (int id = ICON_OPENTX; id != MENUS_ICONS_COUNT; id++) { - createMenuIcon(id, getBuiltinIcon((MenuIcons)id), true); - } + iconsLoaded = true; - // Get mask with max size - unique_ptr shadow(BitmapBuffer::load8bitMaskLZ4(mask_currentmenu_shadow)); - currentMenuBackground = new BitmapBuffer(BMP_RGB565, shadow->width(), shadow->height()); + for (int id = ICON_EDGETX; id != MENUS_ICONS_COUNT; id++) { + iconMask[id] = BitmapBuffer::load8bitMaskLZ4(getBuiltinIcon((MenuIcons)id)); + } - // Get mask with max size - unique_ptr topleft(BitmapBuffer::load8bitMaskLZ4(mask_topleft)); - topleftBitmap = new BitmapBuffer(BMP_RGB565, topleft->width(), topleft->height()); + // Get mask with max size + unique_ptr shadow(BitmapBuffer::load8bitMaskLZ4(mask_currentmenu_shadow)); + currentMenuBackground = new BitmapBuffer(BMP_RGB565, shadow->width(), shadow->height()); - loadBuiltinBitmaps(); - } - } + topleftBitmap = BitmapBuffer::load8bitMaskLZ4(mask_topleft); - void loadMenuIcon(uint8_t index, const uint8_t * lbm, bool reload) const - { - if (iconMask[index]) { - if (menuIconNormal[index]) { - menuIconNormal[index]->clear(COLOR_THEME_SECONDARY1); - menuIconNormal[index]->drawMask(0, 0, iconMask[index], COLOR_THEME_PRIMARY2); - } - - if (menuIconSelected[index]) { - menuIconSelected[index]->clear(COLOR_THEME_FOCUS); - menuIconSelected[index]->drawMask(0, 0, iconMask[index], COLOR_THEME_PRIMARY2); - } - } + loadBuiltinBitmaps(); } void loadIcons() const { - for (int id = ICON_OPENTX; id != MENUS_ICONS_COUNT; id++) { - loadMenuIcon(id, getBuiltinIcon((MenuIcons)id), true); - } - if (currentMenuBackground) { - currentMenuBackground->drawSolidFilledRect( - 0, 0, currentMenuBackground->width(), MENU_HEADER_HEIGHT, + 0, 0, currentMenuBackground->width(), currentMenuBackground->height(), COLOR_THEME_SECONDARY1); currentMenuBackground->drawSolidFilledRect( 0, MENU_HEADER_HEIGHT, currentMenuBackground->width(), MENU_TITLE_TOP - MENU_HEADER_HEIGHT, COLOR_THEME_SECONDARY3); - currentMenuBackground->drawSolidFilledRect( - 0, MENU_TITLE_TOP, currentMenuBackground->width(), - currentMenuBackground->height() - MENU_TITLE_TOP, COLOR_THEME_SECONDARY1); - unique_ptr background(BitmapBuffer::load8bitMaskLZ4(mask_currentmenu_bg)); currentMenuBackground->drawMask(0, 0, background.get(), COLOR_THEME_FOCUS); @@ -151,13 +101,6 @@ class Theme480: public OpenTxTheme unique_ptr dot(BitmapBuffer::load8bitMaskLZ4(mask_currentmenu_dot)); currentMenuBackground->drawMask(10, 39, dot.get(), COLOR_THEME_PRIMARY2); } - - if (topleftBitmap) { - topleftBitmap->clear(COLOR_THEME_SECONDARY1); - - unique_ptr topleft(BitmapBuffer::load8bitMaskLZ4(mask_topleft)); - topleftBitmap->drawMask(0, 0, topleft.get(), COLOR_THEME_FOCUS); - } } void setBackgroundImageFileName(const char *fileName) override @@ -165,7 +108,7 @@ class Theme480: public OpenTxTheme // ensure you delete old bitmap if (backgroundBitmap != nullptr) delete backgroundBitmap; - OpenTxTheme::setBackgroundImageFileName(fileName); // set the filename + EdgeTxTheme::setBackgroundImageFileName(fileName); // set the filename backgroundBitmap = BitmapBuffer::loadBitmap(backgroundImageFileName); } @@ -173,7 +116,7 @@ class Theme480: public OpenTxTheme { loadColors(); ThemePersistance::instance()->loadDefaultTheme(); - OpenTxTheme::load(); + EdgeTxTheme::load(); if (!backgroundBitmap) { backgroundBitmap = BitmapBuffer::loadBitmap(getFilePath("background.png")); } @@ -189,38 +132,28 @@ class Theme480: public OpenTxTheme void drawBackground(BitmapBuffer * dc) const override { - if (backgroundBitmap) { - dc->clear(COLOR_THEME_SECONDARY3); + dc->clear(COLOR_THEME_SECONDARY3); + if (backgroundBitmap) dc->drawBitmap(0, 0, backgroundBitmap); - } else { - dc->drawSolidFilledRect(0, 0, LCD_W, LCD_H, COLOR_THEME_SECONDARY3); - } } - void drawTopLeftBitmap(BitmapBuffer * dc) const override + void drawHeaderIcon(BitmapBuffer * dc, uint8_t icon) const override { - if (topleftBitmap) { - dc->drawBitmap(0, 0, topleftBitmap); - dc->drawBitmap(4, 10, menuIconSelected[ICON_OPENTX]); - } + dc->drawSolidFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, COLOR_THEME_SECONDARY1); + + if (topleftBitmap) + dc->drawMask(0, 0, topleftBitmap, COLOR_THEME_FOCUS); + + if (icon == ICON_EDGETX) + dc->drawMask(4, 10, iconMask[icon], COLOR_THEME_PRIMARY2); + else + dc->drawMask(5, 7, iconMask[icon], COLOR_THEME_PRIMARY2); } void drawPageHeaderBackground(BitmapBuffer *dc, uint8_t icon, const char *title) const override { - if (topleftBitmap) { - dc->drawBitmap(0, 0, topleftBitmap); - uint16_t width = topleftBitmap->width(); - dc->drawSolidFilledRect(width, 0, LCD_W - width, MENU_HEADER_HEIGHT, COLOR_THEME_SECONDARY1); - } - else { - dc->drawSolidFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, COLOR_THEME_SECONDARY1); - } - - if (icon == ICON_OPENTX) - dc->drawBitmap(4, 10, menuIconSelected[ICON_OPENTX]); - else - dc->drawBitmap(5, 7, menuIconSelected[icon]); + drawHeaderIcon(dc, icon); dc->drawSolidFilledRect(0, MENU_HEADER_HEIGHT, LCD_W, MENU_TITLE_TOP - MENU_HEADER_HEIGHT, @@ -240,15 +173,11 @@ class Theme480: public OpenTxTheme return iconMask[index]; } - const BitmapBuffer * getIcon(uint8_t index, IconState state) const override + void drawMenuIcon(BitmapBuffer *dc, uint8_t icon, bool checked) const override { - return state == STATE_DEFAULT ? menuIconNormal[index] : menuIconSelected[index]; - } - - void drawCurrentMenuBackground(BitmapBuffer *dc) const override - { - dc->drawBitmap(0, 0, - currentMenuBackground); + if (checked) + dc->drawBitmap(0, 0, currentMenuBackground); + dc->drawMask(2, 7, iconMask[icon], COLOR_THEME_PRIMARY2); } void drawMenuDatetime(BitmapBuffer * dc) const @@ -268,24 +197,15 @@ class Theme480: public OpenTxTheme dc->drawText(DATETIME_MIDDLE, DATETIME_LINE2, str, FONT(XS)|COLOR_THEME_PRIMARY2|CENTERED); } - void drawProgressBar(BitmapBuffer *dc, coord_t x, coord_t y, coord_t w, - coord_t h, int value, int total) const override - { - dc->drawSolidRect(x, y, w, h, 1, COLOR_THEME_SECONDARY1); - if (value > 0) { - int width = (w * value) / total; - dc->drawSolidFilledRect(x + 2, y + 2, width - 4, h - 4, COLOR_THEME_FOCUS); - } - } + uint16_t* getDefaultColors() const override { return defaultColors; } protected: static bool iconsLoaded; static const BitmapBuffer * backgroundBitmap; static BitmapBuffer * topleftBitmap; - static BitmapBuffer * menuIconNormal[MENUS_ICONS_COUNT]; - static BitmapBuffer * menuIconSelected[MENUS_ICONS_COUNT]; static BitmapBuffer * iconMask[MENUS_ICONS_COUNT]; static BitmapBuffer * currentMenuBackground; + static uint16_t defaultColors[LCD_COLOR_COUNT]; }; bool Theme480::iconsLoaded = false; @@ -293,13 +213,27 @@ bool Theme480::iconsLoaded = false; const BitmapBuffer * Theme480::backgroundBitmap = nullptr; BitmapBuffer * Theme480::topleftBitmap = nullptr; BitmapBuffer * Theme480::iconMask[MENUS_ICONS_COUNT] = { nullptr }; -BitmapBuffer * Theme480::menuIconNormal[MENUS_ICONS_COUNT] = { nullptr }; -BitmapBuffer * Theme480::menuIconSelected[MENUS_ICONS_COUNT] = { nullptr }; BitmapBuffer * Theme480::currentMenuBackground = nullptr; -Theme480 Theme480; +uint16_t Theme480::defaultColors[LCD_COLOR_COUNT] = { + RGB(18, 94, 153), // DEFAULT + RGB(0, 0, 0), // PRIMARY1 + RGB(255, 255, 255), // PRIMARY2 + RGB(12, 63, 102), // PRIMARY3 + RGB(18, 94, 153), // SECONDARY1 + RGB(182, 224, 242), // SECONDARY2 + RGB(228, 238, 242), // SECONDARY3 + RGB(20, 161, 229), // FOCUS + RGB(0, 153, 9), // EDIT + RGB(255, 222, 0), // ACTIVE + RGB(224, 0, 0), // WARNING + RGB(140, 140, 140), // DISABLED + RGB(170, 85, 0) // CUSTOM +}; + +Theme480 theme480; #if LCD_W == 480 || LCD_H == 480 -OpenTxTheme * defaultTheme = &Theme480; -Theme * theme = &Theme480; +EdgeTxTheme * defaultTheme = &theme480; +EdgeTxTheme * theme = &theme480; #endif diff --git a/radio/src/gui/colorlcd/themes/etx_lv_theme.cpp b/radio/src/gui/colorlcd/themes/etx_lv_theme.cpp index 2c71fc957ff..6807b775cea 100644 --- a/radio/src/gui/colorlcd/themes/etx_lv_theme.cpp +++ b/radio/src/gui/colorlcd/themes/etx_lv_theme.cpp @@ -1,6 +1,22 @@ -/** - * @file lv_theme.c +/* + * 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. */ /********************* @@ -10,707 +26,357 @@ #include "../colors.h" #include "font.h" -#include "libopenui_config.h" -#include "widgets/field_edit.h" -#include "widgets/edgetx_table.h" -#include "widgets/window_base.h" - -#include "lvgl_widgets/input_mix_line.h" -#include "lvgl_widgets/input_mix_group.h" - extern lv_color_t makeLvColor(uint32_t colorFlags); /********************* * DEFINES *********************/ -#define MODE_DARK 1 -#define RADIUS_DEFAULT (disp_size == DISP_LARGE ? lv_disp_dpx(theme.disp, 12) : lv_disp_dpx(theme.disp, 8)) - -/*SCREEN*/ -#define LIGHT_COLOR_SCR makeLvColor(COLOR_THEME_SECONDARY3) -#define LIGHT_COLOR_CARD makeLvColor(COLOR_THEME_PRIMARY2) -#define LIGHT_COLOR_TEXT makeLvColor(COLOR_THEME_PRIMARY1) -#define LIGHT_COLOR_GREY makeLvColor(COLOR_THEME_SECONDARY2) -#define DARK_COLOR_SCR lv_color_hex(0x15171A) -#define DARK_COLOR_CARD lv_color_hex(0x282b30) -#define DARK_COLOR_TEXT lv_palette_lighten(LV_PALETTE_GREY, 5) -#define DARK_COLOR_GREY lv_color_hex(0x2f3237) - -#define TRANSITION_TIME 80 -#define BORDER_WIDTH lv_disp_dpx(theme.disp, 2) -#define OUTLINE_WIDTH lv_disp_dpx(theme.disp, 3) - -#define PAD_DEF (disp_size == DISP_LARGE ? lv_disp_dpx(theme.disp, 24) : disp_size == DISP_MEDIUM ? lv_disp_dpx(theme.disp, 20) : lv_disp_dpx(theme.disp, 16)) -#define PAD_SMALL (disp_size == DISP_LARGE ? lv_disp_dpx(theme.disp, 14) : disp_size == DISP_MEDIUM ? lv_disp_dpx(theme.disp, 12) : lv_disp_dpx(theme.disp, 10)) -#define PAD_TINY (disp_size == DISP_LARGE ? lv_disp_dpx(theme.disp, 8) : disp_size == DISP_MEDIUM ? lv_disp_dpx(theme.disp, 6) : lv_disp_dpx(theme.disp, 2)) +#define BORDER_WIDTH lv_disp_dpx(theme.disp, 2) + +#if LCD_W > LCD_H + #define PAD_SMALL (lv_disp_dpx(theme.disp, 12)) + #define PAD_TINY (lv_disp_dpx(theme.disp, 4)) +#else + #define PAD_SMALL (lv_disp_dpx(theme.disp, 10)) + #define PAD_TINY (lv_disp_dpx(theme.disp, 2)) +#endif /********************** * TYPEDEFS **********************/ typedef struct { - lv_style_t scr; - lv_style_t scrollbar; - lv_style_t scrollbar_scrolled; - lv_style_t card; - lv_style_t btn; - lv_style_t line_btn; - lv_style_t field; - - /*Utility*/ - lv_style_t bg_color_primary; - lv_style_t bg_color_primary_muted; - lv_style_t bg_color_secondary; - lv_style_t bg_color_secondary_muted; - lv_style_t bg_color_grey; - lv_style_t bg_color_white; - lv_style_t bg_color_active; - lv_style_t bg_color_focus; - lv_style_t bg_color_edit; - lv_style_t pressed; - lv_style_t disabled; - lv_style_t focus_border; - lv_style_t pad_zero; - lv_style_t pad_tiny; - lv_style_t pad_small; - lv_style_t pad_normal; - lv_style_t pad_gap; - lv_style_t line_space_large; - lv_style_t text_align_center; - lv_style_t outline_primary; - lv_style_t outline_secondary; - lv_style_t circle; - lv_style_t rounded; - lv_style_t no_radius; - lv_style_t clip_corner; -#if LV_THEME_DEFAULT_GROW - lv_style_t grow; -#endif - lv_style_t transition_delayed; - lv_style_t transition_normal; - lv_style_t anim; - lv_style_t anim_fast; - - /*Parts*/ - lv_style_t knob; - lv_style_t indic; - -#if LV_USE_ARC - lv_style_t arc_indic; - lv_style_t arc_indic_primary; -#endif - -#if LV_USE_CHART - lv_style_t chart_series, chart_indic, chart_ticks, chart_bg; -#endif - -#if LV_USE_DROPDOWN - lv_style_t dropdown_list; -#endif - -#if LV_USE_CHECKBOX - lv_style_t cb_marker, cb_marker_checked; -#endif - -#if LV_USE_SWITCH - lv_style_t switch_knob; -#endif - -#if LV_USE_LINE - lv_style_t line; -#endif - -#if LV_USE_TABLE - lv_style_t table_cell; -#endif - -#if LV_USE_METER - lv_style_t meter_marker, meter_indic; -#endif - -#if LV_USE_TEXTAREA - lv_style_t ta_cursor, ta_placeholder; - lv_style_t field_cursor, edit_cursor; -#endif - -#if LV_USE_CALENDAR - lv_style_t calendar_btnm_bg, calendar_btnm_day, calendar_header; -#endif - -#if LV_USE_COLORWHEEL - lv_style_t colorwheel_main; -#endif - -#if LV_USE_MENU - lv_style_t menu_bg, menu_cont, menu_sidebar_cont, menu_main_cont, menu_page, menu_header_cont, menu_header_btn, - menu_section, menu_pressed, menu_separator; -#endif - -#if LV_USE_MSGBOX - lv_style_t msgbox_bg, msgbox_btn_bg, msgbox_backdrop_bg; -#endif - -#if LV_USE_KEYBOARD - lv_style_t keyboard_btn_bg; -#endif - -#if LV_USE_LIST - lv_style_t list_bg, list_btn, list_item_grow, list_label; -#endif + lv_style_t keyboard; + lv_style_t scrollbar; + lv_style_t scrollbar_scrolled; + lv_style_t btn; + lv_style_t line_btn; + lv_style_t field; + + /*Utility*/ + lv_style_t bg_color_grey; + lv_style_t bg_color_white; + lv_style_t bg_color_active; + lv_style_t bg_color_focus; + lv_style_t bg_color_focus_light; + lv_style_t bg_color_edit; + lv_style_t bg_color_transparent; + lv_style_t bg_color_mix_active; + lv_style_t pressed; + lv_style_t disabled; + lv_style_t focussed; + lv_style_t pad_zero; + lv_style_t pad_tiny; + lv_style_t pad_small; + lv_style_t circle; + lv_style_t rounded; + lv_style_t border; + lv_style_t anim_fast; + lv_style_t font_std; + lv_style_t font_bold; + lv_style_t text_align_right; + + // Slider parts + lv_style_t slider_main; + lv_style_t slider_knob; + + // Choice + lv_style_t choice_main; + + // Checkbox + lv_style_t switch_knob; + + // Table + lv_style_t table_cell; + + // Edit field + lv_style_t field_cursor, edit_cursor; + + // Keyboard + lv_style_t keyboard_btn_bg; + + // Model popup + lv_style_t modal_overlay; + lv_style_t modal_content; + lv_style_t modal_title; + + // Progress bar + lv_style_t progress_main; + lv_style_t progress_indicator; -#if LV_USE_TABVIEW - lv_style_t tab_bg_focus, tab_btn; -#endif -#if LV_USE_LED - lv_style_t led; -#endif } my_theme_styles_t; -typedef struct { - lv_theme_t base; - uint8_t light : 1; -} my_theme_t; - -typedef enum { - DISP_SMALL = 3, - DISP_MEDIUM = 2, - DISP_LARGE = 1, -} disp_size_t; - -/********************** - * STATIC PROTOTYPES - **********************/ -static void theme_apply(lv_theme_t * th, lv_obj_t * obj); -static void style_init_reset(lv_style_t * style); - /********************** * STATIC VARIABLES **********************/ static my_theme_styles_t styles; static lv_theme_t theme; -static disp_size_t disp_size; -static lv_color_t color_scr; -static lv_color_t color_text; -static lv_color_t color_card; -static lv_color_t color_grey; static bool inited = false; - -/********************** - * MACROS - **********************/ - /********************** * STATIC FUNCTIONS **********************/ - static lv_color_t dark_color_filter_cb(const lv_color_filter_dsc_t * f, lv_color_t c, lv_opa_t opa) { - LV_UNUSED(f); - return lv_color_darken(c, opa); + LV_UNUSED(f); + return lv_color_darken(c, opa); } static lv_color_t grey_filter_cb(const lv_color_filter_dsc_t * f, lv_color_t color, lv_opa_t opa) { - LV_UNUSED(f); - if(theme.flags & MODE_DARK) return lv_color_mix(lv_palette_darken(LV_PALETTE_GREY, 2), color, opa); - else return lv_color_mix(lv_palette_lighten(LV_PALETTE_GREY, 2), color, opa); + LV_UNUSED(f); + return lv_color_mix(lv_palette_lighten(LV_PALETTE_GREY, 2), color, opa); } static void style_init(void) { - static const lv_style_prop_t trans_props[] = { - LV_STYLE_BG_OPA, LV_STYLE_BG_COLOR, - LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_TRANSFORM_HEIGHT, - LV_STYLE_TRANSLATE_Y, LV_STYLE_TRANSLATE_X, - LV_STYLE_TRANSFORM_ZOOM, LV_STYLE_TRANSFORM_ANGLE, - LV_STYLE_COLOR_FILTER_OPA, LV_STYLE_COLOR_FILTER_DSC, - (const lv_style_prop_t)0 - }; - - color_scr = theme.flags & MODE_DARK ? DARK_COLOR_SCR : LIGHT_COLOR_SCR; - color_text = theme.flags & MODE_DARK ? DARK_COLOR_TEXT : LIGHT_COLOR_TEXT; - color_card = theme.flags & MODE_DARK ? DARK_COLOR_CARD : LIGHT_COLOR_CARD; - color_grey = theme.flags & MODE_DARK ? DARK_COLOR_GREY : LIGHT_COLOR_GREY; - - static lv_style_transition_dsc_t trans_delayed; - lv_style_transition_dsc_init(&trans_delayed, trans_props, lv_anim_path_linear, TRANSITION_TIME, 70, NULL); - - static lv_style_transition_dsc_t trans_normal; - lv_style_transition_dsc_init(&trans_normal, trans_props, lv_anim_path_linear, TRANSITION_TIME, 0, NULL); - - style_init_reset(&styles.transition_delayed); - lv_style_set_transition(&styles.transition_delayed, &trans_delayed); /*Go back to default state with delay*/ - - style_init_reset(&styles.transition_normal); - lv_style_set_transition(&styles.transition_normal, &trans_normal); /*Go back to default state with delay*/ - - style_init_reset(&styles.scrollbar); - lv_style_set_bg_color(&styles.scrollbar, (theme.flags & MODE_DARK) ? lv_palette_darken(LV_PALETTE_GREY, - 2) : lv_palette_main(LV_PALETTE_GREY)); - lv_style_set_radius(&styles.scrollbar, LV_RADIUS_CIRCLE); + if (!inited) { + inited = true; + + // Scrollbar + lv_style_init(&styles.scrollbar); lv_style_set_pad_all(&styles.scrollbar, lv_disp_dpx(theme.disp, 7)); lv_style_set_width(&styles.scrollbar, lv_disp_dpx(theme.disp, 5)); lv_style_set_bg_opa(&styles.scrollbar, LV_OPA_40); - lv_style_set_transition(&styles.scrollbar, &trans_normal); - style_init_reset(&styles.scrollbar_scrolled); + lv_style_init(&styles.scrollbar_scrolled); lv_style_set_bg_opa(&styles.scrollbar_scrolled, LV_OPA_COVER); - style_init_reset(&styles.scr); - lv_style_set_bg_opa(&styles.scr, LV_OPA_COVER); - lv_style_set_bg_color(&styles.scr, color_scr); - lv_style_set_text_color(&styles.scr, color_text); - lv_style_set_pad_row(&styles.scr, PAD_SMALL); - lv_style_set_pad_column(&styles.scr, PAD_SMALL); - - style_init_reset(&styles.card); - lv_style_set_radius(&styles.card, RADIUS_DEFAULT); - lv_style_set_bg_opa(&styles.card, LV_OPA_COVER); - lv_style_set_bg_color(&styles.card, color_card); - lv_style_set_border_color(&styles.card, color_grey); - lv_style_set_border_width(&styles.card, BORDER_WIDTH); - lv_style_set_border_post(&styles.card, true); - lv_style_set_text_color(&styles.card, color_text); - lv_style_set_pad_all(&styles.card, PAD_DEF); - lv_style_set_pad_row(&styles.card, PAD_SMALL); - lv_style_set_pad_column(&styles.card, PAD_SMALL); - lv_style_set_line_color(&styles.card, lv_palette_main(LV_PALETTE_GREY)); - lv_style_set_line_width(&styles.card, lv_disp_dpx(theme.disp, 1)); - - style_init_reset(&styles.outline_primary); - lv_style_set_outline_color(&styles.outline_primary, theme.color_primary); - lv_style_set_outline_width(&styles.outline_primary, OUTLINE_WIDTH); - lv_style_set_outline_pad(&styles.outline_primary, OUTLINE_WIDTH); - lv_style_set_outline_opa(&styles.outline_primary, LV_OPA_50); - - style_init_reset(&styles.outline_secondary); - lv_style_set_outline_color(&styles.outline_secondary, theme.color_secondary); - lv_style_set_outline_width(&styles.outline_secondary, OUTLINE_WIDTH); - lv_style_set_outline_opa(&styles.outline_secondary, LV_OPA_50); - - style_init_reset(&styles.btn); - lv_style_set_radius( - &styles.btn, (disp_size == DISP_LARGE ? lv_disp_dpx(theme.disp, 16) - : disp_size == DISP_MEDIUM ? lv_disp_dpx(theme.disp, 12) - : lv_disp_dpx(theme.disp, 8))); - - lv_style_set_bg_opa(&styles.btn, LV_OPA_COVER); - lv_style_set_bg_color(&styles.btn, makeLvColor(COLOR_THEME_PRIMARY2)); + // Keyboard + lv_style_init(&styles.keyboard); + lv_style_set_bg_opa(&styles.keyboard, LV_OPA_COVER); + lv_style_set_pad_row(&styles.keyboard, PAD_SMALL); + lv_style_set_pad_column(&styles.keyboard, PAD_SMALL); - lv_style_set_border_opa(&styles.btn, LV_OPA_0); - lv_style_set_border_width(&styles.btn, BORDER_WIDTH); + // Border + lv_style_init(&styles.border); + lv_style_set_border_opa(&styles.border, LV_OPA_100); + lv_style_set_border_width(&styles.border, BORDER_WIDTH); - lv_style_set_text_color(&styles.btn, makeLvColor(COLOR_THEME_SECONDARY1)); + // Button + lv_style_init(&styles.btn); + lv_style_set_bg_opa(&styles.btn, LV_OPA_COVER); lv_style_set_pad_hor(&styles.btn, PAD_SMALL); lv_style_set_pad_ver(&styles.btn, PAD_SMALL); lv_style_set_pad_column(&styles.btn, lv_disp_dpx(theme.disp, 5)); lv_style_set_pad_row(&styles.btn, lv_disp_dpx(theme.disp, 5)); - style_init_reset(&styles.line_btn); - lv_style_set_radius( - &styles.line_btn, - (disp_size == DISP_LARGE ? lv_disp_dpx(theme.disp, 16) - : disp_size == DISP_MEDIUM ? lv_disp_dpx(theme.disp, 12) - : lv_disp_dpx(theme.disp, 8))); - + lv_style_init(&styles.line_btn); lv_style_set_bg_opa(&styles.line_btn, LV_OPA_COVER); - lv_style_set_bg_color(&styles.line_btn, makeLvColor(COLOR_THEME_PRIMARY2)); - - lv_style_set_border_opa(&styles.line_btn, LV_OPA_COVER); - lv_style_set_border_width(&styles.line_btn, BORDER_WIDTH); - lv_style_set_border_color(&styles.line_btn, makeLvColor(COLOR_THEME_SECONDARY2)); - style_init_reset(&styles.field); - - lv_style_set_border_width(&styles.field, lv_dpx(1)); - lv_style_set_border_color(&styles.field, makeLvColor(COLOR_THEME_SECONDARY2)); - - lv_style_set_bg_color(&styles.field, makeLvColor(COLOR_THEME_PRIMARY2)); + // Edit box + lv_style_init(&styles.field); lv_style_set_bg_opa(&styles.field, LV_OPA_COVER); + lv_style_set_pad_top(&styles.field, 4); + lv_style_set_pad_bottom(&styles.field, 5); + lv_style_set_pad_left(&styles.field, 4); + lv_style_set_pad_right(&styles.field, 4); - lv_style_set_text_color(&styles.field, makeLvColor(COLOR_THEME_SECONDARY1)); - lv_style_set_pad_left(&styles.field, lv_dpx(3)); - lv_style_set_pad_top(&styles.field, lv_dpx(3)); - + // States (pressed, disabled, etc) static lv_color_filter_dsc_t dark_filter; lv_color_filter_dsc_init(&dark_filter, dark_color_filter_cb); static lv_color_filter_dsc_t grey_filter; lv_color_filter_dsc_init(&grey_filter, grey_filter_cb); - style_init_reset(&styles.pressed); + lv_style_init(&styles.pressed); lv_style_set_color_filter_dsc(&styles.pressed, &dark_filter); lv_style_set_color_filter_opa(&styles.pressed, 35); - style_init_reset(&styles.disabled); + lv_style_init(&styles.disabled); lv_style_set_color_filter_dsc(&styles.disabled, &grey_filter); lv_style_set_color_filter_opa(&styles.disabled, LV_OPA_50); - style_init_reset(&styles.focus_border); - lv_style_set_border_color(&styles.focus_border, makeLvColor(COLOR_THEME_FOCUS)); - lv_style_set_border_opa(&styles.focus_border, LV_OPA_100); - lv_style_set_border_width(&styles.focus_border, BORDER_WIDTH); - - style_init_reset(&styles.clip_corner); - lv_style_set_clip_corner(&styles.clip_corner, true); - lv_style_set_border_post(&styles.clip_corner, true); - - style_init_reset(&styles.pad_normal); - lv_style_set_pad_all(&styles.pad_normal, PAD_DEF); - lv_style_set_pad_row(&styles.pad_normal, PAD_DEF); - lv_style_set_pad_column(&styles.pad_normal, PAD_DEF); - - style_init_reset(&styles.pad_small); + lv_style_init(&styles.focussed); + lv_style_set_border_opa(&styles.focussed, LV_OPA_100); + lv_style_set_border_width(&styles.focussed, BORDER_WIDTH); + + // Padding + lv_style_init(&styles.pad_small); lv_style_set_pad_all(&styles.pad_small, PAD_SMALL); lv_style_set_pad_gap(&styles.pad_small, PAD_SMALL); + lv_style_set_pad_column(&styles.pad_small, PAD_SMALL); - style_init_reset(&styles.pad_gap); - lv_style_set_pad_row(&styles.pad_gap, lv_disp_dpx(theme.disp, 10)); - lv_style_set_pad_column(&styles.pad_gap, lv_disp_dpx(theme.disp, 10)); - - style_init_reset(&styles.line_space_large); - lv_style_set_text_line_space(&styles.line_space_large, lv_disp_dpx(theme.disp, 20)); - - style_init_reset(&styles.text_align_center); - lv_style_set_text_align(&styles.text_align_center, LV_TEXT_ALIGN_CENTER); - - style_init_reset(&styles.pad_zero); + lv_style_init(&styles.pad_zero); lv_style_set_pad_all(&styles.pad_zero, 0); lv_style_set_pad_row(&styles.pad_zero, 0); lv_style_set_pad_column(&styles.pad_zero, 0); - style_init_reset(&styles.pad_tiny); + lv_style_init(&styles.pad_tiny); lv_style_set_pad_all(&styles.pad_tiny, PAD_TINY); lv_style_set_pad_row(&styles.pad_tiny, PAD_TINY); lv_style_set_pad_column(&styles.pad_tiny, PAD_TINY); - style_init_reset(&styles.bg_color_primary); - lv_style_set_bg_color(&styles.bg_color_primary, theme.color_primary); - lv_style_set_text_color(&styles.bg_color_primary, lv_color_white()); - lv_style_set_bg_opa(&styles.bg_color_primary, LV_OPA_COVER); - - style_init_reset(&styles.bg_color_primary_muted); - lv_style_set_bg_color(&styles.bg_color_primary_muted, theme.color_primary); - lv_style_set_text_color(&styles.bg_color_primary_muted, theme.color_primary); - lv_style_set_bg_opa(&styles.bg_color_primary_muted, LV_OPA_20); - - style_init_reset(&styles.bg_color_secondary); - lv_style_set_bg_color(&styles.bg_color_secondary, theme.color_secondary); - lv_style_set_text_color(&styles.bg_color_secondary, lv_color_white()); - lv_style_set_bg_opa(&styles.bg_color_secondary, LV_OPA_COVER); - - style_init_reset(&styles.bg_color_secondary_muted); - lv_style_set_bg_color(&styles.bg_color_secondary_muted, theme.color_secondary); - lv_style_set_text_color(&styles.bg_color_secondary_muted, theme.color_secondary); - lv_style_set_bg_opa(&styles.bg_color_secondary_muted, LV_OPA_20); - - style_init_reset(&styles.bg_color_grey); - lv_style_set_bg_color(&styles.bg_color_grey, color_grey); + // Grey background + lv_style_init(&styles.bg_color_grey); lv_style_set_bg_opa(&styles.bg_color_grey, LV_OPA_COVER); - lv_style_set_text_color(&styles.bg_color_grey, color_text); - style_init_reset(&styles.bg_color_white); - lv_style_set_bg_color(&styles.bg_color_white, makeLvColor(COLOR_THEME_PRIMARY2)); + // White background + lv_style_init(&styles.bg_color_white); lv_style_set_bg_opa(&styles.bg_color_white, LV_OPA_COVER); - lv_style_set_text_color(&styles.bg_color_white, makeLvColor(COLOR_THEME_PRIMARY1)); - style_init_reset(&styles.bg_color_active); - lv_style_set_bg_color(&styles.bg_color_active, makeLvColor(COLOR_THEME_ACTIVE)); + // Active color background + lv_style_init(&styles.bg_color_active); lv_style_set_bg_opa(&styles.bg_color_active, LV_OPA_COVER); - lv_style_set_text_color(&styles.bg_color_active, makeLvColor(COLOR_THEME_PRIMARY1)); - style_init_reset(&styles.bg_color_focus); - lv_style_set_bg_color(&styles.bg_color_focus, makeLvColor(COLOR_THEME_FOCUS)); + // Active color mix line background + lv_style_init(&styles.bg_color_mix_active); + lv_style_set_bg_opa(&styles.bg_color_mix_active, LV_OPA_COVER); + + // Focus color background + lv_style_init(&styles.bg_color_focus); lv_style_set_bg_opa(&styles.bg_color_focus, LV_OPA_COVER); - lv_style_set_text_color(&styles.bg_color_focus, makeLvColor(COLOR_THEME_PRIMARY2)); + lv_style_init(&styles.bg_color_focus_light); + lv_style_set_bg_opa(&styles.bg_color_focus_light, LV_OPA_20); - style_init_reset(&styles.bg_color_edit); - lv_style_set_bg_color(&styles.bg_color_edit, makeLvColor(COLOR_THEME_EDIT)); + // Edit color background + lv_style_init(&styles.bg_color_edit); lv_style_set_bg_opa(&styles.bg_color_edit, LV_OPA_COVER); - lv_style_set_text_color(&styles.bg_color_edit, makeLvColor(COLOR_THEME_PRIMARY2)); - style_init_reset(&styles.circle); + // Transparent color background + lv_style_init(&styles.bg_color_transparent); + lv_style_set_bg_opa(&styles.bg_color_transparent, LV_OPA_TRANSP); + + // Checkbox and slider knob rounding + lv_style_init(&styles.circle); lv_style_set_radius(&styles.circle, LV_RADIUS_CIRCLE); - style_init_reset(&styles.rounded); - lv_style_set_radius( - &styles.rounded, - (disp_size == DISP_LARGE ? lv_disp_dpx(theme.disp, 16) - : disp_size == DISP_MEDIUM ? lv_disp_dpx(theme.disp, 12) - : lv_disp_dpx(theme.disp, 8))); + // Corner rounding (button, edit box, etc) + lv_style_init(&styles.rounded); + lv_style_set_radius(&styles.rounded, 6); + + // Slider + lv_style_init(&styles.slider_main); + lv_style_set_bg_opa(&styles.slider_main, LV_OPA_100); + lv_style_set_pad_all(&styles.slider_main, 6); + lv_style_init(&styles.slider_knob); + lv_style_set_bg_opa(&styles.slider_knob, LV_OPA_COVER); + lv_style_set_border_width(&styles.slider_knob, 1); + lv_style_set_pad_all(&styles.slider_knob, lv_disp_dpx(theme.disp, 6)); + + // Choice + lv_style_init(&styles.choice_main); + lv_style_set_pad_top(&styles.choice_main, 3); + lv_style_set_pad_bottom(&styles.choice_main, 4); + lv_style_set_pad_right(&styles.choice_main, 5); + lv_style_set_bg_opa(&styles.choice_main, LV_OPA_100); + + // Animation + lv_style_init(&styles.anim_fast); + lv_style_set_anim_time(&styles.anim_fast, 120); - style_init_reset(&styles.no_radius); - lv_style_set_radius(&styles.no_radius, 0); + // Checkbox + lv_style_init(&styles.switch_knob); + lv_style_set_pad_all(&styles.switch_knob, -3); + lv_style_set_bg_opa(&styles.switch_knob, LV_OPA_100); -#if LV_THEME_DEFAULT_GROW - style_init_reset(&styles.grow); - lv_style_set_transform_width(&styles.grow, lv_disp_dpx(theme.disp, 3)); - lv_style_set_transform_height(&styles.grow, lv_disp_dpx(theme.disp, 3)); -#endif + // Table + lv_style_init(&styles.table_cell); + lv_style_set_border_width(&styles.table_cell, lv_disp_dpx(theme.disp, 1)); + lv_style_set_border_side(&styles.table_cell, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM); - style_init_reset(&styles.knob); - lv_style_set_bg_color(&styles.knob, theme.color_primary); - lv_style_set_bg_opa(&styles.knob, LV_OPA_COVER); - lv_style_set_pad_all(&styles.knob, lv_disp_dpx(theme.disp, 6)); - lv_style_set_radius(&styles.knob, LV_RADIUS_CIRCLE); + // Edit box cursor + lv_style_init(&styles.field_cursor); + lv_style_set_opa(&styles.field_cursor, LV_OPA_0); - style_init_reset(&styles.anim); - lv_style_set_anim_time(&styles.anim, 200); + lv_style_init(&styles.edit_cursor); + lv_style_set_opa(&styles.edit_cursor, LV_OPA_COVER); + lv_style_set_bg_opa(&styles.edit_cursor, LV_OPA_50); - style_init_reset(&styles.anim_fast); - lv_style_set_anim_time(&styles.anim_fast, 120); + // Keyboard buttons + lv_style_init(&styles.keyboard_btn_bg); + lv_style_set_shadow_width(&styles.keyboard_btn_bg, 0); + lv_style_set_radius(&styles.keyboard_btn_bg, 5); -#if LV_USE_ARC - style_init_reset(&styles.arc_indic); - lv_style_set_arc_color(&styles.arc_indic, color_grey); - lv_style_set_arc_width(&styles.arc_indic, lv_disp_dpx(theme.disp, 15)); - lv_style_set_arc_rounded(&styles.arc_indic, true); + // Modal overlay (for dimming background) + lv_style_init(&styles.modal_overlay); + lv_style_set_bg_opa(&styles.modal_overlay, LV_OPA_50); + lv_style_set_bg_color(&styles.modal_overlay, lv_color_black()); + lv_style_init(&styles.modal_content); + lv_style_set_bg_opa(&styles.modal_content, LV_OPA_COVER); + lv_style_init(&styles.modal_title); + lv_style_set_bg_opa(&styles.modal_title, LV_OPA_COVER); + lv_style_set_pad_all(&styles.modal_title, PAGE_PADDING); + lv_style_set_width(&styles.modal_title, lv_pct(100)); + lv_style_set_max_height(&styles.modal_title, LCD_H * 0.8); - style_init_reset(&styles.arc_indic_primary); - lv_style_set_arc_color(&styles.arc_indic_primary, theme.color_primary); -#endif + // Progress bar + lv_style_init(&styles.progress_main); + lv_style_set_bg_opa(&styles.progress_main, LV_OPA_COVER); + lv_style_init(&styles.progress_indicator); + lv_style_set_bg_opa(&styles.progress_indicator, LV_OPA_COVER); -#if LV_USE_DROPDOWN - style_init_reset(&styles.dropdown_list); - lv_style_set_max_height(&styles.dropdown_list, LV_DPI_DEF * 2); -#endif -#if LV_USE_CHECKBOX - style_init_reset(&styles.cb_marker); - lv_style_set_pad_all(&styles.cb_marker, lv_disp_dpx(theme.disp, 3)); - lv_style_set_border_width(&styles.cb_marker, BORDER_WIDTH); - lv_style_set_border_color(&styles.cb_marker, theme.color_primary); - lv_style_set_bg_color(&styles.cb_marker, color_card); - lv_style_set_bg_opa(&styles.cb_marker, LV_OPA_COVER); - lv_style_set_radius(&styles.cb_marker, RADIUS_DEFAULT / 2); - - style_init_reset(&styles.cb_marker_checked); - lv_style_set_bg_img_src(&styles.cb_marker_checked, LV_SYMBOL_OK); - lv_style_set_text_color(&styles.cb_marker_checked, lv_color_white()); - lv_style_set_text_font(&styles.cb_marker_checked, theme.font_small); -#endif + // Fonts + lv_style_init(&styles.font_std); + lv_style_set_text_font(&styles.font_std, getFont(FONT(STD))); + lv_style_init(&styles.font_bold); + lv_style_set_text_font(&styles.font_bold, getFont(FONT(BOLD))); -#if LV_USE_SWITCH - style_init_reset(&styles.switch_knob); - lv_style_set_pad_all(&styles.switch_knob, - lv_disp_dpx(theme.disp, 4)); - lv_style_set_bg_color(&styles.switch_knob, lv_color_white()); -#endif + // Text align + lv_style_init(&styles.text_align_right); + lv_style_set_text_align(&styles.text_align_right, LV_TEXT_ALIGN_RIGHT); + } -#if LV_USE_LINE - style_init_reset(&styles.line); - lv_style_set_line_width(&styles.line, 1); - lv_style_set_line_color(&styles.line, color_text); -#endif + // Always update colors in case theme changes -#if LV_USE_CHART - style_init_reset(&styles.chart_bg); - lv_style_set_border_post(&styles.chart_bg, false); - lv_style_set_pad_column(&styles.chart_bg, lv_disp_dpx(theme.disp, 10)); - lv_style_set_line_color(&styles.chart_bg, color_grey); - - style_init_reset(&styles.chart_series); - lv_style_set_line_width(&styles.chart_series, lv_disp_dpx(theme.disp, 3)); - lv_style_set_radius(&styles.chart_series, lv_disp_dpx(theme.disp, 3)); - lv_style_set_size(&styles.chart_series, lv_disp_dpx(theme.disp, 8)); - lv_style_set_pad_column(&styles.chart_series, lv_disp_dpx(theme.disp, 2)); - - style_init_reset(&styles.chart_indic); - lv_style_set_radius(&styles.chart_indic, LV_RADIUS_CIRCLE); - lv_style_set_size(&styles.chart_indic, lv_disp_dpx(theme.disp, 8)); - lv_style_set_bg_color(&styles.chart_indic, theme.color_primary); - lv_style_set_bg_opa(&styles.chart_indic, LV_OPA_COVER); - - style_init_reset(&styles.chart_ticks); - lv_style_set_line_width(&styles.chart_ticks, lv_disp_dpx(theme.disp, 1)); - lv_style_set_line_color(&styles.chart_ticks, color_text); - lv_style_set_pad_all(&styles.chart_ticks, lv_disp_dpx(theme.disp, 2)); - lv_style_set_text_color(&styles.chart_ticks, lv_palette_main(LV_PALETTE_GREY)); -#endif + lv_style_set_bg_color(&styles.scrollbar, lv_palette_main(LV_PALETTE_GREY)); -#if LV_USE_MENU - style_init_reset(&styles.menu_bg); - lv_style_set_pad_all(&styles.menu_bg, 0); - lv_style_set_pad_gap(&styles.menu_bg, 0); - lv_style_set_radius(&styles.menu_bg, 0); - lv_style_set_clip_corner(&styles.menu_bg, true); - lv_style_set_border_side(&styles.menu_bg, LV_BORDER_SIDE_NONE); - - style_init_reset(&styles.menu_section); - lv_style_set_radius(&styles.menu_section, RADIUS_DEFAULT); - lv_style_set_clip_corner(&styles.menu_section, true); - lv_style_set_bg_opa(&styles.menu_section, LV_OPA_COVER); - lv_style_set_bg_color(&styles.menu_section, color_card); - lv_style_set_text_color(&styles.menu_section, color_text); - - style_init_reset(&styles.menu_cont); - lv_style_set_pad_hor(&styles.menu_cont, PAD_SMALL); - lv_style_set_pad_ver(&styles.menu_cont, PAD_SMALL); - lv_style_set_pad_gap(&styles.menu_cont, PAD_SMALL); - lv_style_set_border_width(&styles.menu_cont, lv_disp_dpx(theme.disp, 1)); - lv_style_set_border_opa(&styles.menu_cont, LV_OPA_10); - lv_style_set_border_color(&styles.menu_cont, color_text); - lv_style_set_border_side(&styles.menu_cont, LV_BORDER_SIDE_NONE); - - style_init_reset(&styles.menu_sidebar_cont); - lv_style_set_pad_all(&styles.menu_sidebar_cont, 0); - lv_style_set_pad_gap(&styles.menu_sidebar_cont, 0); - lv_style_set_border_width(&styles.menu_sidebar_cont, lv_disp_dpx(theme.disp, 1)); - lv_style_set_border_opa(&styles.menu_sidebar_cont, LV_OPA_10); - lv_style_set_border_color(&styles.menu_sidebar_cont, color_text); - lv_style_set_border_side(&styles.menu_sidebar_cont, LV_BORDER_SIDE_RIGHT); - - style_init_reset(&styles.menu_main_cont); - lv_style_set_pad_all(&styles.menu_main_cont, 0); - lv_style_set_pad_gap(&styles.menu_main_cont, 0); - - style_init_reset(&styles.menu_header_cont); - lv_style_set_pad_hor(&styles.menu_header_cont, PAD_SMALL); - lv_style_set_pad_ver(&styles.menu_header_cont, PAD_TINY); - lv_style_set_pad_gap(&styles.menu_header_cont, PAD_SMALL); - - style_init_reset(&styles.menu_header_btn); - lv_style_set_pad_hor(&styles.menu_header_btn, PAD_TINY); - lv_style_set_pad_ver(&styles.menu_header_btn, PAD_TINY); - lv_style_set_shadow_opa(&styles.menu_header_btn, LV_OPA_TRANSP); - lv_style_set_bg_opa(&styles.menu_header_btn, LV_OPA_TRANSP); - lv_style_set_text_color(&styles.menu_header_btn, color_text); - - style_init_reset(&styles.menu_page); - lv_style_set_pad_hor(&styles.menu_page, 0); - lv_style_set_pad_gap(&styles.menu_page, 0); - - style_init_reset(&styles.menu_pressed); - lv_style_set_bg_opa(&styles.menu_pressed, LV_OPA_20); - lv_style_set_bg_color(&styles.menu_pressed, lv_palette_main(LV_PALETTE_GREY)); - - style_init_reset(&styles.menu_separator); - lv_style_set_bg_opa(&styles.menu_separator, LV_OPA_TRANSP); - lv_style_set_pad_ver(&styles.menu_separator, PAD_TINY); -#endif + lv_style_set_bg_color(&styles.keyboard, makeLvColor(COLOR_THEME_SECONDARY3)); -#if LV_USE_METER - style_init_reset(&styles.meter_marker); - lv_style_set_line_width(&styles.meter_marker, lv_disp_dpx(theme.disp, 5)); - lv_style_set_line_color(&styles.meter_marker, color_text); - lv_style_set_size(&styles.meter_marker, lv_disp_dpx(theme.disp, 20)); - lv_style_set_pad_left(&styles.meter_marker, lv_disp_dpx(theme.disp, 15)); - - style_init_reset(&styles.meter_indic); - lv_style_set_radius(&styles.meter_indic, LV_RADIUS_CIRCLE); - lv_style_set_bg_color(&styles.meter_indic, color_text); - lv_style_set_bg_opa(&styles.meter_indic, LV_OPA_COVER); - lv_style_set_size(&styles.meter_indic, lv_disp_dpx(theme.disp, 15)); -#endif + lv_style_set_border_color(&styles.border, makeLvColor(COLOR_THEME_SECONDARY2)); -#if LV_USE_TABLE - style_init_reset(&styles.table_cell); - lv_style_set_border_width(&styles.table_cell, lv_disp_dpx(theme.disp, 1)); - lv_style_set_border_color(&styles.table_cell, color_grey); - lv_style_set_border_side(&styles.table_cell, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM); -#endif + lv_style_set_bg_color(&styles.btn, makeLvColor(COLOR_THEME_PRIMARY2)); + lv_style_set_text_color(&styles.btn, makeLvColor(COLOR_THEME_SECONDARY1)); -#if LV_USE_TEXTAREA - style_init_reset(&styles.ta_cursor); - lv_style_set_border_color(&styles.ta_cursor, color_text); - lv_style_set_border_width(&styles.ta_cursor, lv_disp_dpx(theme.disp, 2)); - lv_style_set_pad_left(&styles.ta_cursor, - lv_disp_dpx(theme.disp, 1)); - lv_style_set_border_side(&styles.ta_cursor, LV_BORDER_SIDE_LEFT); - lv_style_set_anim_time(&styles.ta_cursor, 400); + lv_style_set_bg_color(&styles.line_btn, makeLvColor(COLOR_THEME_PRIMARY2)); + lv_style_set_text_color(&styles.line_btn, makeLvColor(COLOR_THEME_SECONDARY1)); + lv_style_set_border_color(&styles.line_btn, makeLvColor(COLOR_THEME_SECONDARY2)); - style_init_reset(&styles.ta_placeholder); - lv_style_set_text_color(&styles.ta_placeholder, (theme.flags & MODE_DARK) ? lv_palette_darken(LV_PALETTE_GREY, - 2) : lv_palette_lighten(LV_PALETTE_GREY, 1)); + lv_style_set_bg_color(&styles.field, makeLvColor(COLOR_THEME_PRIMARY2)); + lv_style_set_border_color(&styles.field, makeLvColor(COLOR_THEME_SECONDARY2)); + lv_style_set_text_color(&styles.field, makeLvColor(COLOR_THEME_SECONDARY1)); - // field_cursor, edit_cursor - style_init_reset(&styles.field_cursor); - lv_style_set_opa(&styles.field_cursor, LV_OPA_0); + lv_style_set_border_color(&styles.focussed, makeLvColor(COLOR_THEME_FOCUS)); - style_init_reset(&styles.edit_cursor); - lv_style_set_opa(&styles.edit_cursor, LV_OPA_COVER); - lv_style_set_bg_opa(&styles.edit_cursor, LV_OPA_50); + lv_style_set_bg_color(&styles.bg_color_grey, makeLvColor(COLOR_THEME_DISABLED)); -#endif + lv_style_set_bg_color(&styles.bg_color_white, makeLvColor(COLOR_THEME_PRIMARY2)); + lv_style_set_text_color(&styles.bg_color_white, makeLvColor(COLOR_THEME_PRIMARY1)); -#if LV_USE_CALENDAR - style_init_reset(&styles.calendar_btnm_bg); - lv_style_set_pad_all(&styles.calendar_btnm_bg, PAD_SMALL); - lv_style_set_pad_gap(&styles.calendar_btnm_bg, PAD_SMALL / 2); - - style_init_reset(&styles.calendar_btnm_day); - lv_style_set_border_width(&styles.calendar_btnm_day, lv_disp_dpx(theme.disp, 1)); - lv_style_set_border_color(&styles.calendar_btnm_day, color_grey); - lv_style_set_bg_color(&styles.calendar_btnm_day, color_card); - lv_style_set_bg_opa(&styles.calendar_btnm_day, LV_OPA_20); - - style_init_reset(&styles.calendar_header); - lv_style_set_pad_hor(&styles.calendar_header, PAD_SMALL); - lv_style_set_pad_top(&styles.calendar_header, PAD_SMALL); - lv_style_set_pad_bottom(&styles.calendar_header, PAD_TINY); - lv_style_set_pad_gap(&styles.calendar_header, PAD_SMALL); -#endif + lv_style_set_bg_color(&styles.bg_color_active, makeLvColor(COLOR_THEME_ACTIVE)); + lv_style_set_text_color(&styles.bg_color_active, makeLvColor(COLOR_THEME_PRIMARY1)); -#if LV_USE_COLORWHEEL - style_init_reset(&styles.colorwheel_main); - lv_style_set_arc_width(&styles.colorwheel_main, lv_disp_dpx(theme.disp, 10)); -#endif + lv_style_set_bg_color(&styles.bg_color_mix_active, makeLvColor(COLOR_THEME_ACTIVE)); -#if LV_USE_MSGBOX - /*To add space for for the button shadow*/ - style_init_reset(&styles.msgbox_btn_bg); - lv_style_set_pad_all(&styles.msgbox_btn_bg, lv_disp_dpx(theme.disp, 4)); + lv_style_set_bg_color(&styles.bg_color_focus, makeLvColor(COLOR_THEME_FOCUS)); + lv_style_set_text_color(&styles.bg_color_focus, makeLvColor(COLOR_THEME_PRIMARY2)); - style_init_reset(&styles.msgbox_bg); - lv_style_set_max_width(&styles.msgbox_bg, lv_pct(100)); + lv_style_set_bg_color(&styles.bg_color_focus_light, makeLvColor(COLOR_THEME_FOCUS)); - style_init_reset(&styles.msgbox_backdrop_bg); - lv_style_set_bg_color(&styles.msgbox_backdrop_bg, lv_palette_main(LV_PALETTE_GREY)); - lv_style_set_bg_opa(&styles.msgbox_backdrop_bg, LV_OPA_50); -#endif -#if LV_USE_KEYBOARD - style_init_reset(&styles.keyboard_btn_bg); - lv_style_set_shadow_width(&styles.keyboard_btn_bg, 0); - lv_style_set_radius(&styles.keyboard_btn_bg, disp_size == DISP_SMALL ? RADIUS_DEFAULT / 2 : RADIUS_DEFAULT); -#endif + lv_style_set_bg_color(&styles.bg_color_edit, makeLvColor(COLOR_THEME_EDIT)); + lv_style_set_text_color(&styles.bg_color_edit, makeLvColor(COLOR_THEME_PRIMARY2)); -#if LV_USE_TABVIEW - style_init_reset(&styles.tab_btn); - lv_style_set_border_color(&styles.tab_btn, theme.color_primary); - lv_style_set_border_width(&styles.tab_btn, BORDER_WIDTH * 2); - lv_style_set_border_side(&styles.tab_btn, LV_BORDER_SIDE_BOTTOM); + lv_style_set_bg_color(&styles.slider_main, makeLvColor(COLOR_THEME_SECONDARY1)); - style_init_reset(&styles.tab_bg_focus); - lv_style_set_outline_pad(&styles.tab_bg_focus, -BORDER_WIDTH); -#endif + lv_style_set_bg_color(&styles.slider_knob, makeLvColor(COLOR_THEME_PRIMARY2)); + lv_style_set_border_color(&styles.slider_knob, makeLvColor(COLOR_THEME_SECONDARY1)); -#if LV_USE_LIST - style_init_reset(&styles.list_bg); - lv_style_set_pad_hor(&styles.list_bg, PAD_DEF); - lv_style_set_pad_ver(&styles.list_bg, 0); - lv_style_set_pad_gap(&styles.list_bg, 0); - lv_style_set_clip_corner(&styles.list_bg, true); - - style_init_reset(&styles.list_btn); - lv_style_set_border_width(&styles.list_btn, lv_disp_dpx(theme.disp, 1)); - lv_style_set_border_color(&styles.list_btn, color_grey); - lv_style_set_border_side(&styles.list_btn, LV_BORDER_SIDE_BOTTOM); - lv_style_set_pad_all(&styles.list_btn, PAD_SMALL); - lv_style_set_pad_column(&styles.list_btn, PAD_SMALL); - - style_init_reset(&styles.list_item_grow); - lv_style_set_transform_width(&styles.list_item_grow, PAD_DEF); -#endif + lv_style_set_bg_color(&styles.choice_main, makeLvColor(COLOR_THEME_PRIMARY2)); + lv_style_set_border_color(&styles.choice_main, makeLvColor(COLOR_THEME_SECONDARY2)); + lv_style_set_text_color(&styles.choice_main, makeLvColor(COLOR_THEME_SECONDARY1)); + lv_style_set_bg_color(&styles.switch_knob, makeLvColor(COLOR_THEME_PRIMARY2)); + lv_style_set_border_color(&styles.switch_knob, makeLvColor(COLOR_THEME_SECONDARY1)); -#if LV_USE_LED - style_init_reset(&styles.led); - lv_style_set_bg_opa(&styles.led, LV_OPA_COVER); - lv_style_set_bg_color(&styles.led, lv_color_white()); - lv_style_set_bg_grad_color(&styles.led, lv_palette_main(LV_PALETTE_GREY)); - lv_style_set_radius(&styles.led, LV_RADIUS_CIRCLE); - lv_style_set_shadow_width(&styles.led, lv_disp_dpx(theme.disp, 15)); - lv_style_set_shadow_color(&styles.led, lv_color_white()); - lv_style_set_shadow_spread(&styles.led, lv_disp_dpx(theme.disp, 5)); -#endif + lv_style_set_border_color(&styles.table_cell, makeLvColor(COLOR_THEME_SECONDARY2)); + + lv_style_set_bg_color(&styles.modal_content, makeLvColor(COLOR_THEME_SECONDARY3)); + + lv_style_set_bg_color(&styles.modal_title, makeLvColor(COLOR_THEME_SECONDARY1)); + lv_style_set_text_color(&styles.modal_title, makeLvColor(COLOR_THEME_PRIMARY2)); + + lv_style_set_bg_color(&styles.progress_main, makeLvColor(COLOR_THEME_SECONDARY2)); + lv_style_set_bg_color(&styles.progress_indicator, makeLvColor(COLOR_THEME_SECONDARY1)); } /********************** @@ -718,488 +384,537 @@ static void style_init(void) **********************/ lv_theme_t *etx_lv_theme_init(lv_disp_t *disp, lv_color_t color_primary, - lv_color_t color_secondary, bool dark, + lv_color_t color_secondary, const lv_font_t *font) { - if (LV_HOR_RES <= 320) - disp_size = DISP_SMALL; - else if (LV_HOR_RES < 720) - disp_size = DISP_MEDIUM; - else - disp_size = DISP_LARGE; - theme.disp = disp; theme.color_primary = color_primary; theme.color_secondary = color_secondary; theme.font_small = font; theme.font_normal = font; theme.font_large = font; - theme.apply_cb = theme_apply; - theme.flags = dark ? MODE_DARK : 0; + theme.flags = 0; style_init(); if (disp == NULL || lv_disp_get_theme(disp) == &theme) lv_obj_report_style_change(NULL); - inited = true; - return (lv_theme_t *)&theme; } -lv_theme_t * etx_lv_theme_get(void) +/********************** + * Custom object creation + **********************/ + +// Event handler forward references +static void field_edit_event(const lv_obj_class_t* class_p, lv_event_t* e); +static void window_base_event(const lv_obj_class_t* class_p, lv_event_t* e); +static void table_event(const lv_obj_class_t * class_p, lv_event_t * e); + +// Object constructors +extern "C" { + +void input_mix_line_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) { - if(!etx_lv_theme_is_inited()) { - return NULL; - } + lv_obj_add_style(obj, &styles.line_btn, 0); + lv_obj_add_style(obj, &styles.border, 0); + lv_obj_add_style(obj, &styles.rounded, 0); + lv_obj_add_style(obj, &styles.pad_tiny, 0); + lv_obj_add_style(obj, &styles.font_std, 0); + lv_obj_add_style(obj, &styles.bg_color_mix_active, LV_STATE_CHECKED); + lv_obj_add_style(obj, &styles.focussed, LV_STATE_FOCUSED); +} - return (lv_theme_t *)&theme; +void input_mix_group_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) +{ + lv_obj_add_style(obj, &styles.line_btn, 0); + lv_obj_add_style(obj, &styles.border, 0); + lv_obj_add_style(obj, &styles.rounded, 0); + lv_obj_add_style(obj, &styles.pad_tiny, 0); + lv_obj_add_style(obj, &styles.font_bold, 0); } -bool etx_lv_theme_is_inited(void) +void field_edit_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) { - return inited; + lv_obj_add_style(obj, &styles.field, 0); + lv_obj_add_style(obj, &styles.border, 0); + lv_obj_add_style(obj, &styles.rounded, 0); + lv_obj_add_style(obj, &styles.focussed, LV_STATE_FOCUSED); + lv_obj_add_style(obj, &styles.bg_color_edit, LV_STATE_EDITED); + + lv_obj_add_style(obj, &styles.field_cursor, LV_PART_CURSOR); + lv_obj_add_style(obj, &styles.edit_cursor, LV_PART_CURSOR | LV_STATE_EDITED); + + lv_obj_set_scrollbar_mode(obj, LV_SCROLLBAR_MODE_OFF); + lv_textarea_set_password_mode(obj, false); + lv_textarea_set_one_line(obj, true); } +void number_edit_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) +{ + field_edit_constructor(class_p, obj); + lv_obj_add_style(obj, &styles.text_align_right, 0); +} -static void theme_apply(lv_theme_t * th, lv_obj_t * obj) +void window_base_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) { - LV_UNUSED(th); + lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); + lv_obj_add_style(obj, &styles.scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED); +} - if(lv_obj_get_parent(obj) == NULL) { - lv_obj_add_style(obj, &styles.scr, 0); - lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); - lv_obj_add_style(obj, &styles.scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED); - return; - } +void form_window_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) +{ + window_base_constructor(class_p, obj); + lv_obj_add_style(obj, &styles.bg_color_transparent, LV_PART_MAIN); +} - if(lv_obj_check_type(obj, &lv_obj_class)) { -#if LV_USE_TABVIEW - lv_obj_t * parent = lv_obj_get_parent(obj); - /*Tabview content area*/ - if(lv_obj_check_type(parent, &lv_tabview_class)) { - return; - } - /*Tabview pages*/ - else if(lv_obj_check_type(lv_obj_get_parent(parent), &lv_tabview_class)) { - lv_obj_add_style(obj, &styles.pad_normal, 0); - lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); - lv_obj_add_style(obj, &styles.scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED); - return; - } -#endif +void table_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) +{ + lv_obj_add_style(obj, &styles.pad_zero, 0); + lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); + lv_obj_add_style(obj, &styles.scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED); + lv_obj_add_style(obj, &styles.bg_color_white, LV_PART_ITEMS); + lv_obj_add_style(obj, &styles.table_cell, LV_PART_ITEMS); + lv_obj_add_style(obj, &styles.pad_small, LV_PART_ITEMS); + lv_obj_add_style(obj, &styles.pressed, LV_PART_ITEMS | LV_STATE_PRESSED); + lv_obj_add_style(obj, &styles.bg_color_focus, LV_PART_ITEMS | LV_STATE_EDITED); +} -#if LV_USE_WIN - /*Header*/ - if(lv_obj_get_index(obj) == 0 && lv_obj_check_type(lv_obj_get_parent(obj), &lv_win_class)) { - lv_obj_add_style(obj, &styles.bg_color_grey, 0); - lv_obj_add_style(obj, &styles.pad_tiny, 0); - return; - } - /*Content*/ - else if(lv_obj_get_index(obj) == 1 && lv_obj_check_type(lv_obj_get_parent(obj), &lv_win_class)) { - lv_obj_add_style(obj, &styles.scr, 0); - lv_obj_add_style(obj, &styles.pad_normal, 0); - lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); - lv_obj_add_style(obj, &styles.scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED); - return; - } -#endif +void etx_keyboard_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) +{ + lv_obj_add_style(obj, &styles.keyboard, 0); + lv_obj_add_style(obj, &styles.pad_tiny, 0); + lv_obj_add_style(obj, &styles.btn, LV_PART_ITEMS); + lv_obj_add_style(obj, &styles.rounded, 0); + lv_obj_add_style(obj, &styles.disabled, LV_PART_ITEMS | LV_STATE_DISABLED); + lv_obj_add_style(obj, &styles.bg_color_white, LV_PART_ITEMS); + lv_obj_add_style(obj, &styles.keyboard_btn_bg, LV_PART_ITEMS); + lv_obj_add_style(obj, &styles.pressed, LV_PART_ITEMS | LV_STATE_PRESSED); + lv_obj_add_style(obj, &styles.bg_color_active, LV_PART_ITEMS | LV_STATE_CHECKED); + lv_obj_add_style(obj, &styles.bg_color_focus, LV_PART_ITEMS | LV_STATE_FOCUS_KEY); + lv_obj_add_style(obj, &styles.bg_color_focus, LV_PART_ITEMS | LV_STATE_EDITED); +} +void etx_switch_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) +{ + lv_obj_add_style(obj, &styles.bg_color_grey, 0); + lv_obj_add_style(obj, &styles.border, 0); + lv_obj_add_style(obj, &styles.border, LV_PART_INDICATOR); + lv_obj_add_style(obj, &styles.circle, 0); + lv_obj_add_style(obj, &styles.circle, LV_PART_INDICATOR); + lv_obj_add_style(obj, &styles.circle, LV_PART_KNOB); + lv_obj_add_style(obj, &styles.anim_fast, 0); + lv_obj_add_style(obj, &styles.disabled, LV_STATE_DISABLED); + lv_obj_add_style(obj, &styles.disabled, LV_PART_INDICATOR | LV_STATE_DISABLED); + lv_obj_add_style(obj, &styles.disabled, LV_PART_KNOB | LV_STATE_DISABLED); + lv_obj_add_style(obj, &styles.focussed, LV_STATE_FOCUSED); + lv_obj_add_style(obj, &styles.focussed, LV_PART_INDICATOR | LV_STATE_FOCUSED); + lv_obj_add_style(obj, &styles.bg_color_active, LV_PART_INDICATOR | LV_STATE_CHECKED); + lv_obj_add_style(obj, &styles.switch_knob, LV_PART_KNOB); + lv_obj_add_style(obj, &styles.border, LV_PART_KNOB); +} -#if LV_USE_CALENDAR - if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_calendar_class)) { - /*No style*/ - return; - } -#endif +void etx_slider_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) +{ + lv_obj_add_style(obj, &styles.slider_main, LV_PART_MAIN); + lv_obj_add_style(obj, &styles.slider_knob, LV_PART_KNOB); + lv_obj_add_style(obj, &styles.circle, LV_PART_MAIN); + lv_obj_add_style(obj, &styles.circle, LV_PART_KNOB); + lv_obj_add_style(obj, &styles.bg_color_focus, LV_PART_MAIN | LV_STATE_FOCUSED); + lv_obj_add_style(obj, &styles.bg_color_focus, LV_PART_MAIN | LV_STATE_FOCUSED | LV_STATE_EDITED); +} - lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); - lv_obj_add_style(obj, &styles.scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED); - } -#if LV_USE_BTN - else if(lv_obj_check_type(obj, &lv_btn_class)) { - lv_obj_add_style(obj, &styles.btn, 0); - lv_obj_add_style(obj, &styles.bg_color_active, LV_STATE_CHECKED); - lv_obj_add_style(obj, &styles.focus_border, LV_STATE_FOCUSED); - lv_obj_add_style(obj, &styles.disabled, LV_STATE_DISABLED); - -#if LV_USE_MENU - if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_menu_sidebar_header_cont_class) || - lv_obj_check_type(lv_obj_get_parent(obj), &lv_menu_main_header_cont_class)) { - lv_obj_add_style(obj, &styles.menu_header_btn, 0); - lv_obj_add_style(obj, &styles.menu_pressed, LV_STATE_PRESSED); - } -#endif - } - else if (lv_obj_check_type(obj, &window_base_class)) { - lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); - lv_obj_add_style(obj, &styles.scrollbar_scrolled, - LV_PART_SCROLLBAR | LV_STATE_SCROLLED); - } - else if (lv_obj_check_type(obj, &input_mix_line_class)) { - lv_obj_add_style(obj, &styles.line_btn, 0); - lv_obj_add_style(obj, &styles.pad_tiny, 0); - lv_obj_set_style_bg_color(obj, makeLvColor(COLOR_THEME_SECONDARY3), - LV_STATE_CHECKED); - lv_obj_add_style(obj, &styles.focus_border, LV_STATE_FOCUSED); - lv_obj_set_style_text_color(obj, makeLvColor(COLOR_THEME_SECONDARY1), 0); - lv_obj_set_style_text_font(obj, getFont(FONT(STD)), 0); - } -#endif - else if (lv_obj_check_type(obj, &input_mix_group_class)) { - lv_obj_add_style(obj, &styles.line_btn, 0); - lv_obj_add_style(obj, &styles.pad_tiny, 0); - lv_obj_set_style_text_color(obj, makeLvColor(COLOR_THEME_SECONDARY1), 0); - lv_obj_set_style_text_font(obj, getFont(FONT(BOLD)), 0); - } -#if LV_USE_LINE - else if (lv_obj_check_type(obj, &lv_line_class)) { - lv_obj_add_style(obj, &styles.line, 0); - } -#endif +void etx_btnmatrix_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) +{ + // main + lv_obj_add_style(obj, &styles.rounded, 0); + // items + lv_obj_add_style(obj, &styles.btn, LV_PART_ITEMS); + lv_obj_add_style(obj, &styles.rounded, LV_PART_ITEMS); + lv_obj_add_style(obj, &styles.disabled, LV_PART_ITEMS | LV_STATE_DISABLED); + lv_obj_add_style(obj, &styles.pressed, LV_PART_ITEMS | LV_STATE_PRESSED); + lv_obj_add_style(obj, &styles.bg_color_active, LV_PART_ITEMS | LV_STATE_CHECKED); + lv_obj_add_style(obj, &styles.focussed, LV_PART_ITEMS | LV_STATE_EDITED); + lv_obj_add_style(obj, &styles.bg_color_focus_light, LV_PART_MAIN | LV_STATE_FOCUSED); + lv_obj_add_style(obj, &styles.bg_color_focus_light, LV_PART_MAIN | LV_STATE_FOCUSED | LV_STATE_EDITED); +} -#if LV_USE_BTNMATRIX - else if (lv_obj_check_type(obj, &lv_btnmatrix_class)) { - // main - lv_obj_add_style(obj, &styles.rounded, 0); - // lv_obj_add_style(obj, &styles.focus_border, LV_STATE_FOCUS_KEY); - // items - lv_obj_add_style(obj, &styles.btn, LV_PART_ITEMS); - lv_obj_add_style(obj, &styles.disabled, LV_PART_ITEMS | LV_STATE_DISABLED); - lv_obj_add_style(obj, &styles.pressed, LV_PART_ITEMS | LV_STATE_PRESSED); - lv_obj_add_style(obj, &styles.bg_color_active, LV_PART_ITEMS | LV_STATE_CHECKED); - lv_obj_add_style(obj, &styles.focus_border, LV_PART_ITEMS | LV_STATE_EDITED); - } -#endif +void etx_button_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) +{ + lv_obj_add_style(obj, &styles.btn, 0); + lv_obj_add_style(obj, &styles.border, 0); + lv_obj_add_style(obj, &styles.rounded, 0); + lv_obj_add_style(obj, &styles.bg_color_active, LV_STATE_CHECKED); + lv_obj_add_style(obj, &styles.focussed, LV_STATE_FOCUSED); + lv_obj_add_style(obj, &styles.disabled, LV_STATE_DISABLED); +} -#if LV_USE_BAR - else if (lv_obj_check_type(obj, &lv_bar_class)) { - lv_obj_add_style(obj, &styles.bg_color_primary_muted, 0); - lv_obj_add_style(obj, &styles.circle, 0); - lv_obj_add_style(obj, &styles.outline_primary, LV_STATE_FOCUS_KEY); - lv_obj_add_style(obj, &styles.outline_secondary, LV_STATE_EDITED); - lv_obj_add_style(obj, &styles.bg_color_primary, LV_PART_INDICATOR); - lv_obj_add_style(obj, &styles.circle, LV_PART_INDICATOR); - } -#endif +void etx_choice_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) +{ + lv_obj_add_style(obj, &styles.choice_main, 0); + lv_obj_add_style(obj, &styles.border, 0); + lv_obj_add_style(obj, &styles.focussed, LV_PART_MAIN | LV_STATE_FOCUSED); + lv_obj_add_style(obj, &styles.rounded, 0); +} -#if LV_USE_SLIDER - else if (lv_obj_check_type(obj, &lv_slider_class)) { - lv_obj_add_style(obj, &styles.bg_color_primary_muted, 0); - lv_obj_add_style(obj, &styles.circle, 0); - lv_obj_add_style(obj, &styles.circle, LV_PART_INDICATOR); - lv_obj_add_style(obj, &styles.knob, LV_PART_KNOB); - } -#endif +void etx_bar_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) +{ + lv_obj_add_style(obj, &styles.progress_main, LV_PART_MAIN); + lv_obj_add_style(obj, &styles.progress_indicator, LV_PART_INDICATOR); + lv_obj_add_style(obj, &styles.rounded, LV_PART_MAIN); + lv_obj_add_style(obj, &styles.rounded, LV_PART_INDICATOR); +} -#if LV_USE_TABLE - else if (lv_obj_check_type(obj, &lv_table_class) || lv_obj_check_type(obj, &table_class)) { - lv_obj_add_style(obj, &styles.pad_zero, 0); - lv_obj_add_style(obj, &styles.no_radius, 0); - lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); - lv_obj_add_style(obj, &styles.scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED); - lv_obj_add_style(obj, &styles.bg_color_white, LV_PART_ITEMS); - lv_obj_add_style(obj, &styles.table_cell, LV_PART_ITEMS); - lv_obj_add_style(obj, &styles.pad_small, LV_PART_ITEMS); - lv_obj_add_style(obj, &styles.pressed, LV_PART_ITEMS | LV_STATE_PRESSED); - lv_obj_add_style(obj, &styles.bg_color_focus, LV_PART_ITEMS | LV_STATE_EDITED); - } -#endif +} -#if LV_USE_CHECKBOX - else if (lv_obj_check_type(obj, &lv_checkbox_class)) { - lv_obj_add_style(obj, &styles.pad_gap, 0); - lv_obj_add_style(obj, &styles.outline_primary, LV_STATE_FOCUS_KEY); - lv_obj_add_style(obj, &styles.disabled, LV_PART_INDICATOR | LV_STATE_DISABLED); - lv_obj_add_style(obj, &styles.cb_marker, LV_PART_INDICATOR); - lv_obj_add_style(obj, &styles.bg_color_primary, LV_PART_INDICATOR | LV_STATE_CHECKED); - lv_obj_add_style(obj, &styles.cb_marker_checked, LV_PART_INDICATOR | LV_STATE_CHECKED); - lv_obj_add_style(obj, &styles.pressed, LV_PART_INDICATOR | LV_STATE_PRESSED); -#if LV_THEME_DEFAULT_GROW - lv_obj_add_style(obj, &styles.grow, LV_PART_INDICATOR | LV_STATE_PRESSED); -#endif - lv_obj_add_style(obj, &styles.transition_normal, LV_PART_INDICATOR | LV_STATE_PRESSED); - lv_obj_add_style(obj, &styles.transition_delayed, LV_PART_INDICATOR); - } -#endif +// Object classes +const lv_obj_class_t input_mix_line_class = { + .base_class = &lv_btn_class, + .constructor_cb = input_mix_line_constructor, + .destructor_cb = nullptr, + .user_data = nullptr, + .event_cb = nullptr, + .width_def = LV_PCT(100), + .height_def = LV_SIZE_CONTENT, + .editable = LV_OBJ_CLASS_EDITABLE_INHERIT, + .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, + .instance_size = sizeof(lv_btn_t), +}; + +const lv_obj_class_t input_mix_group_class = { + .base_class = &lv_obj_class, + .constructor_cb = input_mix_group_constructor, + .destructor_cb = nullptr, + .user_data = nullptr, + .event_cb = nullptr, + .width_def = LV_PCT(100), + .height_def = LV_SIZE_CONTENT, + .editable = LV_OBJ_CLASS_EDITABLE_FALSE, + .group_def = LV_OBJ_CLASS_GROUP_DEF_FALSE, + .instance_size = sizeof(lv_obj_t), +}; + +const lv_obj_class_t field_edit_class = { + .base_class = &lv_textarea_class, + .constructor_cb = field_edit_constructor, + .destructor_cb = nullptr, + .user_data = nullptr, + .event_cb = field_edit_event, + .width_def = LV_DPI_DEF, + .height_def = 32, + .editable = LV_OBJ_CLASS_EDITABLE_TRUE, + .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, + .instance_size = sizeof(lv_textarea_t) +}; + +const lv_obj_class_t number_edit_class = { + .base_class = &lv_textarea_class, + .constructor_cb = number_edit_constructor, + .destructor_cb = nullptr, + .user_data = nullptr, + .event_cb = field_edit_event, + .width_def = LV_DPI_DEF, + .height_def = 32, + .editable = LV_OBJ_CLASS_EDITABLE_TRUE, + .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, + .instance_size = sizeof(lv_textarea_t) +}; + +const lv_obj_class_t window_base_class = { + .base_class = &lv_obj_class, + .constructor_cb = window_base_constructor, + .destructor_cb = nullptr, + .user_data = nullptr, + .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) +}; + +const lv_obj_class_t form_window_class = { + .base_class = &window_base_class, + .constructor_cb = form_window_constructor, + .destructor_cb = nullptr, + .user_data = nullptr, + .event_cb = nullptr, + .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) +}; + +const lv_obj_class_t table_class = { + .base_class = &lv_table_class, + .constructor_cb = table_constructor, + .destructor_cb = nullptr, + .user_data = nullptr, + .event_cb = table_event, + .width_def = LV_SIZE_CONTENT, + .height_def = LV_SIZE_CONTENT, + .editable = LV_OBJ_CLASS_EDITABLE_TRUE, + .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, + .instance_size = sizeof(lv_table_t), +}; + +const lv_obj_class_t etx_keyboard_class = { + .base_class = &lv_keyboard_class, + .constructor_cb = etx_keyboard_constructor, + .destructor_cb = nullptr, + .user_data = nullptr, + .event_cb = nullptr, + .width_def = 0, + .height_def = 0, + .editable = LV_OBJ_CLASS_EDITABLE_INHERIT, + .group_def = LV_OBJ_CLASS_GROUP_DEF_INHERIT, + .instance_size = sizeof(lv_keyboard_t), +}; + +const lv_obj_class_t etx_switch_class = { + .base_class = &lv_switch_class, + .constructor_cb = etx_switch_constructor, + .destructor_cb = nullptr, + .user_data = nullptr, + .event_cb = nullptr, + .width_def = 0, + .height_def = 32, + .editable = LV_OBJ_CLASS_EDITABLE_INHERIT, + .group_def = LV_OBJ_CLASS_GROUP_DEF_INHERIT, + .instance_size = sizeof(lv_switch_t), +}; + +const lv_obj_class_t etx_slider_class = { + .base_class = &lv_slider_class, + .constructor_cb = etx_slider_constructor, + .destructor_cb = nullptr, + .user_data = nullptr, + .event_cb = nullptr, + .width_def = 0, + .height_def = 16, + .editable = LV_OBJ_CLASS_EDITABLE_INHERIT, + .group_def = LV_OBJ_CLASS_GROUP_DEF_INHERIT, + .instance_size = sizeof(lv_slider_t), +}; + +const lv_obj_class_t etx_btnmatrix_class = { + .base_class = &lv_btnmatrix_class, + .constructor_cb = etx_btnmatrix_constructor, + .destructor_cb = nullptr, + .user_data = nullptr, + .event_cb = nullptr, + .width_def = 0, + .height_def = 0, + .editable = LV_OBJ_CLASS_EDITABLE_INHERIT, + .group_def = LV_OBJ_CLASS_GROUP_DEF_INHERIT, + .instance_size = sizeof(lv_btnmatrix_t), +}; + +const lv_obj_class_t etx_button_class = { + .base_class = &lv_btn_class, + .constructor_cb = etx_button_constructor, + .destructor_cb = nullptr, + .user_data = nullptr, + .event_cb = nullptr, + .width_def = LV_SIZE_CONTENT, + .height_def = 32, + .editable = LV_OBJ_CLASS_EDITABLE_INHERIT, + .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, + .instance_size = sizeof(lv_btn_t), +}; + +const lv_obj_class_t etx_vbutton_class = { + .base_class = &lv_btn_class, + .constructor_cb = etx_button_constructor, + .destructor_cb = nullptr, + .user_data = nullptr, + .event_cb = nullptr, + .width_def = LV_SIZE_CONTENT, + .height_def = LV_SIZE_CONTENT, + .editable = LV_OBJ_CLASS_EDITABLE_INHERIT, + .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, + .instance_size = sizeof(lv_btn_t), +}; + +const lv_obj_class_t etx_choice_class = { + .base_class = &lv_obj_class, + .constructor_cb = etx_choice_constructor, + .destructor_cb = nullptr, + .user_data = nullptr, + .event_cb = nullptr, + .width_def = LV_SIZE_CONTENT, + .height_def = 32, + .editable = LV_OBJ_CLASS_EDITABLE_INHERIT, + .group_def = LV_OBJ_CLASS_GROUP_DEF_INHERIT, + .instance_size = sizeof(lv_obj_t), +}; + +const lv_obj_class_t etx_bar_class = { + .base_class = &lv_bar_class, + .constructor_cb = etx_bar_constructor, + .destructor_cb = nullptr, + .user_data = nullptr, + .event_cb = nullptr, + .width_def = lv_pct(100), + .height_def = 32, + .editable = LV_OBJ_CLASS_EDITABLE_INHERIT, + .group_def = LV_OBJ_CLASS_GROUP_DEF_INHERIT, + .instance_size = sizeof(lv_bar_t), +}; + +// Event handlers +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(&field_edit_class, e); +} -#if LV_USE_SWITCH - else if (lv_obj_check_type(obj, &lv_switch_class)) { - lv_obj_add_style(obj, &styles.bg_color_grey, 0); - lv_obj_add_style(obj, &styles.circle, 0); - lv_obj_add_style(obj, &styles.anim_fast, 0); - lv_obj_add_style(obj, &styles.disabled, LV_STATE_DISABLED); - lv_obj_add_style(obj, &styles.focus_border, LV_STATE_FOCUSED); - lv_obj_add_style(obj, &styles.focus_border, LV_PART_INDICATOR | LV_STATE_FOCUSED); - lv_obj_add_style(obj, &styles.bg_color_active, LV_PART_INDICATOR | LV_STATE_CHECKED); - lv_obj_add_style(obj, &styles.circle, LV_PART_INDICATOR); - lv_obj_add_style(obj, &styles.disabled, LV_PART_INDICATOR | LV_STATE_DISABLED); - lv_obj_add_style(obj, &styles.knob, LV_PART_KNOB); - lv_obj_add_style(obj, &styles.bg_color_white, LV_PART_KNOB); - lv_obj_add_style(obj, &styles.switch_knob, LV_PART_KNOB); - lv_obj_add_style(obj, &styles.disabled, LV_PART_KNOB | LV_STATE_DISABLED); - } -#endif +extern "C" void window_event_cb(lv_event_t * e); -#if LV_USE_CHART - else if (lv_obj_check_type(obj, &lv_chart_class)) { - // lv_obj_add_style(obj, &styles.card, 0); - lv_obj_add_style(obj, &styles.pad_small, 0); - lv_obj_add_style(obj, &styles.chart_bg, 0); - lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); - lv_obj_add_style(obj, &styles.scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED); - lv_obj_add_style(obj, &styles.chart_series, LV_PART_ITEMS); - lv_obj_add_style(obj, &styles.chart_indic, LV_PART_INDICATOR); - lv_obj_add_style(obj, &styles.chart_ticks, LV_PART_TICKS); - lv_obj_add_style(obj, &styles.chart_series, LV_PART_CURSOR); - } -#endif +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(&window_base_class, e); + if (res != LV_RES_OK) return; -#if LV_USE_ROLLER - else if (lv_obj_check_type(obj, &lv_roller_class)) { - // lv_obj_add_style(obj, &styles.card, 0); - lv_obj_add_style(obj, &styles.anim, 0); - lv_obj_add_style(obj, &styles.line_space_large, 0); - lv_obj_add_style(obj, &styles.text_align_center, 0); - lv_obj_add_style(obj, &styles.outline_primary, LV_STATE_FOCUS_KEY); - lv_obj_add_style(obj, &styles.outline_secondary, LV_STATE_EDITED); - lv_obj_add_style(obj, &styles.bg_color_primary, LV_PART_SELECTED); - } -#endif + window_event_cb(e); +} -#if LV_USE_DROPDOWN - else if (lv_obj_check_type(obj, &lv_dropdown_class)) { - // lv_obj_add_style(obj, &styles.card, 0); - lv_obj_add_style(obj, &styles.pad_small, 0); - lv_obj_add_style(obj, &styles.transition_delayed, 0); - lv_obj_add_style(obj, &styles.transition_normal, LV_STATE_PRESSED); - lv_obj_add_style(obj, &styles.pressed, LV_STATE_PRESSED); - lv_obj_add_style(obj, &styles.outline_primary, LV_STATE_FOCUS_KEY); - lv_obj_add_style(obj, &styles.outline_secondary, LV_STATE_EDITED); - lv_obj_add_style(obj, &styles.transition_normal, LV_PART_INDICATOR); - } else if (lv_obj_check_type(obj, &lv_dropdownlist_class)) { - // lv_obj_add_style(obj, &styles.card, 0); - lv_obj_add_style(obj, &styles.clip_corner, 0); - lv_obj_add_style(obj, &styles.line_space_large, 0); - lv_obj_add_style(obj, &styles.dropdown_list, 0); - lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); - lv_obj_add_style(obj, &styles.scrollbar_scrolled, - LV_PART_SCROLLBAR | LV_STATE_SCROLLED); - lv_obj_add_style(obj, &styles.bg_color_white, LV_PART_SELECTED); - lv_obj_add_style(obj, &styles.bg_color_primary, - LV_PART_SELECTED | LV_STATE_CHECKED); - lv_obj_add_style(obj, &styles.pressed, - LV_PART_SELECTED | LV_STATE_PRESSED); - } -#endif +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(&table_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; + } + } +} -#if LV_USE_ARC - else if (lv_obj_check_type(obj, &lv_arc_class)) { - lv_obj_add_style(obj, &styles.arc_indic, 0); - lv_obj_add_style(obj, &styles.arc_indic, LV_PART_INDICATOR); - lv_obj_add_style(obj, &styles.arc_indic_primary, LV_PART_INDICATOR); - lv_obj_add_style(obj, &styles.knob, LV_PART_KNOB); - } -#endif +// Object creators +static lv_obj_t* etx_create(const lv_obj_class_t* class_p, lv_obj_t* parent) +{ + lv_obj_t * obj = lv_obj_class_create_obj(class_p, parent); + lv_obj_class_init_obj(obj); + return obj; +} -#if LV_USE_SPINNER - else if (lv_obj_check_type(obj, &lv_spinner_class)) { - lv_obj_add_style(obj, &styles.arc_indic, 0); - lv_obj_add_style(obj, &styles.arc_indic, LV_PART_INDICATOR); - lv_obj_add_style(obj, &styles.arc_indic_primary, LV_PART_INDICATOR); - } -#endif +lv_obj_t* input_mix_line_create(lv_obj_t* parent) +{ + return etx_create(&input_mix_line_class, parent); +} -#if LV_USE_METER - else if (lv_obj_check_type(obj, &lv_meter_class)) { - // lv_obj_add_style(obj, &styles.card, 0); - lv_obj_add_style(obj, &styles.circle, 0); - lv_obj_add_style(obj, &styles.meter_indic, LV_PART_INDICATOR); - } -#endif +lv_obj_t* input_mix_group_create(lv_obj_t* parent) +{ + return etx_create(&input_mix_group_class, parent); +} -#if LV_USE_TEXTAREA - else if (lv_obj_check_type(obj, &lv_textarea_class)) { - lv_obj_add_style(obj, &styles.card, 0); - lv_obj_add_style(obj, &styles.pad_small, 0); - lv_obj_add_style(obj, &styles.outline_primary, LV_STATE_FOCUS_KEY); - lv_obj_add_style(obj, &styles.outline_secondary, LV_STATE_EDITED); - lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); - lv_obj_add_style(obj, &styles.scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED); - lv_obj_add_style(obj, &styles.ta_cursor, LV_PART_CURSOR | LV_STATE_FOCUSED); - lv_obj_add_style(obj, &styles.ta_placeholder, LV_PART_TEXTAREA_PLACEHOLDER); - } else if (lv_obj_check_type(obj, &field_edit_class)) { - lv_obj_add_style(obj, &styles.field, 0); - lv_obj_add_style(obj, &styles.bg_color_focus, LV_STATE_FOCUSED); - lv_obj_add_style(obj, &styles.bg_color_edit, LV_STATE_EDITED); - - lv_obj_add_style(obj, &styles.field_cursor, LV_PART_CURSOR); - lv_obj_add_style(obj, &styles.edit_cursor, - LV_PART_CURSOR | LV_STATE_EDITED); - } -#endif +lv_obj_t* etx_text_edit_create(lv_obj_t* parent) +{ + return etx_create(&field_edit_class, parent); +} -#if LV_USE_CALENDAR - else if (lv_obj_check_type(obj, &lv_calendar_class)) { - // lv_obj_add_style(obj, &styles.card, 0); - lv_obj_add_style(obj, &styles.pad_zero, 0); - } -#endif +lv_obj_t* etx_number_edit_create(lv_obj_t* parent) +{ + return etx_create(&number_edit_class, parent); +} -#if LV_USE_CALENDAR_HEADER_ARROW - else if (lv_obj_check_type(obj, &lv_calendar_header_arrow_class)) { - lv_obj_add_style(obj, &styles.calendar_header, 0); - } -#endif +lv_obj_t* window_create(lv_obj_t* parent) +{ + return etx_create(&window_base_class, parent); +} -#if LV_USE_CALENDAR_HEADER_DROPDOWN - else if (lv_obj_check_type(obj, &lv_calendar_header_dropdown_class)) { - lv_obj_add_style(obj, &styles.calendar_header, 0); - } -#endif +lv_obj_t* etx_form_window_create(lv_obj_t* parent) +{ + return etx_create(&form_window_class, parent); +} -#if LV_USE_KEYBOARD - else if (lv_obj_check_type(obj, &lv_keyboard_class)) { - lv_obj_add_style(obj, &styles.scr, 0); - lv_obj_add_style(obj, disp_size == DISP_LARGE ? &styles.pad_small : &styles.pad_tiny, 0); - // lv_obj_add_style(obj, &styles.outline_primary, LV_STATE_FOCUS_KEY); - // lv_obj_add_style(obj, &styles.outline_secondary, LV_STATE_EDITED); - lv_obj_add_style(obj, &styles.btn, LV_PART_ITEMS); - lv_obj_add_style(obj, &styles.disabled, LV_PART_ITEMS | LV_STATE_DISABLED); - lv_obj_add_style(obj, &styles.bg_color_white, LV_PART_ITEMS); - lv_obj_add_style(obj, &styles.keyboard_btn_bg, LV_PART_ITEMS); - lv_obj_add_style(obj, &styles.pressed, LV_PART_ITEMS | LV_STATE_PRESSED); - lv_obj_add_style(obj, &styles.bg_color_active, LV_PART_ITEMS | LV_STATE_CHECKED); - lv_obj_add_style(obj, &styles.bg_color_focus, LV_PART_ITEMS | LV_STATE_FOCUS_KEY); - lv_obj_add_style(obj, &styles.bg_color_focus, LV_PART_ITEMS | LV_STATE_EDITED); - } -#endif -#if LV_USE_LIST - else if (lv_obj_check_type(obj, &lv_list_class)) { - // lv_obj_add_style(obj, &styles.card, 0); - lv_obj_add_style(obj, &styles.list_bg, 0); - lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); - lv_obj_add_style(obj, &styles.scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED); - return; - } else if (lv_obj_check_type(obj, &lv_list_text_class)) { - lv_obj_add_style(obj, &styles.bg_color_grey, 0); - lv_obj_add_style(obj, &styles.list_item_grow, 0); - } else if (lv_obj_check_type(obj, &lv_list_btn_class)) { - lv_obj_add_style(obj, &styles.bg_color_white, 0); - lv_obj_add_style(obj, &styles.list_btn, 0); - lv_obj_add_style(obj, &styles.bg_color_primary, LV_STATE_FOCUS_KEY); - lv_obj_add_style(obj, &styles.list_item_grow, LV_STATE_FOCUS_KEY); - lv_obj_add_style(obj, &styles.list_item_grow, LV_STATE_PRESSED); - lv_obj_add_style(obj, &styles.pressed, LV_STATE_PRESSED); +lv_obj_t * etx_table_create(lv_obj_t * parent) +{ + return etx_create(&table_class, parent); +} - } -#endif -#if LV_USE_MENU - else if (lv_obj_check_type(obj, &lv_menu_class)) { - // lv_obj_add_style(obj, &styles.card, 0); - lv_obj_add_style(obj, &styles.menu_bg, 0); - } else if (lv_obj_check_type(obj, &lv_menu_sidebar_cont_class)) { - lv_obj_add_style(obj, &styles.menu_sidebar_cont, 0); - lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); - lv_obj_add_style(obj, &styles.scrollbar_scrolled, - LV_PART_SCROLLBAR | LV_STATE_SCROLLED); - } else if (lv_obj_check_type(obj, &lv_menu_main_cont_class)) { - lv_obj_add_style(obj, &styles.menu_main_cont, 0); - lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); - lv_obj_add_style(obj, &styles.scrollbar_scrolled, - LV_PART_SCROLLBAR | LV_STATE_SCROLLED); - } else if (lv_obj_check_type(obj, &lv_menu_cont_class)) { - lv_obj_add_style(obj, &styles.menu_cont, 0); - lv_obj_add_style(obj, &styles.menu_pressed, LV_STATE_PRESSED); - lv_obj_add_style(obj, &styles.bg_color_primary_muted, - LV_STATE_PRESSED | LV_STATE_CHECKED); - lv_obj_add_style(obj, &styles.bg_color_primary_muted, LV_STATE_CHECKED); - } else if (lv_obj_check_type(obj, &lv_menu_sidebar_header_cont_class) || - lv_obj_check_type(obj, &lv_menu_main_header_cont_class)) { - lv_obj_add_style(obj, &styles.menu_header_cont, 0); - lv_obj_add_style(obj, &styles.menu_pressed, LV_STATE_PRESSED); - } else if (lv_obj_check_type(obj, &lv_menu_page_class)) { - lv_obj_add_style(obj, &styles.menu_page, 0); - lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); - lv_obj_add_style(obj, &styles.scrollbar_scrolled, - LV_PART_SCROLLBAR | LV_STATE_SCROLLED); - } else if (lv_obj_check_type(obj, &lv_menu_section_class)) { - lv_obj_add_style(obj, &styles.menu_section, 0); - } else if (lv_obj_check_type(obj, &lv_menu_separator_class)) { - lv_obj_add_style(obj, &styles.menu_separator, 0); - } -#endif -#if LV_USE_MSGBOX - else if (lv_obj_check_type(obj, &lv_msgbox_class)) { - // lv_obj_add_style(obj, &styles.card, 0); - lv_obj_add_style(obj, &styles.msgbox_bg, 0); - return; - } else if (lv_obj_check_type(obj, &lv_msgbox_backdrop_class)) { - lv_obj_add_style(obj, &styles.msgbox_backdrop_bg, 0); - } -#endif -#if LV_USE_SPINBOX - else if (lv_obj_check_type(obj, &lv_spinbox_class)) { - // lv_obj_add_style(obj, &styles.card, 0); - lv_obj_add_style(obj, &styles.pad_small, 0); - // lv_obj_add_style(obj, &styles.outline_primary, LV_STATE_FOCUS_KEY); - // lv_obj_add_style(obj, &styles.outline_secondary, LV_STATE_EDITED); - lv_obj_add_style(obj, &styles.bg_color_primary, LV_PART_CURSOR); - } -#endif -#if LV_USE_TILEVIEW - else if (lv_obj_check_type(obj, &lv_tileview_class)) { - lv_obj_add_style(obj, &styles.scr, 0); - lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); - lv_obj_add_style(obj, &styles.scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED); - } else if (lv_obj_check_type(obj, &lv_tileview_tile_class)) { - lv_obj_add_style(obj, &styles.scrollbar, LV_PART_SCROLLBAR); - lv_obj_add_style(obj, &styles.scrollbar_scrolled, - LV_PART_SCROLLBAR | LV_STATE_SCROLLED); - } -#endif +lv_obj_t* etx_keyboard_create(lv_obj_t* parent) +{ + return etx_create(&etx_keyboard_class, parent); +} -#if LV_USE_TABVIEW - else if (lv_obj_check_type(obj, &lv_tabview_class)) { - lv_obj_add_style(obj, &styles.scr, 0); - lv_obj_add_style(obj, &styles.pad_zero, 0); - } -#endif +lv_obj_t* etx_switch_create(lv_obj_t* parent) +{ + return etx_create(&etx_switch_class, parent); +} -#if LV_USE_WIN - else if (lv_obj_check_type(obj, &lv_win_class)) { - lv_obj_add_style(obj, &styles.clip_corner, 0); - } -#endif +lv_obj_t* etx_slider_create(lv_obj_t* parent) +{ + return etx_create(&etx_slider_class, parent); +} -#if LV_USE_COLORWHEEL - else if (lv_obj_check_type(obj, &lv_colorwheel_class)) { - lv_obj_add_style(obj, &styles.colorwheel_main, 0); - lv_obj_add_style(obj, &styles.pad_normal, 0); - lv_obj_add_style(obj, &styles.bg_color_white, LV_PART_KNOB); - lv_obj_add_style(obj, &styles.pad_normal, LV_PART_KNOB); - } -#endif +lv_obj_t* etx_btnmatrix_create(lv_obj_t* parent) +{ + return etx_create(&etx_btnmatrix_class, parent); +} -#if LV_USE_LED - else if (lv_obj_check_type(obj, &lv_led_class)) { - lv_obj_add_style(obj, &styles.led, 0); - } -#endif +// Fixed height (32) +lv_obj_t* etx_button_create(lv_obj_t* parent) +{ + return etx_create(&etx_button_class, parent); } -/********************** - * STATIC FUNCTIONS - **********************/ +// Variable height +lv_obj_t* etx_vbutton_create(lv_obj_t* parent) +{ + return etx_create(&etx_vbutton_class, parent); +} -static void style_init_reset(lv_style_t * style) +lv_obj_t* etx_choice_create(lv_obj_t* parent) { - if(inited) { - lv_style_reset(style); - } - else { - lv_style_init(style); - } + return etx_create(&etx_choice_class, parent); +} + +lv_obj_t* etx_bar_create(lv_obj_t* parent) +{ + return etx_create(&etx_bar_class, parent); +} + +lv_obj_t* etx_modal_create(lv_obj_t* parent) +{ + lv_obj_t* obj = window_create(parent); + + lv_obj_add_style(obj, &styles.modal_overlay, 0); + + return obj; +} + +lv_obj_t* etx_modal_content_create(lv_obj_t* parent) +{ + lv_obj_t* obj = window_create(parent); + + lv_obj_add_style(obj, &styles.modal_content, 0); + + return obj; +} + +lv_obj_t* etx_modal_title_create(lv_obj_t* parent) +{ + lv_obj_t* obj = lv_label_create(parent); + + lv_obj_add_style(obj, &styles.modal_title, 0); + + return obj; } diff --git a/radio/src/gui/colorlcd/themes/etx_lv_theme.h b/radio/src/gui/colorlcd/themes/etx_lv_theme.h index aa85d4499e1..90f949603ad 100644 --- a/radio/src/gui/colorlcd/themes/etx_lv_theme.h +++ b/radio/src/gui/colorlcd/themes/etx_lv_theme.h @@ -1,10 +1,25 @@ -/** - * @file lv_theme.h +/* + * 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. */ -#ifndef ETX_LV_THEME_H -#define ETX_LV_THEME_H +#pragma once /********************* * INCLUDES @@ -23,19 +38,5 @@ * @return a pointer to reference this theme later */ lv_theme_t* etx_lv_theme_init(lv_disp_t* disp, lv_color_t color_primary, - lv_color_t color_secondary, bool dark, + lv_color_t color_secondary, const lv_font_t* font); - -/** - * Get default theme - * @return a pointer to default theme, or NULL if this is not initialized - */ -lv_theme_t * etx_lv_theme_get(void); - -/** - * Check if default theme is initialized - * @return true if default theme is initialized, false otherwise - */ -bool etx_lv_theme_is_inited(void); - -#endif /*LV_THEME_H*/ diff --git a/radio/src/gui/colorlcd/themes/flysky.cpp b/radio/src/gui/colorlcd/themes/flysky.cpp deleted file mode 100644 index b993968810b..00000000000 --- a/radio/src/gui/colorlcd/themes/flysky.cpp +++ /dev/null @@ -1,439 +0,0 @@ -/* - * 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. - */ - -#include "opentx.h" -#include "tabsgroup.h" - -const ZoneOption OPTIONS_THEME_DEFAULT[] = { - { STR_BACKGROUND_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(COLOR_THEME_PRIMARY2) }, - { STR_MAIN_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(COLOR_THEME_WARNING) }, - { nullptr, ZoneOption::Bool } -}; - -class FlyskyTheme: public OpenTxTheme -{ - public: - FlyskyTheme(): - OpenTxTheme("FlySky", OPTIONS_THEME_DEFAULT) - { - loadColors(); - } - - void loadColors() const - { - TRACE("Load FlySky theme colors"); - - lcdColorTable[DEFAULT_COLOR_INDEX] = RGB(18, 94, 153); - - lcdColorTable[COLOR_THEME_PRIMARY1_INDEX] = RGB(0, 0, 0); - lcdColorTable[COLOR_THEME_PRIMARY2_INDEX] = RGB(255, 255, 255); - lcdColorTable[COLOR_THEME_PRIMARY3_INDEX] = RGB(12, 63, 102); - lcdColorTable[COLOR_THEME_SECONDARY1_INDEX] = RGB(18, 94, 153); - lcdColorTable[COLOR_THEME_SECONDARY2_INDEX] = RGB(182, 224, 242); - lcdColorTable[COLOR_THEME_SECONDARY3_INDEX] = RGB(228, 238, 242); - lcdColorTable[COLOR_THEME_FOCUS_INDEX] = RGB(20, 161, 229); - lcdColorTable[COLOR_THEME_EDIT_INDEX] = RGB(0, 153, 9); - lcdColorTable[COLOR_THEME_ACTIVE_INDEX] = RGB(255, 222, 0); - lcdColorTable[COLOR_THEME_WARNING_INDEX] = RGB(224, 0, 0); - lcdColorTable[COLOR_THEME_DISABLED_INDEX] = RGB(140, 140, 140); - lcdColorTable[CUSTOM_COLOR_INDEX] = RGB(170, 85, 0); - } - - void loadMenuIcon(uint8_t index, const char * filename, uint32_t color=COLOR_THEME_SECONDARY1) const - { - TRACE("loadMenuIcon %s", getFilePath(filename)); - - BitmapBuffer * mask = BitmapBuffer::loadMask(getFilePath(filename)); - if (mask) { - delete iconMask[index]; - iconMask[index] = mask; - - uint8_t width = mask->width(); - uint8_t height = mask->height(); - - if (0) { - delete menuIconNormal[index]; - menuIconNormal[index] = new BitmapBuffer(BMP_RGB565, width, height); - if (menuIconNormal[index]) { - menuIconNormal[index]->clear(COLOR_THEME_FOCUS); - menuIconNormal[index]->drawMask(0, 0, mask, color); - } - - delete menuIconSelected[index]; - menuIconSelected[index] = new BitmapBuffer(BMP_RGB565, width, height); - if (menuIconSelected[index]) { - menuIconSelected[index]->clear(COLOR_THEME_FOCUS); - menuIconSelected[index]->drawMask(0, 0, mask, color); - } - } - else { - delete menuIconNormal[index]; - menuIconNormal[index] = new BitmapBuffer(BMP_RGB565, MENU_HEADER_BUTTON_WIDTH, MENU_HEADER_BUTTON_WIDTH); - if (menuIconNormal[index]) { - menuIconNormal[index]->clear(COLOR_THEME_FOCUS); - menuIconNormal[index]->drawMask((MENU_HEADER_BUTTON_WIDTH-width)/2, (MENU_HEADER_BUTTON_WIDTH-width)/2, mask, color); - } - - delete menuIconSelected[index]; - menuIconSelected[index] = new BitmapBuffer(BMP_RGB565, MENU_HEADER_BUTTON_WIDTH, MENU_HEADER_BUTTON_WIDTH); - if (menuIconSelected[index]) { - if (index < ICON_RADIO) - menuIconSelected[index]->clear(COLOR_THEME_FOCUS /*HEADER_LOGO_BGCOLOR*/); - else - menuIconSelected[index]->clear(COLOR_THEME_FOCUS); - menuIconSelected[index]->drawMask((MENU_HEADER_BUTTON_WIDTH-width)/2, (MENU_HEADER_BUTTON_WIDTH-height)/2, mask, color); - } - } - } - } - - void loadIcons() const - { -#if defined(LOG_TELEMETRY) || defined(WATCHDOG_DISABLED) - loadMenuIcon(ICON_OPENTX, "mask_opentx_testmode.png", COLOR_THEME_SECONDARY1); -#else - loadMenuIcon(ICON_OPENTX, "mask_edgetx.png"); -#endif -#if defined(HARDWARE_TOUCH) - loadMenuIcon(ICON_NEXT, "mask_next.png"); - loadMenuIcon(ICON_BACK, "mask_back.png"); -#endif - loadMenuIcon(ICON_RADIO, "mask_menu_radio.png"); - loadMenuIcon(ICON_RADIO_SETUP, "mask_radio_setup.png"); - loadMenuIcon(ICON_RADIO_SD_MANAGER, "mask_radio_sd_browser.png"); - loadMenuIcon(ICON_RADIO_TOOLS, "mask_radio_tools.png"); - loadMenuIcon(ICON_RADIO_GLOBAL_FUNCTIONS, "mask_radio_global_functions.png"); - loadMenuIcon(ICON_RADIO_TRAINER, "mask_radio_trainer.png"); - loadMenuIcon(ICON_RADIO_HARDWARE, "mask_radio_hardware.png"); - loadMenuIcon(ICON_RADIO_CALIBRATION, "mask_radio_calibration.png"); - loadMenuIcon(ICON_RADIO_VERSION, "mask_radio_version.png"); - loadMenuIcon(ICON_MODEL, "mask_menu_model.png"); - loadMenuIcon(ICON_MODEL_SETUP, "mask_model_setup.png"); - loadMenuIcon(ICON_MODEL_HELI, "mask_model_heli.png"); - loadMenuIcon(ICON_MODEL_FLIGHT_MODES, "mask_model_flight_modes.png"); - loadMenuIcon(ICON_MODEL_INPUTS, "mask_model_inputs.png"); - loadMenuIcon(ICON_MODEL_MIXER, "mask_model_mixer.png"); - loadMenuIcon(ICON_MODEL_OUTPUTS, "mask_model_outputs.png"); - loadMenuIcon(ICON_MODEL_CURVES, "mask_model_curves.png"); - loadMenuIcon(ICON_MODEL_GVARS, "mask_model_gvars.png"); - loadMenuIcon(ICON_MODEL_LOGICAL_SWITCHES, "mask_model_logical_switches.png"); - loadMenuIcon(ICON_MODEL_SPECIAL_FUNCTIONS, "mask_model_special_functions.png"); - loadMenuIcon(ICON_MODEL_LUA_SCRIPTS, "mask_model_lua_scripts.png"); - loadMenuIcon(ICON_MODEL_TELEMETRY, "mask_model_telemetry.png"); - loadMenuIcon(ICON_STATS, "mask_menu_stats.png"); - loadMenuIcon(ICON_STATS_THROTTLE_GRAPH, "mask_stats_throttle_graph.png"); - loadMenuIcon(ICON_STATS_TIMERS, "mask_stats_timers.png"); - loadMenuIcon(ICON_STATS_ANALOGS, "mask_stats_analogs.png"); - loadMenuIcon(ICON_STATS_DEBUG, "mask_stats_debug.png"); - loadMenuIcon(ICON_THEME, "mask_menu_theme.png"); - loadMenuIcon(ICON_THEME_SETUP, "mask_theme_setup.png"); - loadMenuIcon(ICON_THEME_VIEW1, "mask_theme_view1.png"); - loadMenuIcon(ICON_THEME_VIEW2, "mask_theme_view2.png"); - loadMenuIcon(ICON_THEME_VIEW3, "mask_theme_view3.png"); - loadMenuIcon(ICON_THEME_VIEW4, "mask_theme_view4.png"); - loadMenuIcon(ICON_THEME_VIEW5, "mask_theme_view5.png"); - loadMenuIcon(ICON_THEME_VIEW6, "mask_theme_view6.png"); - loadMenuIcon(ICON_THEME_VIEW7, "mask_theme_view7.png"); - loadMenuIcon(ICON_THEME_VIEW8, "mask_theme_view8.png"); - loadMenuIcon(ICON_THEME_VIEW9, "mask_theme_view9.png"); - loadMenuIcon(ICON_THEME_VIEW10, "mask_theme_view10.png"); - loadMenuIcon(ICON_THEME_ADD_VIEW, "mask_theme_add_view.png"); - loadMenuIcon(ICON_MONITOR, "mask_monitor.png"); - loadMenuIcon(ICON_MONITOR_CHANNELS1, "mask_monitor_channels1.png"); - loadMenuIcon(ICON_MONITOR_CHANNELS2, "mask_monitor_channels2.png"); - loadMenuIcon(ICON_MONITOR_CHANNELS3, "mask_monitor_channels3.png"); - loadMenuIcon(ICON_MONITOR_CHANNELS4, "mask_monitor_channels4.png"); - loadMenuIcon(ICON_MONITOR_LOGICAL_SWITCHES, "mask_monitor_logsw.png"); - - BitmapBuffer * background = BitmapBuffer::loadMask(getFilePath("mask_currentmenu_bg.png")); - BitmapBuffer * shadow = BitmapBuffer::loadMask(getFilePath("mask_currentmenu_shadow.png")); - BitmapBuffer * dot = BitmapBuffer::loadMask(getFilePath("mask_currentmenu_dot.png")); - - if (!currentMenuBackground) { - currentMenuBackground = new BitmapBuffer(BMP_RGB565, 36, 53); - } - if (currentMenuBackground) { - currentMenuBackground->drawSolidFilledRect(0, 0, currentMenuBackground->width(), MENU_HEADER_HEIGHT, COLOR_THEME_FOCUS); - currentMenuBackground->drawSolidFilledRect(0, MENU_HEADER_HEIGHT, currentMenuBackground->width(), MENU_TITLE_TOP - MENU_HEADER_HEIGHT, COLOR_THEME_SECONDARY3); - currentMenuBackground->drawSolidFilledRect(0, MENU_TITLE_TOP, currentMenuBackground->width(), currentMenuBackground->height() - MENU_TITLE_TOP, COLOR_THEME_SECONDARY1); - currentMenuBackground->drawMask(0, 0, background, COLOR_THEME_FOCUS); - currentMenuBackground->drawMask(0, 0, shadow, COLOR_THEME_PRIMARY1); - currentMenuBackground->drawMask(10, 39, dot, COLOR_THEME_SECONDARY1); - } - - delete topleftBitmap; - topleftBitmap = BitmapBuffer::loadMaskOnBackground("topleft.png", COLOR_THEME_SECONDARY1, COLOR_THEME_FOCUS); - - delete background; - delete shadow; - delete dot; - } - - void loadThemeBitmaps() const - { - // Calibration screen - delete calibStick; - calibStick = BitmapBuffer::loadBitmap(getFilePath("stick_pointer.png")); - - delete calibStickBackground; - calibStickBackground = BitmapBuffer::loadBitmap(getFilePath("stick_background.png")); - - delete calibTrackpBackground; - calibTrackpBackground = BitmapBuffer::loadBitmap(getFilePath("trackp_background.png")); - - // Model Selection screen - // delete modelselIconBitmap; - // modelselIconBitmap = BitmapBuffer::loadMaskOnBackground("modelsel/mask_iconback.png", COLOR_THEME_SECONDARY1, COLOR_THEME_SECONDARY3); - // if (modelselIconBitmap) { - // BitmapBuffer * bitmap = BitmapBuffer::loadBitmap(getFilePath("modelsel/icon_default.png")); - // modelselIconBitmap->drawBitmap(20, 8, bitmap); - // delete bitmap; - // } - - delete modelselSdFreeBitmap; - modelselSdFreeBitmap = BitmapBuffer::loadMask(getFilePath("modelsel/mask_sdfree.png")); - - delete modelselModelQtyBitmap; - modelselModelQtyBitmap = BitmapBuffer::loadMask(getFilePath("modelsel/mask_modelqty.png")); - - delete modelselModelNameBitmap; - modelselModelNameBitmap = BitmapBuffer::loadMask(getFilePath("modelsel/mask_modelname.png")); - - delete modelselModelMoveBackground; - modelselModelMoveBackground = BitmapBuffer::loadMask(getFilePath("modelsel/mask_moveback.png")); - - delete modelselModelMoveIcon; - modelselModelMoveIcon = BitmapBuffer::loadMask(getFilePath("modelsel/mask_moveico.png")); - - delete modelselWizardBackground; - modelselWizardBackground = BitmapBuffer::loadBitmap(getFilePath("wizard/background.png")); - - // Channels monitor screen - delete chanMonLockedBitmap; - chanMonLockedBitmap = BitmapBuffer::loadMaskOnBackground("mask_monitor_lockch.png", COLOR_THEME_SECONDARY1, COLOR_THEME_SECONDARY3); - - delete chanMonInvertedBitmap; - chanMonInvertedBitmap = BitmapBuffer::loadMaskOnBackground("mask_monitor_inver.png", COLOR_THEME_SECONDARY1, COLOR_THEME_SECONDARY3); - - // Mixer setup screen - delete mixerSetupMixerBitmap; - mixerSetupMixerBitmap = BitmapBuffer::loadMaskOnBackground("mask_sbar_mixer.png", COLOR_THEME_SECONDARY1, COLOR_THEME_FOCUS); - - delete mixerSetupToBitmap; - mixerSetupToBitmap = BitmapBuffer::loadMaskOnBackground("mask_sbar_to.png", COLOR_THEME_SECONDARY1, COLOR_THEME_FOCUS); - - delete mixerSetupOutputBitmap; - mixerSetupOutputBitmap = BitmapBuffer::loadMaskOnBackground("mask_sbar_output.png", COLOR_THEME_SECONDARY1, COLOR_THEME_FOCUS); - - delete mixerSetupAddBitmap; - mixerSetupAddBitmap = BitmapBuffer::loadMaskOnBackground(getFilePath("mask_mplex_add.png"), COLOR_THEME_SECONDARY1, COLOR_THEME_SECONDARY3); - - delete mixerSetupMultiBitmap; - mixerSetupMultiBitmap = BitmapBuffer::loadMaskOnBackground(getFilePath("mask_mplex_multi.png"), COLOR_THEME_SECONDARY1, COLOR_THEME_SECONDARY3); - - delete mixerSetupReplaceBitmap; - mixerSetupReplaceBitmap = BitmapBuffer::loadMaskOnBackground(getFilePath("mask_mplex_replace.png"), COLOR_THEME_SECONDARY1, COLOR_THEME_SECONDARY3); - - delete mixerSetupLabelIcon; - mixerSetupLabelIcon = BitmapBuffer::loadMask(getFilePath("mask_textline_label.png")); - - // delete mixerSetupCurveIcon; - // mixerSetupCurveIcon = BitmapBuffer::loadMask(getFilePath("mask_textline_curve.png")); - - delete mixerSetupSwitchIcon; - mixerSetupSwitchIcon = BitmapBuffer::loadMask(getFilePath("mask_textline_switch.png")); - - // delete mixerSetupFlightmodeIcon; - // mixerSetupFlightmodeIcon = BitmapBuffer::loadMask(getFilePath("mask_textline_fm.png")); - -// delete mixerSetupSlowIcon; -// mixerSetupSlowIcon = BitmapBuffer::loadMask(getFilePath("mask_textline_slow.png")); -// -// delete mixerSetupDelayIcon; -// mixerSetupDelayIcon = BitmapBuffer::loadMask(getFilePath("mask_textline_delay.png")); -// -// delete mixerSetupDelaySlowIcon; -// mixerSetupDelaySlowIcon = BitmapBuffer::loadMask(getFilePath("mask_textline_delayslow.png")); - } - - void load() const override - { - loadColors(); - OpenTxTheme::load(); - if (!backgroundBitmap) { - backgroundBitmap = BitmapBuffer::loadBitmap(getFilePath("background.png")); - } - update(); - } - - virtual void update(bool reload = true) const override - { - TRACE("TODO THEME::UPDATE()"); - -#if 0 - uint32_t color = g_eeGeneral.themeData.options[1].unsignedValue; - uint32_t bg_color = UNEXPECTED_SHUTDOWN() ? WHITE : g_eeGeneral.themeData.options[0].unsignedValue; - - lcdColorTable[COLOR_THEME_SECONDARY3_INDEX] = bg_color; - lcdColorTable[COLOR_THEME_FOCUS_INDEX] = color; - lcdColorTable[COLOR_THEME_FOCUS_INDEX] = color; - lcdColorTable[COLOR_THEME_PRIMARY3_INDEX] = color; - lcdColorTable[COLOR_THEME_SECONDARY1_INDEX] = color; - lcdColorTable[COLOR_THEME_WARNING_INDEX] = color; - lcdColorTable[COLOR_THEME_SECONDARY1_INDEX] = color; - lcdColorTable[COLOR_THEME_PRIMARY3_INDEX] = - RGB(GET_RED(color)>>1, GET_GREEN(color)>>1, GET_BLUE(color)>>1); - lcdColorTable[COLOR_THEME_FOCUS_INDEX] = color; - lcdColorTable[COLOR_THEME_SECONDARY1_INDEX] = color; - #define DARKER(x) ((x * 70) / 100) - lcdColorTable[COLOR_THEME_FOCUS_INDEX] = RGB(DARKER(GET_RED(color)), DARKER(GET_GREEN(color)), DARKER(GET_BLUE(color))); - lcdColorTable[COLOR_THEME_SECONDARY1_INDEX] = color; - lcdColorTable[COLOR_THEME_FOCUS_INDEX] = color; -#endif - loadIcons(); - loadThemeBitmaps(); - } - - void drawBackground(BitmapBuffer * dc) const override - { - if (backgroundBitmap) { - dc->drawBitmap(0, 0, backgroundBitmap); - } - else { - lcdSetColor(g_eeGeneral.themeData.options[0].value.unsignedValue); - dc->drawSolidFilledRect(0, 0, LCD_W, LCD_H, CUSTOM_COLOR); - } - } - - void drawTopLeftBitmap(BitmapBuffer * dc) const override - { - if (topleftBitmap) { - dc->drawBitmap(0, 0, topleftBitmap); - uint16_t width = topleftBitmap->width(); - dc->drawSolidFilledRect(width, 0, LCD_W - width, MENU_HEADER_HEIGHT, COLOR_THEME_PRIMARY2); - } - } - - void drawPageHeaderBackground(BitmapBuffer *dc, uint8_t icon, - const char *title) const override - { - // if (topleftBitmap) { - // dc->drawBitmap(0, 0, topleftBitmap); - // uint16_t width = topleftBitmap->width(); - // dc->drawSolidFilledRect(width, 0, LCD_W-width, - // MENU_HEADER_HEIGHT, COLOR_THEME_FOCUS); - // } - // else { - dc->drawSolidFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, COLOR_THEME_FOCUS); - // } - // - // if (icon == ICON_OPENTX) - // dc->drawBitmap(4, 10, menuIconSelected[ICON_OPENTX]); - // else - // dc->drawBitmap(5, 7, menuIconSelected[icon]); - // - dc->drawSolidFilledRect(0, MENU_HEADER_HEIGHT, LCD_W, - MENU_TITLE_TOP - MENU_HEADER_HEIGHT, - COLOR_THEME_SECONDARY3); // the white separation line - dc->drawSolidFilledRect(0, MENU_TITLE_TOP, LCD_W, MENU_TITLE_HEIGHT, - COLOR_THEME_SECONDARY1); // the title line background - // - if (title) { - dc->drawText(MENUS_MARGIN_LEFT, MENU_TITLE_TOP + 1, title, COLOR_THEME_SECONDARY1); - } - } - - const BitmapBuffer * getIconMask(uint8_t index) const override - { - return iconMask[index]; - } - - const BitmapBuffer * getIcon(uint8_t index, IconState state) const override - { - return state == STATE_DEFAULT ? menuIconNormal[index] : menuIconSelected[index]; - } - - void drawCurrentMenuBackground(BitmapBuffer *dc) const override - { -// uint8_t padding_left = 4; -// -// dc->drawSolidFilledRect(0, 0, 4, MENU_HEADER_BUTTON_WIDTH, -// COLOR_THEME_FOCUS); -// for (unsigned i = 0; i < tabs.size(); i++) { -// dc->drawBitmap( -// padding_left + i * MENU_HEADER_BUTTON_WIDTH, 0, -// theme->getIcon(tabs[i]->getIcon(), -// currentIndex == i ? STATE_PRESSED : STATE_DEFAULT)); -// } - } - - void drawMenuDatetime(BitmapBuffer * dc) const - { - dc->drawSolidVerticalLine(DATETIME_SEPARATOR_X, 7, 31, COLOR_THEME_PRIMARY2); - - const TimerOptions timerOptions = {.options = SHOW_TIME}; - struct gtm t; - gettime(&t); - char str[10]; - -#if defined(TRANSLATIONS_CN) || defined(TRANSLATIONS_TW) - sprintf(str, "%d" TR_MONTH "%d", t.tm_mon + 1, t.tm_mday); -#else - sprintf(str, "%d %s", t.tm_mday, STR_MONTHS[t.tm_mon]); -#endif - dc->drawText(DATETIME_MIDDLE, DATETIME_LINE1, str, FONT(XS)|COLOR_THEME_PRIMARY2|CENTERED); - - getTimerString(str, getValue(MIXSRC_TX_TIME), timerOptions); - dc->drawText(DATETIME_MIDDLE, DATETIME_LINE2, str, FONT(XS)|COLOR_THEME_PRIMARY2|CENTERED); - } - - void drawProgressBar(BitmapBuffer *dc, coord_t x, coord_t y, coord_t w, - coord_t h, int value, int total) const override - { - dc->drawSolidRect(x, y, w, h, 1, COLOR_THEME_SECONDARY1); - if (value > 0) { - int width = (w * value) / total; - dc->drawSolidFilledRect(x + 2, y + 2, width - 4, h - 4, COLOR_THEME_FOCUS); - } - } - - protected: - static const BitmapBuffer * backgroundBitmap; - static BitmapBuffer * topleftBitmap; - static BitmapBuffer * menuIconNormal[MENUS_ICONS_COUNT]; - static BitmapBuffer * menuIconSelected[MENUS_ICONS_COUNT]; - static BitmapBuffer * iconMask[MENUS_ICONS_COUNT]; - static BitmapBuffer * currentMenuBackground; -}; - -const BitmapBuffer * FlyskyTheme::backgroundBitmap = nullptr; -BitmapBuffer * FlyskyTheme::topleftBitmap = nullptr; -BitmapBuffer * FlyskyTheme::iconMask[MENUS_ICONS_COUNT] = { nullptr }; -BitmapBuffer * FlyskyTheme::menuIconNormal[MENUS_ICONS_COUNT] = { nullptr }; -BitmapBuffer * FlyskyTheme::menuIconSelected[MENUS_ICONS_COUNT] = { nullptr }; -BitmapBuffer * FlyskyTheme::currentMenuBackground = nullptr; - -/*FlyskyTheme flyskyTheme; - -#if defined(PCBFLYSKY) -OpenTxTheme * defaultTheme = &flyskyTheme; -Theme * theme = &flyskyTheme; -#endif*/ diff --git a/radio/src/gui/colorlcd/throttle_params.cpp b/radio/src/gui/colorlcd/throttle_params.cpp index cbd1ef4c211..1051c959b1c 100644 --- a/radio/src/gui/colorlcd/throttle_params.cpp +++ b/radio/src/gui/colorlcd/throttle_params.cpp @@ -65,7 +65,7 @@ ThrottleParams::ThrottleParams() : Page(ICON_MODEL_SETUP) // Throttle reversed auto line = body.newLine(&grid); new StaticText(line, rect_t{}, STR_THROTTLEREVERSE, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_model.throttleReversed)); + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(g_model.throttleReversed)); // Throttle source line = body.newLine(&grid); @@ -78,7 +78,7 @@ ThrottleParams::ThrottleParams() : Page(ICON_MODEL_SETUP) // Throttle trim line = body.newLine(&grid); new StaticText(line, rect_t{}, STR_TTRIM, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_model.thrTrim)); + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(g_model.thrTrim)); // Throttle trim source line = body.newLine(&grid); diff --git a/radio/src/gui/colorlcd/timeedit.cpp b/radio/src/gui/colorlcd/timeedit.cpp index 1a67fcd34fb..7d44d70591f 100644 --- a/radio/src/gui/colorlcd/timeedit.cpp +++ b/radio/src/gui/colorlcd/timeedit.cpp @@ -19,7 +19,6 @@ * GNU General Public License for more details. */ -#include "libopenui_config.h" #include "timeedit.h" #include "strhelpers.h" @@ -33,21 +32,3 @@ TimeEdit::TimeEdit(Window * parent, const rect_t & rect, int32_t vmin, int32_t v return std::string(getTimerString(this->getValue(), timerOptions)); }); } - -// void TimeEdit::paint(BitmapBuffer * dc) -// { -// FormField::paint(dc); - -// LcdFlags textColor; -// if (editMode) -// textColor = COLOR_THEME_PRIMARY2; -// else if (hasFocus()) -// textColor = COLOR_THEME_PRIMARY2; -// else -// textColor = COLOR_THEME_SECONDARY1; - -// TimerOptions timerOptions; -// timerOptions.options = (textFlags & TIMEHOUR) != 0 ? SHOW_TIME : SHOW_TIMER; -// dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, -// getTimerString(getValue(), timerOptions), textColor); -// } diff --git a/radio/src/gui/colorlcd/timer_setup.cpp b/radio/src/gui/colorlcd/timer_setup.cpp index f8a410a29b3..2cef3b1389c 100644 --- a/radio/src/gui/colorlcd/timer_setup.cpp +++ b/radio/src/gui/colorlcd/timer_setup.cpp @@ -60,10 +60,7 @@ TimerWindow::TimerWindow(uint8_t timer) : Page(ICON_STATS_TIMERS) header.setTitle(STR_MENU_MODEL_SETUP); header.setTitle2(title2); - body.padAll(0); - lv_obj_set_scrollbar_mode(body.getLvObj(), LV_SCROLLBAR_MODE_AUTO); - - auto form = new FormGroup(&body, rect_t{}); + auto form = new FormWindow(&body, rect_t{}); form->setFlexLayout(); form->padAll(lv_dpx(8)); @@ -111,13 +108,13 @@ TimerWindow::TimerWindow(uint8_t timer) : Page(ICON_STATS_TIMERS) // Timer minute beep line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_MINUTEBEEP, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(p_timer->minuteBeep)); + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(p_timer->minuteBeep)); // Timer countdown line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_BEEPCOUNTDOWN, 0, COLOR_THEME_PRIMARY1); - auto box = new FormGroup(line, rect_t{}); + auto box = new FormWindow(line, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW); lv_obj_set_width(box->getLvObj(), LV_SIZE_CONTENT); diff --git a/radio/src/gui/colorlcd/topbar.cpp b/radio/src/gui/colorlcd/topbar.cpp index c61592aa3e4..6578b8f754a 100644 --- a/radio/src/gui/colorlcd/topbar.cpp +++ b/radio/src/gui/colorlcd/topbar.cpp @@ -35,7 +35,7 @@ Topbar * TopbarFactory::create(Window * parent) } SetupTopBarWidgetsPage::SetupTopBarWidgetsPage(): - FormWindow(ViewMain::instance(), rect_t{}, FORM_FORWARD_FOCUS) + FormWindow(ViewMain::instance(), rect_t{}) { // remember focus Layer::push(this); @@ -61,7 +61,7 @@ SetupTopBarWidgetsPage::SetupTopBarWidgetsPage(): this->deleteLater(); return 1; }, - NO_FOCUS | FORM_NO_BORDER, 0, window_create); + NO_FOCUS, 0, window_create); #endif } diff --git a/radio/src/gui/colorlcd/trainer_bluetooth.cpp b/radio/src/gui/colorlcd/trainer_bluetooth.cpp index e61173646da..31dcdd08803 100644 --- a/radio/src/gui/colorlcd/trainer_bluetooth.cpp +++ b/radio/src/gui/colorlcd/trainer_bluetooth.cpp @@ -75,7 +75,7 @@ void BTDiscoverMenu::selectAddr(const char* addr) } BluetoothTrainerWindow::BluetoothTrainerWindow(Window* parent) : - FormGroup(parent, rect_t{}) + FormWindow(parent, rect_t{}) { setFlexLayout(); FlexGridLayout grid(col_dsc, row_dsc, 2); diff --git a/radio/src/gui/colorlcd/trainer_bluetooth.h b/radio/src/gui/colorlcd/trainer_bluetooth.h index 6e39e0d20a4..818605b7ec7 100644 --- a/radio/src/gui/colorlcd/trainer_bluetooth.h +++ b/radio/src/gui/colorlcd/trainer_bluetooth.h @@ -26,7 +26,7 @@ #include "button.h" #include "bluetooth.h" -class BluetoothTrainerWindow : public FormGroup +class BluetoothTrainerWindow : public FormWindow { bool is_master = true; bool menuopened = false; diff --git a/radio/src/gui/colorlcd/trainer_setup.cpp b/radio/src/gui/colorlcd/trainer_setup.cpp index 6cf8f3bf69b..87203f3354f 100644 --- a/radio/src/gui/colorlcd/trainer_setup.cpp +++ b/radio/src/gui/colorlcd/trainer_setup.cpp @@ -41,10 +41,10 @@ static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(2), static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; -class TrainerModuleWindow : public FormGroup +class TrainerModuleWindow : public FormWindow { public: - TrainerModuleWindow(FormGroup* parent); + TrainerModuleWindow(FormWindow* parent); void checkEvents() override; void update(); @@ -70,8 +70,8 @@ class TrainerModuleWindow : public FormGroup #endif }; -TrainerModuleWindow::TrainerModuleWindow(FormGroup* parent) : - FormGroup(parent, rect_t{}) +TrainerModuleWindow::TrainerModuleWindow(FormWindow* parent) : + FormWindow(parent, rect_t{}) { setFlexLayout(); update(); @@ -100,7 +100,7 @@ void TrainerModuleWindow::checkEvents() // lastbluetoothstate = bluetooth.state; // } // #endif - FormGroup::checkEvents(); + FormWindow::checkEvents(); } void TrainerModuleWindow::update() @@ -146,7 +146,7 @@ TrainerPage::TrainerPage() : Page(ICON_MODEL_SETUP) header.setTitle(STR_MENU_MODEL_SETUP); header.setTitle2(STR_TRAINER); - auto form = new FormGroup(&body, rect_t{}); + auto form = new FormWindow(&body, rect_t{}); form->setFlexLayout(); form->padAll(lv_dpx(8)); diff --git a/radio/src/gui/colorlcd/trims_setup.cpp b/radio/src/gui/colorlcd/trims_setup.cpp index 6a593a49d84..25df41ef811 100644 --- a/radio/src/gui/colorlcd/trims_setup.cpp +++ b/radio/src/gui/colorlcd/trims_setup.cpp @@ -65,7 +65,7 @@ TrimsSetup::TrimsSetup() : Page(ICON_MODEL_SETUP) // Extended trims line = body.newLine(&grid); new StaticText(line, rect_t{}, STR_ETRIMS, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_model.extendedTrims)); + new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(g_model.extendedTrims)); // Display trims // TODO: move to "Screen setup" ? diff --git a/radio/src/gui/colorlcd/view_about.cpp b/radio/src/gui/colorlcd/view_about.cpp index 7cba4075a2a..88d450ae2f4 100644 --- a/radio/src/gui/colorlcd/view_about.cpp +++ b/radio/src/gui/colorlcd/view_about.cpp @@ -24,10 +24,9 @@ #include "opentx.h" #include "stamp.h" -const uint8_t _mask_qrcode[] = { +const uint8_t mask_qrcode[] = { #include "mask_qrcode.lbm" }; -STATIC_LZ4_BITMAP(mask_qrcode); #if defined(VERSION_TAG) const std::string about_str = "EdgeTX" " (" VERSION_TAG ")\n" "\"" CODENAME "\"" ; @@ -63,13 +62,12 @@ AboutUs::AboutUs() : messageWidget->setText(about_str + "\n" + copyright_str); - qrcode = BitmapBuffer::load8bitMaskOnBackground( - mask_qrcode, COLOR_THEME_SECONDARY1, COLOR_THEME_SECONDARY3); + qrcode = BitmapBuffer::load8bitMaskLZ4(mask_qrcode); new StaticBitmap(content, rect_t{content->width() / 2 - qrcode->width() / 2, TOP_PADDING + (NUM_LINES * PAGE_LINE_HEIGHT), qrcode->width(), qrcode->height()}, - qrcode); + qrcode, COLOR_THEME_SECONDARY1); } AboutUs::~AboutUs() { delete qrcode; } diff --git a/radio/src/gui/colorlcd/view_logical_switches.cpp b/radio/src/gui/colorlcd/view_logical_switches.cpp index 53a9bb4e928..1d350244de2 100644 --- a/radio/src/gui/colorlcd/view_logical_switches.cpp +++ b/radio/src/gui/colorlcd/view_logical_switches.cpp @@ -258,7 +258,7 @@ void LogicalSwitchesViewPage::build(FormWindow* window) form->padTop(3); FlexGridLayout grid(col_dsc, row_dsc, 2); - FormWindow::Line* line; + FormWindow::Line* line = nullptr; // Footer footer = new LogicalSwitchDisplayFooter( diff --git a/radio/src/gui/colorlcd/view_main.cpp b/radio/src/gui/colorlcd/view_main.cpp index 6c95e337eb7..aeca7c41d33 100644 --- a/radio/src/gui/colorlcd/view_main.cpp +++ b/radio/src/gui/colorlcd/view_main.cpp @@ -66,7 +66,7 @@ static void tile_view_scroll(lv_event_t* e) ViewMain * ViewMain::_instance = nullptr; ViewMain::ViewMain(): - Window(MainWindow::instance(), MainWindow::instance()->getRect(), NO_SCROLLBAR | OPAQUE) + Window(MainWindow::instance(), MainWindow::instance()->getRect(), OPAQUE) { Layer::push(this); @@ -388,7 +388,7 @@ void ViewMain::paint(BitmapBuffer * dc) dc->getOffsetX(), dc->getOffsetY()); // TODO: set it as "window background" w/ LVGL - OpenTxTheme::instance()->drawBackground(dc); + EdgeTxTheme::instance()->drawBackground(dc); } void ViewMain::ws_timer(lv_timer_t* t) diff --git a/radio/src/gui/colorlcd/view_main_decoration.cpp b/radio/src/gui/colorlcd/view_main_decoration.cpp index 572a59b4102..e7862d418ae 100644 --- a/radio/src/gui/colorlcd/view_main_decoration.cpp +++ b/radio/src/gui/colorlcd/view_main_decoration.cpp @@ -99,7 +99,7 @@ void ViewMainDecoration::setFlightModeVisible(bool visible) } } -void ViewMainDecoration::setFlightModeColor() +void ViewMainDecoration::updateFromTheme() { // Hack to fix flight mode color on main view // Required because theme is loaded after the main view has been created @@ -131,32 +131,18 @@ rect_t ViewMainDecoration::getMainZone() const void ViewMainDecoration::createSliders(Window* ml, Window* mr, Window* bl, Window* bc, Window* br) { - // TODO: make dynamic - //uint8_t pot_idx = 0; - Window* sl = new MainViewHorizontalSlider(bl, 0); - sl->updateSize(); - sliders[0] = sl; + sliders[0] = new MainViewHorizontalSlider(bl, 0); - if (!IS_POT_AVAILABLE(2)) { + if (!IS_POT_AVAILABLE(2)) bc = br; - } - - if (IS_POT_MULTIPOS(1)) { - sl = new MainView6POS(bc, 1); - sl->updateSize(); - sliders[1] = sl; - } - else if (IS_POT_AVAILABLE(1)) { - sl = new MainViewHorizontalSlider(bc, 1); - sl->updateSize(); - sliders[1] = sl; - } + + if (IS_POT_MULTIPOS(1)) + sliders[1] = new MainView6POS(bc, 1); + else if (IS_POT_AVAILABLE(1)) + sliders[1] = new MainViewHorizontalSlider(bc, 1); - if (IS_POT_AVAILABLE(2)) { - sl = new MainViewHorizontalSlider(br, 2); - sl->updateSize(); - sliders[2] = sl; - } + if (IS_POT_AVAILABLE(2)) + sliders[2] = new MainViewHorizontalSlider(br, 2); // TODO: check how many pots are configured instead auto max_pots = adcGetMaxInputs(ADC_INPUT_POT); @@ -169,40 +155,30 @@ void ViewMainDecoration::createSliders(Window* ml, Window* mr, Window* bl, Windo auto rightPots = create_layout_box(mr, LV_ALIGN_RIGHT_MID, LV_FLEX_FLOW_COLUMN); rightPots->setHeight(VERTICAL_SLIDERS_HEIGHT); - for (int i = 3; i <= 6; i++) { - if (IS_POT_AVAILABLE(i)) { - sl = new MainViewVerticalSlider(i & 1 ? leftPots : rightPots, i); - sliders[i] = sl; - } - } + coord_t lsh = (IS_POT_AVAILABLE(5)) ? VERTICAL_SLIDERS_HEIGHT / 2 : VERTICAL_SLIDERS_HEIGHT; + coord_t rsh = (IS_POT_AVAILABLE(6)) ? VERTICAL_SLIDERS_HEIGHT / 2 : VERTICAL_SLIDERS_HEIGHT; - // update size AFTER all pots/sliders are created - for (int i = 3; i <= 6; i++) { - if (sliders[i] != nullptr) - sliders[i]->updateSize(); - } + if (IS_POT_AVAILABLE(3)) + sliders[3] = new MainViewVerticalSlider(leftPots, rect_t{0, 0, TRIM_SQUARE_SIZE, lsh}, 3); + + if (IS_POT_AVAILABLE(4)) + sliders[4] = new MainViewVerticalSlider(rightPots, rect_t{0, 0, TRIM_SQUARE_SIZE, rsh}, 4); + + if (IS_POT_AVAILABLE(5)) + sliders[5] = new MainViewVerticalSlider(leftPots, rect_t{0, 0, TRIM_SQUARE_SIZE, lsh}, 5); + + if (IS_POT_AVAILABLE(6)) + sliders[6] = new MainViewVerticalSlider(rightPots, rect_t{0, 0, TRIM_SQUARE_SIZE, rsh}, 6); } } void ViewMainDecoration::createTrims(Window* ml, Window* mr, Window* bl, Window* br) { // Trim order TRIM_LH, TRIM_LV, TRIM_RV, TRIM_RH - - Window* tr = new MainViewHorizontalTrim(bl, TRIMS_LH); - tr->updateSize(); - trims[TRIMS_LH] = tr; - - tr = new MainViewHorizontalTrim(br, TRIMS_RH); - tr->updateSize(); - trims[TRIMS_RH] = tr; - - tr = new MainViewVerticalTrim(ml, TRIMS_LV); - tr->updateSize(); - trims[TRIMS_LV] = tr; - - tr = new MainViewVerticalTrim(mr, TRIMS_RV); - tr->updateSize(); - trims[TRIMS_RV] = tr; + trims[TRIMS_LH] = new MainViewHorizontalTrim(bl, TRIMS_LH); + trims[TRIMS_RH] = new MainViewHorizontalTrim(br, TRIMS_RH); + trims[TRIMS_LV] = new MainViewVerticalTrim(ml, TRIMS_LV); + trims[TRIMS_RV] = new MainViewVerticalTrim(mr, TRIMS_RV); } void ViewMainDecoration::createFlightMode(Window* bc) diff --git a/radio/src/gui/colorlcd/view_main_decoration.h b/radio/src/gui/colorlcd/view_main_decoration.h index 6d63472a27c..6f09fe6782c 100644 --- a/radio/src/gui/colorlcd/view_main_decoration.h +++ b/radio/src/gui/colorlcd/view_main_decoration.h @@ -34,17 +34,14 @@ class ViewMainDecoration void setTrimsVisible(bool visible); void setSlidersVisible(bool visible); void setFlightModeVisible(bool visible); - void setFlightModeColor(); + void updateFromTheme(); // Get the available space in the middle of the screen // (without decoration) rect_t getMainZone() const; - - protected: - enum { SLIDERS_POT1 = 0, SLIDERS_POT2, diff --git a/radio/src/gui/colorlcd/view_main_menu.cpp b/radio/src/gui/colorlcd/view_main_menu.cpp index 1ed70550157..d5efe112b5e 100644 --- a/radio/src/gui/colorlcd/view_main_menu.cpp +++ b/radio/src/gui/colorlcd/view_main_menu.cpp @@ -101,7 +101,7 @@ ViewMainMenu::ViewMainMenu(Window* parent, std::function closeHandler) : return 0; }); - carousel->addButton(ICON_OPENTX, STR_MAIN_MENU_ABOUT_EDGETX, [=]() -> uint8_t { + carousel->addButton(ICON_EDGETX, STR_MAIN_MENU_ABOUT_EDGETX, [=]() -> uint8_t { deleteLater(); new AboutUs(); return 0; diff --git a/radio/src/gui/colorlcd/view_statistics.cpp b/radio/src/gui/colorlcd/view_statistics.cpp index 1943d9fa737..7d4409d6c23 100644 --- a/radio/src/gui/colorlcd/view_statistics.cpp +++ b/radio/src/gui/colorlcd/view_statistics.cpp @@ -203,7 +203,7 @@ void StatisticsViewPage::build(FormWindow* window) line = form->newLine(&grid); line->padAll(0); - line->padTop(4); + line->padTop(3); // Throttle curve auto curve = new ThrottleCurveWindow(line, {0, 0, CV_WIDTH, CV_HEIGHT}); @@ -213,7 +213,7 @@ void StatisticsViewPage::build(FormWindow* window) line = form->newLine(&grid); line->padAll(0); - line->padTop(8); + line->padTop(3); // Reset auto btn = new TextButton(line, rect_t{0, 0, 0, 24}, STR_MENUTORESET, @@ -229,7 +229,7 @@ void StatisticsViewPage::build(FormWindow* window) }); lv_obj_set_grid_cell(btn->getLvObj(), LV_GRID_ALIGN_STRETCH, 0, 4, - LV_GRID_ALIGN_CENTER, 0, 1); + LV_GRID_ALIGN_START, 0, 1); } void DebugViewPage::build(FormWindow* window) diff --git a/radio/src/gui/colorlcd/view_text.cpp b/radio/src/gui/colorlcd/view_text.cpp index f4e633ca539..acf47397d58 100644 --- a/radio/src/gui/colorlcd/view_text.cpp +++ b/radio/src/gui/colorlcd/view_text.cpp @@ -20,7 +20,6 @@ #include "view_text.h" -#include "gridlayout.h" #include "menu.h" #include "opentx.h" #include "sdcard.h" diff --git a/radio/src/gui/colorlcd/widget.cpp b/radio/src/gui/colorlcd/widget.cpp index a2d2b11277c..87adb93ec8b 100644 --- a/radio/src/gui/colorlcd/widget.cpp +++ b/radio/src/gui/colorlcd/widget.cpp @@ -74,7 +74,7 @@ void Widget::paint(BitmapBuffer * dc) { if (fullscreen) { // Draw background screen bellow - OpenTxTheme::instance()->drawBackground(dc); + EdgeTxTheme::instance()->drawBackground(dc); } // refresh the widget diff --git a/radio/src/gui/colorlcd/widget_settings.cpp b/radio/src/gui/colorlcd/widget_settings.cpp index bf351a0aad3..e9cc5c07afa 100644 --- a/radio/src/gui/colorlcd/widget_settings.cpp +++ b/radio/src/gui/colorlcd/widget_settings.cpp @@ -87,7 +87,7 @@ WidgetSettings::WidgetSettings(Window* parent, Widget* widget) : break; case ZoneOption::Bool: - new CheckBox( + new ToggleSwitch( line, rect_t{}, [=]() -> uint8_t { return (uint8_t)widget->getOptionValue(optIdx)->boolValue; diff --git a/radio/src/gui/colorlcd/widgets/widgets_container_impl.h b/radio/src/gui/colorlcd/widgets/widgets_container_impl.h index 03230044c1e..6764f265b4d 100644 --- a/radio/src/gui/colorlcd/widgets/widgets_container_impl.h +++ b/radio/src/gui/colorlcd/widgets/widgets_container_impl.h @@ -33,7 +33,7 @@ class WidgetsContainerImpl : public WidgetsContainer WidgetsContainerImpl(Window* parent, const rect_t& rect, PersistentData* persistentData) : - WidgetsContainer(parent, rect, NO_FOCUS | FORM_FORWARD_FOCUS), + WidgetsContainer(parent, rect, NO_FOCUS), persistentData(persistentData) { } diff --git a/radio/src/gui/colorlcd/widgets_container.h b/radio/src/gui/colorlcd/widgets_container.h index 79f736397d4..ed8046aea97 100644 --- a/radio/src/gui/colorlcd/widgets_container.h +++ b/radio/src/gui/colorlcd/widgets_container.h @@ -23,7 +23,7 @@ #define _WIDGETS_CONTAINER_H_ #include -#include "libopenui_types.h" +#include "opentx_types.h" #include "form.h" #include "zone.h" diff --git a/radio/src/gui/colorlcd/widgets_setup.cpp b/radio/src/gui/colorlcd/widgets_setup.cpp index 44553ad383b..aa9a6388bfb 100644 --- a/radio/src/gui/colorlcd/widgets_setup.cpp +++ b/radio/src/gui/colorlcd/widgets_setup.cpp @@ -31,7 +31,7 @@ #include "gui.h" #include "translations.h" -SetupWidgetsPageSlot::SetupWidgetsPageSlot(FormGroup* parent, +SetupWidgetsPageSlot::SetupWidgetsPageSlot(FormWindow* parent, const rect_t& rect, WidgetsContainer* container, uint8_t slotIndex) : @@ -75,7 +75,7 @@ void SetupWidgetsPageSlot::paint(BitmapBuffer* dc) } SetupWidgetsPage::SetupWidgetsPage(uint8_t customScreenIdx) : - FormWindow(ViewMain::instance(), {0, 0, 0, 0}, FORM_FORWARD_FOCUS), + FormWindow(ViewMain::instance(), rect_t{}), customScreenIdx(customScreenIdx) { Layer::push(this); @@ -103,7 +103,7 @@ SetupWidgetsPage::SetupWidgetsPage(uint8_t customScreenIdx) : this->deleteLater(); return 1; }, - NO_FOCUS | FORM_NO_BORDER, + NO_FOCUS, 0, window_create); #endif } diff --git a/radio/src/gui/colorlcd/widgets_setup.h b/radio/src/gui/colorlcd/widgets_setup.h index 3ffed7fcf3b..3bea09155f9 100644 --- a/radio/src/gui/colorlcd/widgets_setup.h +++ b/radio/src/gui/colorlcd/widgets_setup.h @@ -52,7 +52,7 @@ class SetupWidgetsPage : public FormWindow class SetupWidgetsPageSlot : public Button { public: - SetupWidgetsPageSlot(FormGroup* parent, const rect_t& rect, + SetupWidgetsPageSlot(FormWindow* parent, const rect_t& rect, WidgetsContainer* container, uint8_t slotIndex); void paint(BitmapBuffer* dc) override; diff --git a/radio/src/keys.h b/radio/src/keys.h index ea146282d47..406b442e730 100644 --- a/radio/src/keys.h +++ b/radio/src/keys.h @@ -24,7 +24,6 @@ #include #include "opentx_types.h" -#include "libopenui/src/libopenui_types.h" #include "hal/key_driver.h" diff --git a/radio/src/lua/api_colorlcd.cpp b/radio/src/lua/api_colorlcd.cpp index b2018911331..09cfc62bf46 100644 --- a/radio/src/lua/api_colorlcd.cpp +++ b/radio/src/lua/api_colorlcd.cpp @@ -971,7 +971,7 @@ static int luaLcdSetColor(lua_State *L) if (index < LCD_COLOR_COUNT && lcdColorTable[index] != color) { lcdColorTable[index] = color; if (index != CUSTOM_COLOR_INDEX) - OpenTxTheme::instance()->update(false); + EdgeTxTheme::instance()->update(false); } return 0; } diff --git a/radio/src/lua/lua_api.h b/radio/src/lua/lua_api.h index 3e992c69417..a80afede465 100644 --- a/radio/src/lua/lua_api.h +++ b/radio/src/lua/lua_api.h @@ -73,7 +73,6 @@ extern bool luaLcdAllowed; #define INVERS 0x01u #define BLINK 0x1000u -#define RGB_FLAG 0x8000u extern bool luaLcdAllowed; diff --git a/radio/src/lv_conf.h b/radio/src/lv_conf.h index ee6da4dd68a..120cab1597e 100644 --- a/radio/src/lv_conf.h +++ b/radio/src/lv_conf.h @@ -571,9 +571,9 @@ #define LV_LABEL_LONG_TXT_HINT 1 /*Store some extra info in labels to speed up drawing of very long texts*/ #endif -#define LV_USE_LINE 1 +#define LV_USE_LINE 0 -#define LV_USE_ROLLER 1 /*Requires: lv_label*/ +#define LV_USE_ROLLER 0 /*Requires: lv_label*/ #if LV_USE_ROLLER #define LV_ROLLER_INF_PAGES 7 /*Number of extra "pages" when the roller is infinite*/ #endif @@ -612,7 +612,7 @@ #define LV_USE_CHART 0 -#define LV_USE_COLORWHEEL 1 +#define LV_USE_COLORWHEEL 0 #define LV_USE_IMGBTN 0 @@ -620,7 +620,7 @@ #define LV_USE_LED 0 -#define LV_USE_LIST 1 +#define LV_USE_LIST 0 #define LV_USE_MENU 0 @@ -628,7 +628,7 @@ #define LV_USE_MSGBOX 0 -#define LV_USE_SPINBOX 1 +#define LV_USE_SPINBOX 0 #define LV_USE_SPINNER 0 diff --git a/radio/src/main.cpp b/radio/src/main.cpp index a7df1c5dbcf..0957794f4fc 100644 --- a/radio/src/main.cpp +++ b/radio/src/main.cpp @@ -558,7 +558,7 @@ void perMain() #if defined(LIBOPENUI) // draw some image showing USB lcdInitDirectDrawing(); - OpenTxTheme::instance()->drawUsbPluggedScreen(lcd); + EdgeTxTheme::instance()->drawUsbPluggedScreen(lcd); lcdRefresh(); #else // disable access to menus diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 7bb9a6c5c7d..219f9b9e562 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -323,8 +323,8 @@ void generalDefault() #endif #if defined(COLORLCD) - strcpy(g_eeGeneral.themeName, static_cast(theme)->getName()); - static_cast(theme)->init(); + strcpy(g_eeGeneral.themeName, static_cast(theme)->getName()); + static_cast(theme)->init(); #endif #if defined(PXX2) diff --git a/radio/src/opentx_helpers.h b/radio/src/opentx_helpers.h index 5f1bfd29140..082698887fe 100644 --- a/radio/src/opentx_helpers.h +++ b/radio/src/opentx_helpers.h @@ -19,32 +19,53 @@ * GNU General Public License for more details. */ -#ifndef _OPENTX_HELPERS_H_ -#define _OPENTX_HELPERS_H_ +#pragma once -#include +#include +#include -#if defined(COLORLCD) -#include "thirdparty/libopenui/src/libopenui_helpers.h" -#else template inline T sgn(T a) { return a > 0 ? 1 : (a < 0 ? -1 : 0); } -template inline t min(t a, t b) { return a inline t max(t a, t b) { return a>b?a:b; } -template inline t limit(t mi, t x, t ma) { return min(max(mi,x),ma); } +template +inline T min(T a, T b) +{ + return a < b ? a : b; +} + +template +inline T max(T a, T b) +{ + return a > b ? a : b; +} + +template +inline T limit(T vmin, T x, T vmax) +{ + return min(max(vmin, x), vmax); +} -inline int divRoundClosest(const int n, const int d) +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); } -#endif + +inline unsigned align32(unsigned n) +{ + unsigned rest = (n & 3u); + return rest ? n + 4u - rest : n; +} + +inline std::string TEXT_AT_INDEX(const char *const *val, uint8_t idx) +{ + return std::string(val[idx]); +} template inline void SWAP(T & a, T & b) @@ -100,5 +121,3 @@ class CircularBuffer { return true; } }; - -#endif diff --git a/radio/src/opentx_types.h b/radio/src/opentx_types.h index 352a53ad8df..4f556d12c04 100644 --- a/radio/src/opentx_types.h +++ b/radio/src/opentx_types.h @@ -19,10 +19,68 @@ * GNU General Public License for more details. */ -#ifndef _OPENTX_TYPES_H_ -#define _OPENTX_TYPES_H_ +#pragma once -#include "thirdparty/libopenui/src/libopenui_types.h" +#include + +typedef int coord_t; + +#if defined(COLORLCD) +typedef uint16_t pixel_t; +#else +typedef uint8_t pixel_t; +#endif + +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; typedef uint32_t tmr10ms_t; typedef int32_t getvalue_t; @@ -51,5 +109,3 @@ typedef uint64_t swarnstate_t; // pot warning enabled: 1 bit per pot typedef uint8_t potwarnen_t; #endif - -#endif // _OPENTX_TYPES_H_ diff --git a/radio/src/storage/sdcard_common.cpp b/radio/src/storage/sdcard_common.cpp index 6586d6d8af0..4695dfd15ac 100644 --- a/radio/src/storage/sdcard_common.cpp +++ b/radio/src/storage/sdcard_common.cpp @@ -39,7 +39,7 @@ void storageEraseAll(bool warn) #if defined(COLORLCD) // the theme has not been loaded before - static_cast(theme)->load(); + static_cast(theme)->load(); #endif // Init backlight mode before entering alert screens diff --git a/radio/src/targets/horus/board.h b/radio/src/targets/horus/board.h index e475191a6da..4dcbab1c12f 100644 --- a/radio/src/targets/horus/board.h +++ b/radio/src/targets/horus/board.h @@ -238,13 +238,18 @@ void ledBlue(); #define LCD_PHYS_H LCD_H #define LCD_PHYS_W LCD_W #define LCD_DEPTH 16 + void lcdInit(); void lcdCopy(void * dest, void * src); + void DMAFillRect(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color); 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 DMABitmapConvert(uint16_t * dest, const uint8_t * src, uint16_t w, uint16_t h, uint32_t format); + #define lcdOff() backlightEnable(0) /* just disable the backlight */ + #define lcdRefreshWait(...) // Backlight driver diff --git a/radio/src/targets/horus/lcd_driver.cpp b/radio/src/targets/horus/lcd_driver.cpp index f5e990a193a..e807e50f168 100644 --- a/radio/src/targets/horus/lcd_driver.cpp +++ b/radio/src/targets/horus/lcd_driver.cpp @@ -20,7 +20,6 @@ */ #include "opentx_types.h" -#include "libopenui_config.h" #include "lcd.h" #include diff --git a/radio/src/targets/horus/libopenui_config.h b/radio/src/targets/horus/libopenui_config.h index 719778f1481..3ad23525295 100644 --- a/radio/src/targets/horus/libopenui_config.h +++ b/radio/src/targets/horus/libopenui_config.h @@ -21,121 +21,27 @@ #pragma once -#include "debug.h" -#include "libopenui_defines.h" - -#include "colors.h" -#include "board.h" -#include "keys.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 -}; - -typedef uint16_t pixel_t; - -constexpr bool WRAP_FORM_FIELDS_WITHIN_PAGE = true; -constexpr short SLIDE_SPEED_REDUCTION = 5; - -constexpr uint32_t MENU_HEADER_BUTTON_WIDTH = 33; -constexpr uint32_t MENU_HEADER_BUTTONS_LEFT = 47; - -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_CONTENT_TOP = MENU_BODY_TOP + 1; -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 coord_t MENUS_SEPARATOR_HEIGHT = 15; - -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 LABELS_LINE_HEIGHT = 30; -constexpr uint32_t PAGE_LINE_HEIGHT = 20; -constexpr coord_t LINE_HEIGHT = PAGE_LINE_HEIGHT; - -constexpr uint32_t PAGE_LINE_SPACING = 2; -constexpr uint32_t PAGE_INDENT_WIDTH = 10; -constexpr uint32_t PAGE_LABEL_WIDTH = 240; -constexpr uint32_t FH = PAGE_LINE_HEIGHT; -constexpr uint32_t NUM_BODY_LINES = MENU_BODY_HEIGHT / PAGE_LINE_HEIGHT; -constexpr uint32_t TEXT_VIEWER_LINES = (MENU_FOOTER_TOP - MENU_HEADER_HEIGHT) / FH; - -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 RSSI_X = LCD_W - 90; constexpr uint32_t AUDIO_X = LCD_W - 130; constexpr uint32_t USB_X = LCD_W - 98; constexpr uint32_t LOG_X = LCD_W - 98; constexpr uint32_t GPS_X = LCD_W - 148; -constexpr uint32_t MENUS_TOOLBAR_BUTTON_WIDTH = 30; -constexpr uint32_t MENUS_TOOLBAR_BUTTON_PADDING = 3; -constexpr rect_t MENUS_TOOLBAR_RECT = { 100, 51, 30, 209 }; - constexpr uint32_t ALERT_FRAME_TOP = 70; constexpr uint32_t ALERT_FRAME_HEIGHT = (LCD_H - 2 * ALERT_FRAME_TOP); constexpr uint32_t ALERT_BITMAP_TOP = ALERT_FRAME_TOP + 15; constexpr uint32_t ALERT_BITMAP_LEFT = 40; constexpr uint32_t ALERT_TITLE_TOP = ALERT_FRAME_TOP + 10; constexpr uint32_t ALERT_TITLE_LEFT = 186; -constexpr uint32_t ALERT_TITLE_LINE_HEIGHT = 30; constexpr uint32_t ALERT_MESSAGE_TOP = ALERT_TITLE_TOP + 90; constexpr uint32_t ALERT_MESSAGE_LEFT = ALERT_TITLE_LEFT; -constexpr uint32_t ALERT_ACTION_TOP = 240; -constexpr uint32_t ALERT_BUTTON_TOP = 300; - -constexpr uint32_t PAGE_TITLE_TOP = 2; -constexpr uint32_t PAGE_TITLE_LEFT = 50; - -constexpr uint32_t INPUT_EDIT_LABELS_WIDTH = 120; constexpr coord_t INPUT_EDIT_CURVE_WIDTH = 132; constexpr coord_t INPUT_EDIT_CURVE_HEIGHT = INPUT_EDIT_CURVE_WIDTH; -constexpr coord_t INPUT_EDIT_CURVE_LEFT = PAGE_PADDING; -constexpr coord_t INPUT_EDIT_CURVE_TOP = MENU_HEADER_HEIGHT + PAGE_PADDING; constexpr coord_t MENUS_LINE_HEIGHT = 30; constexpr coord_t MENUS_WIDTH = 200; -constexpr coord_t POPUP_HEADER_HEIGHT = 30; constexpr coord_t MENUS_MAX_HEIGHT = LCD_H * 0.9; -constexpr coord_t MODEL_SELECT_FOOTER_HEIGHT = 24; -constexpr coord_t SCROLLBAR_WIDTH = 3; -constexpr coord_t TABLE_LINE_HEIGHT = 50; -constexpr coord_t TABLE_HEADER_HEIGHT = 48; -constexpr coord_t ROLLER_LINE_HEIGHT = 40; - -constexpr LcdFlags MENU_HEADER_FONT = FONT(BOLD); -constexpr LcdFlags MENU_FONT = FONT(STD); -constexpr LcdFlags TABLE_HEADER_FONT = FONT(STD); -constexpr LcdFlags TABLE_BODY_FONT = FONT(STD); +constexpr rect_t MENUS_TOOLBAR_RECT = { 100, 51, 30, 209 }; -constexpr int CJK_FIRST_LETTER_INDEX = 128 - 32 + 21; -constexpr coord_t CHAR_SPACING = 0; +#define ROTARY_ENCODER_SPEED() rotencSpeed diff --git a/radio/src/targets/nv14/board.h b/radio/src/targets/nv14/board.h index 05356599019..4aa91e7fdde 100644 --- a/radio/src/targets/nv14/board.h +++ b/radio/src/targets/nv14/board.h @@ -206,12 +206,16 @@ const etx_serial_port_t* auxSerialGetPort(int port_nr); void lcdInit(); void lcdCopy(void * dest, void * src); + void DMAFillRect(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color); 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 DMABitmapConvert(uint16_t * dest, const uint8_t * src, uint16_t w, uint16_t h, uint32_t format); + void lcdOff(); void lcdOn(); + #define lcdRefreshWait(...) // Backlight driver diff --git a/radio/src/targets/nv14/lcd_driver.cpp b/radio/src/targets/nv14/lcd_driver.cpp index ab0ff76a285..986918c21ed 100644 --- a/radio/src/targets/nv14/lcd_driver.cpp +++ b/radio/src/targets/nv14/lcd_driver.cpp @@ -20,8 +20,6 @@ */ #include "opentx_types.h" -#include "libopenui_config.h" - #include "lcd.h" #include "lcd_driver.h" diff --git a/radio/src/targets/nv14/libopenui_config.h b/radio/src/targets/nv14/libopenui_config.h index 87d05d2833c..cc9d1cf442b 100644 --- a/radio/src/targets/nv14/libopenui_config.h +++ b/radio/src/targets/nv14/libopenui_config.h @@ -21,120 +21,28 @@ #pragma once -#include "debug.h" -#include "libopenui_defines.h" - -#include "colors.h" -#include "board.h" -#include "keys.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 -}; - -typedef uint16_t pixel_t; - -constexpr bool WRAP_FORM_FIELDS_WITHIN_PAGE = true; -constexpr short SLIDE_SPEED_REDUCTION = 5; - -constexpr uint32_t MENU_HEADER_BUTTON_WIDTH = 33; -constexpr uint32_t MENU_HEADER_BUTTONS_LEFT = 47; - -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_CONTENT_TOP = MENU_BODY_TOP + 1; -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 coord_t MENUS_SEPARATOR_HEIGHT = 15; - -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 PAGE_LINE_SPACING = 2; -constexpr uint32_t PAGE_INDENT_WIDTH = 10; -constexpr uint32_t PAGE_LABEL_WIDTH = 140; -constexpr uint32_t FH = PAGE_LINE_HEIGHT; -constexpr uint32_t NUM_BODY_LINES = MENU_BODY_HEIGHT / PAGE_LINE_HEIGHT; -constexpr uint32_t TEXT_VIEWER_LINES = (MENU_FOOTER_TOP - MENU_HEADER_HEIGHT) / FH; - -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 coord_t LINE_HEIGHT = PAGE_LINE_HEIGHT; - constexpr uint32_t RSSI_X = LCD_W - 80; constexpr uint32_t AUDIO_X = LCD_W - 115; constexpr uint32_t USB_X = LCD_W - 82; constexpr uint32_t LOG_X = LCD_W - 82; constexpr uint32_t GPS_X = LCD_W - 130; -constexpr uint32_t MENUS_TOOLBAR_BUTTON_WIDTH = 30; -constexpr uint32_t MENUS_TOOLBAR_BUTTON_PADDING = 3; - constexpr uint32_t ALERT_FRAME_TOP = 70; constexpr uint32_t ALERT_FRAME_HEIGHT = (LCD_H - 2 * ALERT_FRAME_TOP); constexpr uint32_t ALERT_BITMAP_TOP = ALERT_FRAME_TOP + 15; constexpr uint32_t ALERT_BITMAP_LEFT = 15; constexpr uint32_t ALERT_TITLE_TOP = ALERT_FRAME_TOP + 10; constexpr uint32_t ALERT_TITLE_LEFT = 140; -constexpr uint32_t ALERT_TITLE_LINE_HEIGHT = 30; constexpr uint32_t ALERT_MESSAGE_TOP = ALERT_TITLE_TOP + 130; constexpr uint32_t ALERT_MESSAGE_LEFT = 15; -constexpr uint32_t ALERT_ACTION_TOP = 240; -constexpr uint32_t ALERT_BUTTON_TOP = 300; -constexpr uint32_t PAGE_TITLE_TOP = 2; -constexpr uint32_t PAGE_TITLE_LEFT = 50; - -constexpr uint32_t INPUT_EDIT_LABELS_WIDTH = 80; constexpr coord_t INPUT_EDIT_CURVE_WIDTH = 176; constexpr coord_t INPUT_EDIT_CURVE_HEIGHT = 132; -constexpr coord_t INPUT_EDIT_CURVE_LEFT = PAGE_PADDING; -constexpr coord_t INPUT_EDIT_CURVE_TOP = MENU_HEADER_HEIGHT + PAGE_PADDING; constexpr coord_t MENUS_LINE_HEIGHT = 40; constexpr coord_t MENUS_WIDTH = 200; -constexpr coord_t POPUP_HEADER_HEIGHT = 30; constexpr coord_t MENUS_MAX_HEIGHT = 7 * MENUS_LINE_HEIGHT - 1; constexpr rect_t MENUS_TOOLBAR_RECT = { 35, (LCD_H - MENUS_MAX_HEIGHT) / 2, 50, MENUS_MAX_HEIGHT }; -constexpr coord_t MODEL_SELECT_FOOTER_HEIGHT = 24; -constexpr coord_t SCROLLBAR_WIDTH = 3; -constexpr coord_t TABLE_LINE_HEIGHT = 50; -constexpr coord_t TABLE_HEADER_HEIGHT = 48; - -constexpr coord_t ROLLER_LINE_HEIGHT = 40; - -constexpr LcdFlags MENU_HEADER_FONT = FONT(BOLD); -constexpr LcdFlags MENU_FONT = FONT(STD); -constexpr LcdFlags TABLE_HEADER_FONT = FONT(STD); -constexpr LcdFlags TABLE_BODY_FONT = FONT(STD); - -constexpr int CJK_FIRST_LETTER_INDEX = 128 - 32 + 21; -constexpr coord_t CHAR_SPACING = 0; +// Disable rotary encoder, as the NV14 does not have one +#define ROTARY_ENCODER_SPEED() 0 diff --git a/radio/src/thirdparty/libopenui/src/CMakeLists.txt b/radio/src/thirdparty/libopenui/src/CMakeLists.txt index 2d4891572bd..cde31ffa1e3 100644 --- a/radio/src/thirdparty/libopenui/src/CMakeLists.txt +++ b/radio/src/thirdparty/libopenui/src/CMakeLists.txt @@ -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) diff --git a/radio/src/thirdparty/libopenui/src/basenumberedit.h b/radio/src/thirdparty/libopenui/src/basenumberedit.h deleted file mode 100644 index 8dac05573e3..00000000000 --- a/radio/src/thirdparty/libopenui/src/basenumberedit.h +++ /dev/null @@ -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 getValue, - std::function 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 handler) - { - _setValue = std::move(handler); - } - - void setGetValueHandler(std::function 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 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 _getValue; - std::function _setValue; - std::function displayFunction; -}; diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index 6efc0ef674d..6afefb99da0 100644 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -19,9 +19,9 @@ #include #include +#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" diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.h b/radio/src/thirdparty/libopenui/src/bitmapbuffer.h index ebf481b4f03..4bb45187c26 100644 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.h +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.h @@ -21,10 +21,9 @@ #include #include #include -#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; diff --git a/radio/src/thirdparty/libopenui/src/bufferedwindow.h b/radio/src/thirdparty/libopenui/src/bufferedwindow.h deleted file mode 100644 index 8251d2dad08..00000000000 --- a/radio/src/thirdparty/libopenui/src/bufferedwindow.h +++ /dev/null @@ -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 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 OpaqueBufferedWindow: public BufferedWindow -{ - public: - using BufferedWindow::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 TransparentBufferedWindow: public BufferedWindow -{ - public: - using BufferedWindow::BufferedWindow; - - void paint(BitmapBuffer * dc) override - { - if (!BufferedWindow::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 -{ - public: - TransparentBitmapBackground(Window * parent, const rect_t & rect, const BitmapBuffer * bitmap): - TransparentBufferedWindow(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); - } - } -}; - diff --git a/radio/src/thirdparty/libopenui/src/button.cpp b/radio/src/thirdparty/libopenui/src/button.cpp index 9f225677fe8..9fdcd594c78 100644 --- a/radio/src/thirdparty/libopenui/src/button.cpp +++ b/radio/src/thirdparty/libopenui/src/button.cpp @@ -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 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)); -} diff --git a/radio/src/thirdparty/libopenui/src/button.h b/radio/src/thirdparty/libopenui/src/button.h index b3d30c041d9..ac295f0a2fe 100644 --- a/radio/src/thirdparty/libopenui/src/button.h +++ b/radio/src/thirdparty/libopenui/src/button.h @@ -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 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 bgColorHandler = nullptr; }; - -class IconButton: public Button -{ - public: - IconButton(Window* parent, const rect_t& rect, uint8_t icon, - std::function 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; -}; diff --git a/radio/src/thirdparty/libopenui/src/button_matrix.cpp b/radio/src/thirdparty/libopenui/src/button_matrix.cpp index 40f78d414b7..d98862fa0e3 100644 --- a/radio/src/thirdparty/libopenui/src/button_matrix.cpp +++ b/radio/src/thirdparty/libopenui/src/button_matrix.cpp @@ -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); +} diff --git a/radio/src/thirdparty/libopenui/src/button_matrix.h b/radio/src/thirdparty/libopenui/src/button_matrix.h index 31a28c13d2d..ffef0223684 100644 --- a/radio/src/thirdparty/libopenui/src/button_matrix.h +++ b/radio/src/thirdparty/libopenui/src/button_matrix.h @@ -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; }; diff --git a/radio/src/thirdparty/libopenui/src/carousel.cpp b/radio/src/thirdparty/libopenui/src/carousel.cpp deleted file mode 100644 index 9b4e4bbd651..00000000000 --- a/radio/src/thirdparty/libopenui/src/carousel.cpp +++ /dev/null @@ -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(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 diff --git a/radio/src/thirdparty/libopenui/src/carousel.h b/radio/src/thirdparty/libopenui/src/carousel.h deleted file mode 100644 index f72953a5ef2..00000000000 --- a/radio/src/thirdparty/libopenui/src/carousel.h +++ /dev/null @@ -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 -#include "button.h" - -class CarouselItem -{ - public: - CarouselItem(Window * front, Window * back): - front(front), - back(back) - { - } - - void setSelectHandler(std::function handler) - { - selectHandler = std::move(handler); - } - - virtual ~CarouselItem() = default; - - public: - Window * front; - Window * back; - std::function 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 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; -}; - diff --git a/radio/src/thirdparty/libopenui/src/choice.cpp b/radio/src/thirdparty/libopenui/src/choice.cpp index 908b59c723a..3f2604a9a2b 100644 --- a/radio/src/thirdparty/libopenui/src/choice.cpp +++ b/radio/src/thirdparty/libopenui/src/choice.cpp @@ -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); + } +} diff --git a/radio/src/thirdparty/libopenui/src/choice.h b/radio/src/thirdparty/libopenui/src/choice.h index 1aec0761603..9e78bbf04b6 100644 --- a/radio/src/thirdparty/libopenui/src/choice.h +++ b/radio/src/thirdparty/libopenui/src/choice.h @@ -21,6 +21,14 @@ #include #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 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 longPressHandler = nullptr; + + static void ClickHandler(lv_event_t* e) + { + auto ch = (Choice*)lv_event_get_user_data(e); + if (ch) ch->longPressData.isLongPressed = false; + } }; diff --git a/radio/src/thirdparty/libopenui/src/choiceex.cpp b/radio/src/thirdparty/libopenui/src/choiceex.cpp deleted file mode 100644 index 88dcad09339..00000000000 --- a/radio/src/thirdparty/libopenui/src/choiceex.cpp +++ /dev/null @@ -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 getValue, - std::function setValue, - WindowFlags windowFlags) : - Choice(parent, rect, vmin, vmax, getValue, setValue, windowFlags) -{ - longPressData.isLongPressed = false; -} diff --git a/radio/src/thirdparty/libopenui/src/choiceex.h b/radio/src/thirdparty/libopenui/src/choiceex.h deleted file mode 100644 index 803c7f2da21..00000000000 --- a/radio/src/thirdparty/libopenui/src/choiceex.h +++ /dev/null @@ -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 getValue, - std::function 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 longPressHandler = nullptr; - - static void ClickHandler(lv_event_t* e) - { - ChoiceEx* ch = (ChoiceEx*)lv_event_get_user_data(e); - if (ch) ch->longPressData.isLongPressed = false; - } -}; diff --git a/radio/src/thirdparty/libopenui/src/dialog.cpp b/radio/src/thirdparty/libopenui/src/dialog.cpp index 59bbce86ae0..84f3c6067ac 100644 --- a/radio/src/thirdparty/libopenui/src/dialog.cpp +++ b/radio/src/thirdparty/libopenui/src/dialog.cpp @@ -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 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(); +} diff --git a/radio/src/thirdparty/libopenui/src/dialog.h b/radio/src/thirdparty/libopenui/src/dialog.h index 46148120aaf..526e5b31d63 100644 --- a/radio/src/thirdparty/libopenui/src/dialog.h +++ b/radio/src/thirdparty/libopenui/src/dialog.h @@ -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 onClose; + + public: + ProgressDialog(Window *parent, std::string title, + std::function onClose); + + void updateProgress(int percentage); + void setTitle(std::string title) { content->setTitle(title); } + void closeDialog(); + + protected: + // disable keys + void onEvent(event_t) override {} +}; diff --git a/radio/src/thirdparty/libopenui/src/font.h b/radio/src/thirdparty/libopenui/src/font.h index ca1ae9b9a9e..63c94bc81a1 100644 --- a/radio/src/thirdparty/libopenui/src/font.h +++ b/radio/src/thirdparty/libopenui/src/font.h @@ -19,7 +19,7 @@ #pragma once #include -#include "libopenui_types.h" +#include "opentx_types.h" const lv_font_t* getFont(LcdFlags flags); uint8_t getFontHeight(LcdFlags flags); diff --git a/radio/src/thirdparty/libopenui/src/form.cpp b/radio/src/thirdparty/libopenui/src/form.cpp index 291d39b9722..20a1cb780e8 100644 --- a/radio/src/thirdparty/libopenui/src/form.cpp +++ b/radio/src/thirdparty/libopenui/src/form.cpp @@ -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); diff --git a/radio/src/thirdparty/libopenui/src/form.h b/radio/src/thirdparty/libopenui/src/form.h index 8f65bd3fb9a..d9c6526be97 100644 --- a/radio/src/thirdparty/libopenui/src/form.h +++ b/radio/src/thirdparty/libopenui/src/form.h @@ -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); - - virtual void changeEnd(bool forceChanged = false) - { - if (changeHandler) { changeHandler(); } - } - - void setChangeHandler(std::function handler) - { - changeHandler = std::move(handler); - } + public: + FormField(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0, + LcdFlags textFlags = 0, LvglCreate objConstruct = nullptr); - void setBackgroundHandler(std::function handler) - { - backgroundHandler = std::move(handler); - } + virtual void changeEnd(bool forceChanged = false) + { + if (changeHandler) { changeHandler(); } + } - inline bool isEditMode() const { return editMode; } - virtual void setEditMode(bool newEditMode); + void setChangeHandler(std::function handler) + { + changeHandler = std::move(handler); + } - bool isEnabled() const; - void enable(bool value = true); - void disable() { enable(false); } + inline bool isEditMode() const { return editMode; } + virtual void setEditMode(bool newEditMode); - void onFocusLost() override - { - setEditMode(false); - Window::onFocusLost(); - } + void enable(bool value = true); + void disable() { enable(false); } - void onClicked() override; - void onCancel() override; + void onClicked() override; + void onCancel() override; - protected: - bool editMode = false; - bool enabled = true; - std::function changeHandler = nullptr; - std::function backgroundHandler = nullptr; + protected: + bool editMode = false; + bool enabled = true; + std::function 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(); + }; -#if defined(DEBUG_WINDOWS) - std::string getName() const override { return "FormGroup"; } -#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) - { - } + FormWindow(Window *parent, const rect_t &rect, WindowFlags windowflags = 0); #if defined(DEBUG_WINDOWS) - std::string getName() const override { return "FormWindow"; } + 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); }; diff --git a/radio/src/thirdparty/libopenui/src/gridlayout.h b/radio/src/thirdparty/libopenui/src/gridlayout.h deleted file mode 100644 index d2e19195a92..00000000000 --- a/radio/src/thirdparty/libopenui/src/gridlayout.h +++ /dev/null @@ -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; -}; - diff --git a/radio/src/thirdparty/libopenui/src/keyboard_base.cpp b/radio/src/thirdparty/libopenui/src/keyboard_base.cpp index 45337d3ad99..8620cf47041 100644 --- a/radio/src/thirdparty/libopenui/src/keyboard_base.cpp +++ b/radio/src/thirdparty/libopenui/src/keyboard_base.cpp @@ -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); diff --git a/radio/src/thirdparty/libopenui/src/libopenui_compat.h b/radio/src/thirdparty/libopenui/src/libopenui_compat.h deleted file mode 100644 index 940db4f52a7..00000000000 --- a/radio/src/thirdparty/libopenui/src/libopenui_compat.h +++ /dev/null @@ -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 - diff --git a/radio/src/thirdparty/libopenui/src/libopenui_defines.h b/radio/src/thirdparty/libopenui/src/libopenui_defines.h index 59bd7a7e987..f85d843720b 100644 --- a/radio/src/thirdparty/libopenui/src/libopenui_defines.h +++ b/radio/src/thirdparty/libopenui/src/libopenui_defines.h @@ -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 LV_OBJ_FLAG_ENCODER_ACCEL LV_OBJ_FLAG_USER_1 -#define COLOR2FLAGS(color) LcdFlags(unsigned(color) << 16u) -#define COLOR_VAL(flags) ((flags) >> 16u) -#define COLOR_MASK(flags) ((flags) & 0xFFFF0000u) +#include "libopenui_config.h" -#define LV_OBJ_FLAG_ENCODER_ACCEL LV_OBJ_FLAG_USER_1 diff --git a/radio/src/thirdparty/libopenui/src/libopenui_depends.h b/radio/src/thirdparty/libopenui/src/libopenui_depends.h deleted file mode 100644 index 6cafd6e370c..00000000000 --- a/radio/src/thirdparty/libopenui/src/libopenui_depends.h +++ /dev/null @@ -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 -#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 diff --git a/radio/src/thirdparty/libopenui/src/libopenui_file.cpp b/radio/src/thirdparty/libopenui/src/libopenui_file.cpp index f61b843b7d8..1e68c187a01 100644 --- a/radio/src/thirdparty/libopenui/src/libopenui_file.cpp +++ b/radio/src/thirdparty/libopenui/src/libopenui_file.cpp @@ -19,7 +19,6 @@ #include #include #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) { diff --git a/radio/src/thirdparty/libopenui/src/libopenui_file.h b/radio/src/thirdparty/libopenui/src/libopenui_file.h index 415d5a33497..f5588580c50 100644 --- a/radio/src/thirdparty/libopenui/src/libopenui_file.h +++ b/radio/src/thirdparty/libopenui/src/libopenui_file.h @@ -18,7 +18,6 @@ #pragma once -#include "libopenui_compat.h" // for strcasecmp / VC++ #include #include #include diff --git a/radio/src/thirdparty/libopenui/src/libopenui_helpers.cpp b/radio/src/thirdparty/libopenui/src/libopenui_helpers.cpp deleted file mode 100644 index 067dcbd2be3..00000000000 --- a/radio/src/thirdparty/libopenui/src/libopenui_helpers.cpp +++ /dev/null @@ -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" - diff --git a/radio/src/thirdparty/libopenui/src/libopenui_helpers.h b/radio/src/thirdparty/libopenui/src/libopenui_helpers.h deleted file mode 100644 index bc3d73a42fa..00000000000 --- a/radio/src/thirdparty/libopenui/src/libopenui_helpers.h +++ /dev/null @@ -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 -#include - -#if defined(min) - #undef min - #undef max -#endif - -template -inline T min(T a, T b) -{ - return a < b ? a : b; -} - -template -inline T max(T a, T b) -{ - return a > b ? a : b; -} - -template -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 -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; - } -} diff --git a/radio/src/thirdparty/libopenui/src/libopenui_types.h b/radio/src/thirdparty/libopenui/src/libopenui_types.h deleted file mode 100644 index 2558303908e..00000000000 --- a/radio/src/thirdparty/libopenui/src/libopenui_types.h +++ /dev/null @@ -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 - -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; diff --git a/radio/src/thirdparty/libopenui/src/mainwindow.cpp b/radio/src/thirdparty/libopenui/src/mainwindow.cpp index 766565be7b9..939e57eeb3e 100644 --- a/radio/src/thirdparty/libopenui/src/mainwindow.cpp +++ b/radio/src/thirdparty/libopenui/src/mainwindow.cpp @@ -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(0, rect.left(), invalidatedRect.left()); - auto right = limit(invalidatedRect.right(), rect.right(), LCD_W); - auto top = limit(0, rect.top(), invalidatedRect.top()); - auto bottom = - limit(rect.bottom(), invalidatedRect.bottom(), LCD_H); - invalidatedRect = {left, top, right - left, bottom - top}; - } else { - invalidatedRect = rect; - } -} - void MainWindow::run(bool trash) { auto start = ticksNow(); diff --git a/radio/src/thirdparty/libopenui/src/mainwindow.h b/radio/src/thirdparty/libopenui/src/mainwindow.h index 72e54cd988d..713853994c2 100644 --- a/radio/src/thirdparty/libopenui/src/mainwindow.h +++ b/radio/src/thirdparty/libopenui/src/mainwindow.h @@ -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; }; diff --git a/radio/src/thirdparty/libopenui/src/menu.cpp b/radio/src/thirdparty/libopenui/src/menu.cpp index 8818e5ebb0e..a729b555b4c 100644 --- a/radio/src/thirdparty/libopenui/src/menu.cpp +++ b/radio/src/thirdparty/libopenui/src/menu.cpp @@ -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) { } diff --git a/radio/src/thirdparty/libopenui/src/menutoolbar.cpp b/radio/src/thirdparty/libopenui/src/menutoolbar.cpp index 8a3eb65eed8..dc6901a79ba 100644 --- a/radio/src/thirdparty/libopenui/src/menutoolbar.cpp +++ b/radio/src/thirdparty/libopenui/src/menutoolbar.cpp @@ -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); } diff --git a/radio/src/thirdparty/libopenui/src/modal_window.cpp b/radio/src/thirdparty/libopenui/src/modal_window.cpp index 9ba189a6748..6e11e5e10df 100644 --- a/radio/src/thirdparty/libopenui/src/modal_window.cpp +++ b/radio/src/thirdparty/libopenui/src/modal_window.cpp @@ -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()); diff --git a/radio/src/thirdparty/libopenui/src/numberedit.cpp b/radio/src/thirdparty/libopenui/src/numberedit.cpp index 139d803244f..d688625ecce 100644 --- a/radio/src/thirdparty/libopenui/src/numberedit.cpp +++ b/radio/src/thirdparty/libopenui/src/numberedit.cpp @@ -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 getValue, std::function 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(); } diff --git a/radio/src/thirdparty/libopenui/src/numberedit.h b/radio/src/thirdparty/libopenui/src/numberedit.h index 90ce5737dc8..e55a16cb323 100644 --- a/radio/src/thirdparty/libopenui/src/numberedit.h +++ b/radio/src/thirdparty/libopenui/src/numberedit.h @@ -18,32 +18,185 @@ #pragma once -#include "basenumberedit.h" +#include "form.h" +#include "strhelpers.h" #include -class NumberEdit : public BaseNumberEdit +class NumberEdit: public FormField { - public: - NumberEdit(Window* parent, const rect_t& rect, int vmin, int vmax, - std::function getValue, - std::function setValue = nullptr, - WindowFlags windowFlags = 0, LcdFlags textFlags = 0); + public: + NumberEdit(Window* parent, const rect_t& rect, int vmin, int vmax, + std::function getValue, + std::function 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 handler) - { - isValueAvailable = std::move(handler); - } + void setAvailableHandler(std::function 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 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 handler) + { + _setValue = std::move(handler); + } + + void setGetValueHandler(std::function handler) + { + _getValue = std::move(handler); + } + + int32_t getValue() const + { + return _getValue != nullptr ? _getValue() : 0; + } + + void setDisplayHandler(std::function 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 _getValue; + std::function _setValue; + std::function displayFunction; + std::function isValueAvailable; }; diff --git a/radio/src/thirdparty/libopenui/src/progress.cpp b/radio/src/thirdparty/libopenui/src/progress.cpp index 1f481ce5c51..8f5de98531b 100644 --- a/radio/src/thirdparty/libopenui/src/progress.cpp +++ b/radio/src/thirdparty/libopenui/src/progress.cpp @@ -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); + } } diff --git a/radio/src/thirdparty/libopenui/src/progress.h b/radio/src/thirdparty/libopenui/src/progress.h index 55b18266544..9f1b7f6178e 100644 --- a/radio/src/thirdparty/libopenui/src/progress.h +++ b/radio/src/thirdparty/libopenui/src/progress.h @@ -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; }; diff --git a/radio/src/thirdparty/libopenui/src/roller.h b/radio/src/thirdparty/libopenui/src/roller.h deleted file mode 100644 index 996953ee7cf..00000000000 --- a/radio/src/thirdparty/libopenui/src/roller.h +++ /dev/null @@ -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 -#include -#include -#include -#include -#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 getValue, std::function 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 values, int vmin, int vmax, std::function getValue, std::function 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 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(); - } -}; diff --git a/radio/src/thirdparty/libopenui/src/slider.cpp b/radio/src/thirdparty/libopenui/src/slider.cpp index 9d36773ff98..b02bb3c3407 100644 --- a/radio/src/thirdparty/libopenui/src/slider.cpp +++ b/radio/src/thirdparty/libopenui/src/slider.cpp @@ -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 getValue, std::function 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); - - 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); + padAll(7); - // 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); + auto slider = etx_slider_create(lvobj); + lv_obj_set_width(slider, lv_pct(100)); - // 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_event_cb(slider, slider_changed_cb, LV_EVENT_VALUE_CHANGED, this); + lv_slider_set_range(slider, vmin, vmax); - 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); -} - - -int Slider::value(coord_t x) const -{ - return vmin + ((vmax - vmin) * x + (rect.w / 2)) / rect.w; + if (_getValue != nullptr) + lv_slider_set_value(slider, _getValue(), LV_ANIM_OFF); } - diff --git a/radio/src/thirdparty/libopenui/src/slider.h b/radio/src/thirdparty/libopenui/src/slider.h index fc19d3d748d..b2991090387 100644 --- a/radio/src/thirdparty/libopenui/src/slider.h +++ b/radio/src/thirdparty/libopenui/src/slider.h @@ -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 getValue, std::function setValue); #if defined(DEBUG_WINDOWS) @@ -40,6 +40,4 @@ class Slider : public FormField int vmax; std::function _getValue; std::function _setValue; - - int value(coord_t x) const; }; diff --git a/radio/src/thirdparty/libopenui/src/static.cpp b/radio/src/thirdparty/libopenui/src/static.cpp index 3bab6437818..4a0f53e4b3f 100644 --- a/radio/src/thirdparty/libopenui/src/static.cpp +++ b/radio/src/thirdparty/libopenui/src/static.cpp @@ -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); diff --git a/radio/src/thirdparty/libopenui/src/static.h b/radio/src/thirdparty/libopenui/src/static.h index 19264988140..068b7815519 100644 --- a/radio/src/thirdparty/libopenui/src/static.h +++ b/radio/src/thirdparty/libopenui/src/static.h @@ -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 { diff --git a/radio/src/thirdparty/libopenui/src/table.cpp b/radio/src/thirdparty/libopenui/src/table.cpp index 75be0c63470..00ccdd91a1e 100644 --- a/radio/src/thirdparty/libopenui/src/table.cpp +++ b/radio/src/thirdparty/libopenui/src/table.cpp @@ -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); } diff --git a/radio/src/thirdparty/libopenui/src/table.h b/radio/src/thirdparty/libopenui/src/table.h index d624803e18f..636b143894c 100644 --- a/radio/src/thirdparty/libopenui/src/table.h +++ b/radio/src/thirdparty/libopenui/src/table.h @@ -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"; } diff --git a/radio/src/thirdparty/libopenui/src/textedit.cpp b/radio/src/thirdparty/libopenui/src/textedit.cpp index 91b8289fc45..a93a657c378 100644 --- a/radio/src/thirdparty/libopenui/src/textedit.cpp +++ b/radio/src/thirdparty/libopenui/src/textedit.cpp @@ -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(); -} diff --git a/radio/src/thirdparty/libopenui/src/textedit.h b/radio/src/thirdparty/libopenui/src/textedit.h index f25f40dd9b8..b55865d9938 100644 --- a/radio/src/thirdparty/libopenui/src/textedit.h +++ b/radio/src/thirdparty/libopenui/src/textedit.h @@ -46,5 +46,4 @@ class TextEdit : public FormField void changeEnd(bool forceChanged = false) override; void onClicked() override; - void onFocusLost() override; }; diff --git a/radio/src/thirdparty/libopenui/src/theme.h b/radio/src/thirdparty/libopenui/src/theme.h deleted file mode 100644 index 14f943b0ac0..00000000000 --- a/radio/src/thirdparty/libopenui/src/theme.h +++ /dev/null @@ -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 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); - diff --git a/radio/src/thirdparty/libopenui/src/checkbox.cpp b/radio/src/thirdparty/libopenui/src/toggleswitch.cpp similarity index 64% rename from radio/src/thirdparty/libopenui/src/checkbox.cpp rename to radio/src/thirdparty/libopenui/src/toggleswitch.cpp index a40e76a56ea..4073916ae6e 100644 --- a/radio/src/thirdparty/libopenui/src/checkbox.cpp +++ b/radio/src/thirdparty/libopenui/src/toggleswitch.cpp @@ -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 getValue, std::function 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() } diff --git a/radio/src/thirdparty/libopenui/src/checkbox.h b/radio/src/thirdparty/libopenui/src/toggleswitch.h similarity index 90% rename from radio/src/thirdparty/libopenui/src/checkbox.h rename to radio/src/thirdparty/libopenui/src/toggleswitch.h index 4eeaaba58f9..c3b763a7a1d 100644 --- a/radio/src/thirdparty/libopenui/src/checkbox.h +++ b/radio/src/thirdparty/libopenui/src/toggleswitch.h @@ -21,15 +21,15 @@ #include #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 getValue, std::function 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; diff --git a/radio/src/thirdparty/libopenui/src/widgets/edgetx_table.c b/radio/src/thirdparty/libopenui/src/widgets/edgetx_table.c deleted file mode 100644 index 0935ca9b7c5..00000000000 --- a/radio/src/thirdparty/libopenui/src/widgets/edgetx_table.c +++ /dev/null @@ -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; - } - } -} diff --git a/radio/src/thirdparty/libopenui/src/widgets/edgetx_table.h b/radio/src/thirdparty/libopenui/src/widgets/edgetx_table.h deleted file mode 100644 index 82960d64cf9..00000000000 --- a/radio/src/thirdparty/libopenui/src/widgets/edgetx_table.h +++ /dev/null @@ -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 - -#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 diff --git a/radio/src/thirdparty/libopenui/src/widgets/etx_obj_create.h b/radio/src/thirdparty/libopenui/src/widgets/etx_obj_create.h new file mode 100644 index 00000000000..43ab4dc691d --- /dev/null +++ b/radio/src/thirdparty/libopenui/src/widgets/etx_obj_create.h @@ -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 + +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); diff --git a/radio/src/thirdparty/libopenui/src/widgets/field_edit.c b/radio/src/thirdparty/libopenui/src/widgets/field_edit.c deleted file mode 100644 index 2df85d5e081..00000000000 --- a/radio/src/thirdparty/libopenui/src/widgets/field_edit.c +++ /dev/null @@ -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; -} diff --git a/radio/src/thirdparty/libopenui/src/widgets/field_edit.h b/radio/src/thirdparty/libopenui/src/widgets/field_edit.h deleted file mode 100644 index 2a125453219..00000000000 --- a/radio/src/thirdparty/libopenui/src/widgets/field_edit.h +++ /dev/null @@ -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 - -#ifdef __cplusplus -extern "C" { -#endif - -extern const lv_obj_class_t field_edit_class; -lv_obj_t* field_edit_create(lv_obj_t* parent); - -#ifdef __cplusplus -}; -#endif - -#endif diff --git a/radio/src/thirdparty/libopenui/src/widgets/number_edit.c b/radio/src/thirdparty/libopenui/src/widgets/number_edit.c deleted file mode 100644 index 0e925620af4..00000000000 --- a/radio/src/thirdparty/libopenui/src/widgets/number_edit.c +++ /dev/null @@ -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; -} diff --git a/radio/src/thirdparty/libopenui/src/widgets/number_edit.h b/radio/src/thirdparty/libopenui/src/widgets/number_edit.h deleted file mode 100644 index 2a125453219..00000000000 --- a/radio/src/thirdparty/libopenui/src/widgets/number_edit.h +++ /dev/null @@ -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 - -#ifdef __cplusplus -extern "C" { -#endif - -extern const lv_obj_class_t field_edit_class; -lv_obj_t* field_edit_create(lv_obj_t* parent); - -#ifdef __cplusplus -}; -#endif - -#endif diff --git a/radio/src/thirdparty/libopenui/src/widgets/simple_btn.c b/radio/src/thirdparty/libopenui/src/widgets/simple_btn.c deleted file mode 100644 index 07bb73f36ff..00000000000 --- a/radio/src/thirdparty/libopenui/src/widgets/simple_btn.c +++ /dev/null @@ -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; -} diff --git a/radio/src/thirdparty/libopenui/src/widgets/simple_btn.h b/radio/src/thirdparty/libopenui/src/widgets/simple_btn.h deleted file mode 100644 index 2d39985b552..00000000000 --- a/radio/src/thirdparty/libopenui/src/widgets/simple_btn.h +++ /dev/null @@ -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 - -#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 diff --git a/radio/src/thirdparty/libopenui/src/widgets/window_base.c b/radio/src/thirdparty/libopenui/src/widgets/window_base.c deleted file mode 100644 index 7a0117ecf58..00000000000 --- a/radio/src/thirdparty/libopenui/src/widgets/window_base.c +++ /dev/null @@ -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; -} diff --git a/radio/src/thirdparty/libopenui/src/widgets/window_base.h b/radio/src/thirdparty/libopenui/src/widgets/window_base.h deleted file mode 100644 index 00d5132f9c3..00000000000 --- a/radio/src/thirdparty/libopenui/src/widgets/window_base.h +++ /dev/null @@ -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 - -#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 diff --git a/radio/src/thirdparty/libopenui/src/window.cpp b/radio/src/thirdparty/libopenui/src/window.cpp index 20882def914..ea28c1491c5 100644 --- a/radio/src/thirdparty/libopenui/src/window.cpp +++ b/radio/src/thirdparty/libopenui/src/window.cpp @@ -20,8 +20,6 @@ #include "touch.h" #include "mainwindow.h" -#include "widgets/window_base.h" - std::list 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::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::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); diff --git a/radio/src/thirdparty/libopenui/src/window.h b/radio/src/thirdparty/libopenui/src/window.h index aa52f6e961c..e259c5d4a62 100644 --- a/radio/src/thirdparty/libopenui/src/window.h +++ b/radio/src/thirdparty/libopenui/src/window.h @@ -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 FocusHandler; void setFocusHandler(FocusHandler h) { focusHandler = std::move(h); } - const std::list 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::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; };