From 4b05632c844b3c83c5b12b3606fd30e29f99bd65 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 28 Aug 2022 10:36:03 +0200 Subject: [PATCH] Remove ColorEdit (#60) --- .../thirdparty/libopenui/src/CMakeLists.txt | 1 - .../thirdparty/libopenui/src/coloredit.cpp | 101 ------------------ .../src/thirdparty/libopenui/src/coloredit.h | 41 ------- 3 files changed, 143 deletions(-) delete mode 100644 radio/src/thirdparty/libopenui/src/coloredit.cpp delete mode 100644 radio/src/thirdparty/libopenui/src/coloredit.h diff --git a/radio/src/thirdparty/libopenui/src/CMakeLists.txt b/radio/src/thirdparty/libopenui/src/CMakeLists.txt index 50d910e00..2d4891572 100644 --- a/radio/src/thirdparty/libopenui/src/CMakeLists.txt +++ b/radio/src/thirdparty/libopenui/src/CMakeLists.txt @@ -26,7 +26,6 @@ set(LIBOPENUI_SRC filechoice.cpp numberedit.cpp textedit.cpp - coloredit.cpp progress.cpp table.cpp modal_window.cpp diff --git a/radio/src/thirdparty/libopenui/src/coloredit.cpp b/radio/src/thirdparty/libopenui/src/coloredit.cpp deleted file mode 100644 index 36be41dde..000000000 --- a/radio/src/thirdparty/libopenui/src/coloredit.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) OpenTX - * - * Source: - * https://github.com/opentx/libopenui - * - * This file is a part of libopenui library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - */ - -#include "coloredit.h" -#include "numberedit.h" -#include "bitfield.h" -#include "dialog.h" - -#define PICKER_SIZE lv_colorwheel_class.width_def - -struct ColorWheelPopup : public Dialog { - ColorWheelPopup(Window* parent, lv_color_t color, - std::function setValue) : - Dialog(parent, std::string(), - rect_t{0, 0, PICKER_SIZE, - PICKER_SIZE + POPUP_HEADER_HEIGHT}) - { - auto lv_content = content->getLvObj(); - auto form = content->form.getLvObj(); - lv_obj_set_size(form, PICKER_SIZE, PICKER_SIZE); - - lv_obj_center(lv_content); - lv_obj_center(form); - - auto cw = lv_colorwheel_create(form, true); - lv_colorwheel_set_rgb(cw, color); - - auto wheel_size = 3 * PICKER_SIZE / 4; - lv_obj_set_style_arc_width(cw, wheel_size / 5, 0); - lv_obj_set_size(cw, wheel_size, wheel_size); - lv_obj_center(cw); - - content->updateSize(); - - setCloseWhenClickOutside(true); - setCloseHandler([=]() { - lv_color_t lv_color = lv_colorwheel_get_rgb(cw); - setValue(lv_color); - }); - } -}; - -static void colorwheel_popup(lv_event_t* e) -{ - auto edit = (ColorEdit*)lv_event_get_user_data(e); - if (edit) { - new ColorWheelPopup(edit, edit->getColor(), - [=](lv_color_t c) { edit->setColor(c); }); - } -} - -// based on LVGL default switch size -constexpr lv_coord_t COLOR_PAD_WIDTH = (4 * LV_DPI_DEF) / 10; -constexpr lv_coord_t COLOR_PAD_HEIGHT = (4 * LV_DPI_DEF) / 17; - -ColorEdit::ColorEdit(Window* parent, const rect_t& rect, - std::function getValue, - std::function setValue) : - FormField(parent, rect, 0, 0, lv_btn_create), - setValue(std::move(setValue)) -{ - auto value = getValue(); - color = lv_color_make(GET_RED(value), GET_GREEN(value), GET_BLUE(value)); - - lv_obj_set_style_bg_color(lvobj, color, LV_PART_MAIN); - lv_obj_set_style_bg_opa(lvobj, LV_OPA_100, LV_PART_MAIN); - - lv_obj_set_style_bg_color(lvobj, color, LV_STATE_FOCUS_KEY); - lv_obj_set_style_bg_opa(lvobj, LV_OPA_100, LV_STATE_FOCUS_KEY); - - lv_obj_set_size(lvobj, COLOR_PAD_WIDTH, COLOR_PAD_HEIGHT); - lv_obj_add_event_cb(lvobj, colorwheel_popup, LV_EVENT_CLICKED, this); -} - -void ColorEdit::setColor(lv_color_t c) -{ - color = c; - setValue(RGB_JOIN(c.ch.red, c.ch.green, c.ch.blue)); - - lv_obj_set_style_bg_color(lvobj, color, LV_PART_MAIN); - lv_obj_set_style_bg_color(lvobj, color, LV_STATE_FOCUS_KEY); - - // TRACE("### color: %d %d %d ###", c.ch.red, c.ch.green, c.ch.blue); - invalidate(); -} diff --git a/radio/src/thirdparty/libopenui/src/coloredit.h b/radio/src/thirdparty/libopenui/src/coloredit.h deleted file mode 100644 index 601fa490d..000000000 --- a/radio/src/thirdparty/libopenui/src/coloredit.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) OpenTX - * - * Source: - * https://github.com/opentx/libopenui - * - * This file is a part of libopenui library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - */ - -#pragma once - -#include "form.h" - -class ColorEdit : public FormField -{ - lv_color_t color; - std::function setValue; - -public: - - ColorEdit(Window* parent, const rect_t& rect, - std::function getValue, - std::function setValue = nullptr); - - void setColor(lv_color_t c); - lv_color_t getColor() const { return color; } - -#if defined(DEBUG_WINDOWS) - std::string getName() const override { return "ColorEdit"; } -#endif -};