diff --git a/Firmware/UI/Screens/MainPage.cpp b/Firmware/UI/Screens/MainPage.cpp index 363db28..b719ef6 100644 --- a/Firmware/UI/Screens/MainPage.cpp +++ b/Firmware/UI/Screens/MainPage.cpp @@ -4,7 +4,11 @@ #include "../MenuSystem.h" // TODO: Add assignment of menu system to IMenu -MainPage::MainPage(IUSBDevice* cdcDevice) : IMenu(cdcDevice), _backgroundColor(Color565::MenuBackground) +MainPage::MainPage(IUSBDevice* cdcDevice) : + IMenu(cdcDevice), _backgroundColor(Color565::MenuBackground), _fpsButton(10, 0, 90, "FPS", false), + _analogGainButton(115, 0, 90, "A. Gain", false), _digitalGainButton(220, 0, 90, "D. Gain", false), + _menuButton(10, 210, 90, "MENU", true, ButtonType::BUTTON), _shutterButton(115, 179, 90, "Shutter", true), + _whiteBalanceButton(220, 179, 90, "WB", true) { SetupButtons(); } @@ -12,22 +16,15 @@ MainPage::MainPage(IUSBDevice* cdcDevice) : IMenu(cdcDevice), _backgroundColor(C void MainPage::SetupButtons() { // Top row - _fpsButton = MainPageButton(10, 0, 90, "FPS", false); - _analogGainButton = MainPageButton(115, 0, 90, "A. Gain", false); _analogGainButton.SetHandler(&AnalogGainButtonHandler); - _digitalGainButton = MainPageButton(220, 0, 90, "D. Gain", false), _digitalGainButton.SetHandler(&DigitalGainButtonHandler); // Bottom row - _menuButton = MainPageButton(10, 210, 90, "MENU", true, ButtonType::BUTTON); _menuButton.SetLabelHeight(30); _menuButton.SetLabelFont(Font::FreeSans12pt7b); _menuButton.SetHandler(&MenuButtonHandler); - - _shutterButton = MainPageButton(115, 179, 90, "Shutter", true); - _whiteBalanceButton = MainPageButton(220, 179, 90, "WB", true); } Color565 MainPage::GetBackgroundColor() @@ -81,45 +78,45 @@ void MainPage::Update(Button button, int8_t knob, IMenuSystem* menuSystem) { case Button::BUTTON_1_UP: _fpsButton.SetValue((char*)"1U"); - _fpsButton.SetHighlighted(false); + _fpsButton.SetState(ButtonState::Default); break; case Button::BUTTON_1_DOWN: _fpsButton.SetValue((char*)"1D"); - _fpsButton.SetHighlighted(true); + _fpsButton.SetState(ButtonState::Highlighted); break; case Button::BUTTON_2_UP: //_fpsButton.SetValue((char*)"2"); - _analogGainButton.SetHighlighted(false); + _analogGainButton.SetState(ButtonState::Default); _analogGainButton.Activate(this); // _usbDevice->Send((uint8_t*)"Button 2\r\n", 10); break; case Button::BUTTON_2_DOWN: - _analogGainButton.SetHighlighted(true); + _analogGainButton.SetState(ButtonState::Highlighted); break; case Button::BUTTON_3_UP: //_fpsButton.SetValue((char*)"3"); - _digitalGainButton.SetHighlighted(false); + _digitalGainButton.SetState(ButtonState::Default); _digitalGainButton.Activate(this); break; case Button::BUTTON_3_DOWN: _fpsButton.SetValue((char*)"3"); - _digitalGainButton.SetHighlighted(true); + _digitalGainButton.SetState(ButtonState::Highlighted); break; case Button::BUTTON_4_UP: //_menuButton.Activate(this); - _menuButton.SetHighlighted(false); + _menuButton.SetState(ButtonState::Default); menuSystem->SetCurrentScreen(AvailableScreens::MainMenu); break; case Button::BUTTON_4_DOWN: - _menuButton.SetHighlighted(true); + _menuButton.SetState(ButtonState::Highlighted); break; case Button::BUTTON_6_UP: //_menuButton.Activate(this); - _whiteBalanceButton.SetHighlighted(false); + _whiteBalanceButton.SetState(ButtonState::Default); menuSystem->SetCurrentScreen(AvailableScreens::WhiteBalance); break; case Button::BUTTON_6_DOWN: - _whiteBalanceButton.SetHighlighted(true); + _whiteBalanceButton.SetState(ButtonState::Highlighted); break; default: break; diff --git a/Firmware/UI/Screens/NumericValueScreen.h b/Firmware/UI/Screens/NumericValueScreen.h index 5c796b3..c0f12a9 100644 --- a/Firmware/UI/Screens/NumericValueScreen.h +++ b/Firmware/UI/Screens/NumericValueScreen.h @@ -42,7 +42,8 @@ class NumericValueScreen : public IScreen // This is the primary button in this menu //_setButton.SetHandler(&SetButtonHandler); - _setButton.SetBackgroundColor((uint16_t)Color565::AXIOM_Orange); + _setButton.SetColor(ButtonState::Default, PushButton::Colors::Background, + static_cast(Color565::AXIOM_Orange)); _bottomButtonBar.SetButton(ButtonPosition::Right, &_setButton); _bottomButtonBar.SetButton(ButtonPosition::Center, &_liveButton); @@ -119,12 +120,12 @@ class NumericValueScreen : public IScreen void SetSetButtonPressed(bool pressed) { - _setButton.SetHighlighted(pressed); + _setButton.SetState(pressed ? ButtonState::Highlighted : ButtonState::Default); } void SetCancelButtonPressed(bool pressed) { - _cancelButton.SetHighlighted(pressed); + _cancelButton.SetState(pressed ? ButtonState::Highlighted : ButtonState::Default); } void Draw(IPainter* painter) override diff --git a/Firmware/UI/Screens/ParameterListScreen.h b/Firmware/UI/Screens/ParameterListScreen.h index 0d1d905..2f50c81 100644 --- a/Firmware/UI/Screens/ParameterListScreen.h +++ b/Firmware/UI/Screens/ParameterListScreen.h @@ -47,7 +47,8 @@ class ParameterListScreen : public IScreen // This is the primary button in this menu //_setButton.SetHandler(&SetButtonHandler); - _setButton.SetBackgroundColor((uint16_t)Color565::AXIOM_Orange); + _setButton.SetColor(ButtonState::Default, PushButton::Colors::Background, + static_cast(Color565::AXIOM_Orange)); _bottomButtonBar.SetButton(ButtonPosition::Right, &_setButton); } @@ -63,12 +64,12 @@ class ParameterListScreen : public IScreen void SetSetButtonPressed(bool pressed) { - _setButton.SetHighlighted(pressed); + _setButton.SetState(pressed ? ButtonState::Highlighted : ButtonState::Default); } void SetCancelButtonPressed(bool pressed) { - _cancelButton.SetHighlighted(pressed); + _cancelButton.SetState(pressed ? ButtonState::Highlighted : ButtonState::Default); } void SetHighlighted(uint8_t highlightindex) diff --git a/Firmware/UI/Screens/WhiteBalanceScreen.cpp b/Firmware/UI/Screens/WhiteBalanceScreen.cpp index 4198d56..0f5cd4a 100644 --- a/Firmware/UI/Screens/WhiteBalanceScreen.cpp +++ b/Firmware/UI/Screens/WhiteBalanceScreen.cpp @@ -19,7 +19,8 @@ WhiteBalanceScreen::WhiteBalanceScreen(IUSBDevice* usbDevice) : // This is the primary button in this menu _setButton.SetHandler(&SetButtonHandler); - _setButton.SetBackgroundColor((uint16_t)Color565::AXIOM_Orange); + _setButton.SetColor(ButtonState::Default, PushButton::Colors::Background, + static_cast(Color565::AXIOM_Orange)); _bottomButtonBar.SetButton(ButtonPosition::Right, &_setButton); //_leftButtonBar.SetButton(ButtonPosition::Left, &_homeButton); //already done in IScreen @@ -74,30 +75,30 @@ void WhiteBalanceScreen::Update(Button button, int8_t knob, IMenuSystem* menuSys switch (button) { case Button::BUTTON_4_DOWN: - _cancelButton.SetHighlighted(true); + _cancelButton.SetState(ButtonState::Highlighted); break; case Button::BUTTON_4_UP: - _cancelButton.SetHighlighted(false); + _cancelButton.SetState(ButtonState::Default); menuSystem->SetCurrentScreen(AvailableScreens::MainPage); break; case Button::BUTTON_5_DOWN: - _addPresetButton.SetHighlighted(true); + _addPresetButton.SetState(ButtonState::Highlighted); break; case Button::BUTTON_5_UP: - _addPresetButton.SetHighlighted(false); + _addPresetButton.SetState(ButtonState::Default); break; case Button::BUTTON_6_DOWN: - _setButton.SetHighlighted(true); + _setButton.SetState(ButtonState::Highlighted); break; case Button::BUTTON_6_UP: - _setButton.SetHighlighted(false); + _setButton.SetState(ButtonState::Default); menuSystem->SetCurrentScreen(AvailableScreens::MainPage); break; case Button::BUTTON_7_DOWN: - _homeButton.SetHighlighted(true); + _homeButton.SetState(ButtonState::Highlighted); break; case Button::BUTTON_7_UP: - _homeButton.SetHighlighted(false); + _homeButton.SetState(ButtonState::Default); menuSystem->SetCurrentScreen(AvailableScreens::MainPage); break; default: diff --git a/Firmware/UI/Widgets/IButton.h b/Firmware/UI/Widgets/IButton.h index 35091ac..7a472b3 100755 --- a/Firmware/UI/Widgets/IButton.h +++ b/Firmware/UI/Widgets/IButton.h @@ -10,14 +10,39 @@ #include "IWidget.h" +enum class ButtonState : uint8_t +{ + Default = 0, + Highlighted = 1, + Disabled = 2, +}; + class IButton : public IWidget { // void* -> sender, e.g. MainPage void (*_handlerPtr)(void*); + // Might want to move these three into implementers instead, + // to allow for correct sizes + + uint16_t* _colorPtr; + const uint8_t _colorsPerState; + const uint8_t _stateCount; + ButtonState _currentState; + + // index: every derived class is supposed to define its own enum for colorMeanings + uint8_t Index(ButtonState state, uint8_t index) + { + return static_cast(state) * _colorsPerState + index; + } + public: - IButton(uint16_t x = 0, uint16_t y = 0, uint16_t width = 0, uint16_t height = 0) : - IWidget(x, y, width, height), _handlerPtr(nullptr) + // TODO: add startState to constructor? + IButton(uint8_t stateCount, uint8_t colorsPerState, uint16_t* colorPointer, uint16_t x = 0, uint16_t y = 0, + uint16_t width = 0, uint16_t height = 0) : + IWidget(x, y, width, height), + _handlerPtr(nullptr), _currentState(ButtonState::Default), _colorPtr(colorPointer), + _colorsPerState(colorsPerState), _stateCount(colorsPerState) { } @@ -30,6 +55,26 @@ class IButton : public IWidget { _handlerPtr(sender); } + + void SetColor(ButtonState state, uint8_t index, uint16_t color) + { + _colorPtr[Index(state, index)] = color; + } + + uint16_t GetColor(ButtonState state, uint8_t index) + { + return _colorPtr[Index(state, index)]; + } + + uint16_t GetCurrentColor(uint8_t index) + { + return GetColor(_currentState, index); + } + + void SetState(ButtonState state) + { + _currentState = state; + } }; #endif /* IBUTTON_H */ diff --git a/Firmware/UI/Widgets/ImageButton.h b/Firmware/UI/Widgets/ImageButton.h index 9e2a21d..5090a0c 100644 --- a/Firmware/UI/Widgets/ImageButton.h +++ b/Firmware/UI/Widgets/ImageButton.h @@ -18,20 +18,11 @@ class ImageButton : public IButton const char* _label; uint8_t _cornerRadius; - bool _highlighted; - // Color Defintions - uint16_t _textColor; - uint16_t _imageColor; - uint16_t _backgroundColor; - - uint16_t _textHighlightColor; - uint16_t _imageHighlightColor; - uint16_t _backgroundHighlightColor; - - uint16_t _currentTextColor; - uint16_t _currentImageColor; - uint16_t _currentBackgroundColor; + // Color Definitions + static constexpr uint8_t _stateCount = 3; + static constexpr uint8_t _colorsPerState = 3; + uint16_t _colors[_stateCount * _colorsPerState]; uint8_t _imagePositionX; uint8_t _textPositionX; @@ -42,13 +33,20 @@ class ImageButton : public IButton ButtonStyle _buttonStyle; public: + enum Colors : uint8_t + { + Text = 0, + Background = 1, + Image = 2, + }; + explicit ImageButton(const Icon* icon, uint16_t x = 0, uint16_t y = 0, uint16_t width = 0, uint16_t height = 0) : - IButton(x, y, width, height), _image(icon), _cornerRadius(3), _highlighted(false), - _imageColor((uint16_t)Color565::Black), _currentImageColor(_imageColor), - _backgroundHighlightColor((uint16_t)Color565::AXIOM_Blue), - _currentBackgroundColor(utils::RGB565(220, 220, 220)), _backgroundColor(utils::RGB565(220, 220, 220)), + IButton(_stateCount, _colorsPerState, _colors, x, y, width, height), _image(icon), _cornerRadius(3), _buttonStyle(ButtonStyle::Icon) { + SetColor(ButtonState::Default, Colors::Image, static_cast(Color565::Black)); + SetColor(ButtonState::Default, Colors::Background, utils::RGB565(220, 220, 220)); + SetColor(ButtonState::Highlighted, Colors::Background, static_cast(Color565::AXIOM_Blue)); _totalWidth = _image->Width; _textPositionY = _height / 2; _imagePositionX = _width / 2 - _totalWidth / 2; @@ -88,7 +86,7 @@ class ImageButton : public IButton virtual void Draw(IPainter* painter) override { - painter->DrawFillRoundRectangle(_x, _y, _width, _height, _cornerRadius, _currentBackgroundColor); + painter->DrawFillRoundRectangle(_x, _y, _width, _height, _cornerRadius, GetCurrentColor(Colors::Background)); if (_buttonStyle == ButtonStyle::IconAndText) { @@ -99,66 +97,14 @@ class ImageButton : public IButton _textPositionY += painter->GetCurrentFontHeight() / 2; // TODO: This should not be recalculated with every redraw - painter->DrawIcon(_image, _x + _imagePositionX, _y + _height / 2 - _image->Height / 2, _currentImageColor); - painter->DrawText(_x + _textPositionX, _y + _textPositionY, _label, _currentTextColor, + painter->DrawIcon(_image, _x + _imagePositionX, _y + _height / 2 - _image->Height / 2, + GetCurrentColor(Colors::Image)); + painter->DrawText(_x + _textPositionX, _y + _textPositionY, _label, GetCurrentColor(Colors::Text), TextAlign::TEXT_ALIGN_LEFT, strlen(_label)); } else if (_buttonStyle == ButtonStyle::Icon) { painter->DrawIcon(_image, _x + _width / 2 - _image->Width / 2, _y + _height / 2 - _image->Height / 2, - _currentImageColor); - } - } - - void SetBackgroundColor(uint16_t color) - { - _backgroundColor = color; - SetHighlighted(_highlighted); - } - - void SetImageColor(uint16_t color) - { - _imageColor = color; - SetHighlighted(_highlighted); - } - - void SetTextColor(uint16_t color) - { - _textColor = color; - SetHighlighted(_highlighted); - } - - void SetHighlightBackgroundColor(uint16_t color) - { - _backgroundHighlightColor = color; - SetHighlighted(_highlighted); - } - - void SetHighlightImageColor(uint16_t color) - { - _imageHighlightColor = color; - SetHighlighted(_highlighted); - } - - void SetHighlightTextColor(uint16_t color) - { - _textHighlightColor = color; - SetHighlighted(_highlighted); - } - - void SetHighlighted(bool highlighted) - { - _highlighted = highlighted; - if (highlighted) - { - _currentImageColor = _imageHighlightColor; - _currentBackgroundColor = _backgroundHighlightColor; - _currentTextColor = _textHighlightColor; - - } else - { - _currentImageColor = _imageColor; - _currentBackgroundColor = _backgroundColor; - _currentTextColor = _textColor; + GetCurrentColor(Colors::Image)); } } }; diff --git a/Firmware/UI/Widgets/MainPageButton.h b/Firmware/UI/Widgets/MainPageButton.h index c82b8c7..ba6cdf3 100755 --- a/Firmware/UI/Widgets/MainPageButton.h +++ b/Firmware/UI/Widgets/MainPageButton.h @@ -27,7 +27,6 @@ class MainPageButton : public IButton char* _value; bool _invertOrder; - bool _highlighted; Font _labelFont; Font _valueFont; @@ -35,42 +34,40 @@ class MainPageButton : public IButton ButtonType _type; // Color Defintions - uint16_t labelTextColor; - uint16_t labelBackgroundColor; - uint16_t valueTextColor; - uint16_t valueBackgroundColor; - uint16_t textHighlightColor; - uint16_t backgroundHighlightColor; - - uint16_t currentLabelTextColor; - uint16_t currentLabelBackgroundColor; - uint16_t currentValueTextColor; - uint16_t currentValueBackgroundColor; + static constexpr uint8_t _stateCount = 3; + static constexpr uint8_t _colorsPerState = 4; + uint16_t _colors[_stateCount * _colorsPerState]; // bool _hideValue; public: - MainPageButton() : IButton() + enum Colors : uint8_t + { + LabelText = 0, + LabelBackground = 1, + ValueText = 2, + ValueBackground = 3, + }; + + MainPageButton() : IButton(_stateCount, _colorsPerState, _colors) { } // TODO: Check if customizable height is required for this button, if yes, add it later MainPageButton(uint16_t x, uint16_t y, uint16_t width, const char* label = "...", bool invertOrder = false, ButtonType type = ButtonType::VALUE_AND_LABEL) : - _x(x), - _y(y), _width(width), _labelHeight(20), _valueHeight(40), _label((char*)label), _value((char*)"..."), + IButton(_stateCount, _colorsPerState, _colors), + _x(x), _y(y), _width(width), _labelHeight(20), _valueHeight(40), _label((char*)label), _value((char*)"..."), _invertOrder(invertOrder), _labelFont(Font::FreeSans9pt7b), _valueFont(Font::FreeSans12pt7b), _type(type) { - currentLabelTextColor = labelTextColor = (uint16_t)Color565::White; - currentLabelBackgroundColor = labelBackgroundColor = (uint16_t)Color565::Black; - currentValueTextColor = valueTextColor = (uint16_t)Color565::Black; - currentValueBackgroundColor = valueBackgroundColor = (uint16_t)Color565::White; - - backgroundHighlightColor = (uint16_t)Color565::AXIOM_Orange; - textHighlightColor = (uint16_t)Color565::Black; + SetColor(ButtonState::Default, Colors::LabelText, static_cast(Color565::White)); + SetColor(ButtonState::Default, Colors::LabelBackground, static_cast(Color565::Black)); + SetColor(ButtonState::Default, Colors::ValueText, static_cast(Color565::Black)); + SetColor(ButtonState::Default, Colors::ValueBackground, static_cast(Color565::White)); - _highlighted = false; + SetColor(ButtonState::Highlighted, Colors::ValueBackground, static_cast(Color565::AXIOM_Orange)); + SetColor(ButtonState::Highlighted, Colors::ValueText, static_cast(Color565::Black)); } void Draw(IPainter* painter) override @@ -102,24 +99,27 @@ class MainPageButton : public IButton void DrawButton(IPainter* painter) { - painter->DrawFillRoundRectangle(_x, _y, _width, _labelHeight, 3, currentLabelBackgroundColor); + painter->DrawFillRoundRectangle(_x, _y, _width, _labelHeight, 3, GetCurrentColor(Colors::LabelBackground)); painter->SetFont(_labelFont); - painter->DrawText(_x, _y + 24, _label, currentLabelTextColor, TextAlign::TEXT_ALIGN_CENTER, _width); + painter->DrawText(_x, _y + 24, _label, GetCurrentColor(Colors::LabelText), TextAlign::TEXT_ALIGN_CENTER, + _width); } void DrawLabelBox(IPainter* painter, int8_t verticaloffset, int8_t verticaltextoffset) { - painter->DrawFillRoundRectangle(_x, _y + verticaloffset, _width, _labelHeight, 3, currentLabelBackgroundColor); + painter->DrawFillRoundRectangle(_x, _y + verticaloffset, _width, _labelHeight, 3, + GetCurrentColor(Colors::LabelBackground)); painter->SetFont(_labelFont); - painter->DrawText(_x, _y + verticaloffset + verticaltextoffset, _label, currentLabelTextColor, + painter->DrawText(_x, _y + verticaloffset + verticaltextoffset, _label, GetCurrentColor(Colors::LabelText), TextAlign::TEXT_ALIGN_CENTER, _width); } void DrawValueBox(IPainter* painter, int8_t verticaloffset, int8_t verticaltextoffset) { - painter->DrawFillRoundRectangle(_x, _y + verticaloffset, _width, _valueHeight, 3, currentValueBackgroundColor); + painter->DrawFillRoundRectangle(_x, _y + verticaloffset, _width, _valueHeight, 3, + GetCurrentColor(Colors::ValueBackground)); painter->SetFont(_valueFont); - painter->DrawText(_x, _y + verticaloffset + verticaltextoffset, _value, currentValueTextColor, + painter->DrawText(_x, _y + verticaloffset + verticaltextoffset, _value, GetCurrentColor(Colors::ValueText), TextAlign::TEXT_ALIGN_CENTER, _width); } @@ -166,24 +166,6 @@ class MainPageButton : public IButton { _labelHeight = height; } - - void SetHighlighted(bool highlighted) - { - _highlighted = highlighted; - if (highlighted) - { - currentLabelTextColor = textHighlightColor; - currentLabelBackgroundColor = backgroundHighlightColor; - currentValueTextColor = valueBackgroundColor; - currentValueBackgroundColor = valueTextColor; - } else - { - currentLabelTextColor = labelTextColor; - currentLabelBackgroundColor = labelBackgroundColor; - currentValueTextColor = valueTextColor; - currentValueBackgroundColor = valueBackgroundColor; - } - }; }; #endif /* MAINPAGEBUTTON_H */ diff --git a/Firmware/UI/Widgets/PushButton.h b/Firmware/UI/Widgets/PushButton.h index cedd7c4..db98ed0 100644 --- a/Firmware/UI/Widgets/PushButton.h +++ b/Firmware/UI/Widgets/PushButton.h @@ -10,27 +10,27 @@ class PushButton : public IButton { const char* _label; uint8_t _cornerRadius; - bool _highlighted; // Color Defintions - uint16_t _TextColor; - uint16_t _BackgroundColor; - - uint16_t _textHighlightColor; - uint16_t _backgroundHighlightColor; - - uint16_t _currentTextColor; - uint16_t _currentBackgroundColor; + static constexpr uint8_t _stateCount = 3; + static constexpr uint8_t _colorsPerState = 2; + uint16_t _colors[_stateCount * _colorsPerState]; public: + enum Colors : uint8_t + { + Text = 0, + Background = 1, + }; + explicit PushButton(const char* label, uint16_t x = 0, uint16_t y = 0, uint16_t width = 0, uint16_t height = 0) : - IButton(x, y, width, height), _label(label), _cornerRadius(3), _highlighted(false) + IButton(_stateCount, _colorsPerState, _colors, x, y, width, height), _label(label), _cornerRadius(3) { - _currentTextColor = _TextColor = (uint16_t)Color565::Black; - _currentBackgroundColor = _BackgroundColor = utils::RGB565(220, 220, 220); + SetColor(ButtonState::Default, Colors::Text, (uint16_t)Color565::Black); + SetColor(ButtonState::Default, Colors::Background, (uint16_t)utils::RGB565(220, 220, 220)); - _backgroundHighlightColor = (uint16_t)Color565::AXIOM_Blue; - _textHighlightColor = (uint16_t)Color565::Black; + SetColor(ButtonState::Highlighted, Colors::Text, (uint16_t)Color565::Black); + SetColor(ButtonState::Highlighted, Colors::Background, (uint16_t)Color565::AXIOM_Blue); } void SetCornerRadius(uint8_t cornerRadius) @@ -45,51 +45,12 @@ class PushButton : public IButton virtual void Draw(IPainter* painter) override { - painter->DrawFillRoundRectangle(_x, _y, _width, _height, _cornerRadius, _currentBackgroundColor); + painter->DrawFillRoundRectangle(_x, _y, _width, _height, _cornerRadius, GetCurrentColor(Colors::Background)); painter->SetFont(Font::FreeSans12pt7b); uint8_t textPosY = _height / 2 + painter->GetCurrentFontHeight() / 2; - painter->DrawText(_x + _width / 2, _y + textPosY, _label, _currentTextColor, TextAlign::TEXT_ALIGN_CENTER, - strlen(_label)); - } - - void SetBackgroundColor(uint16_t color) - { - _BackgroundColor = color; - SetHighlighted(_highlighted); - } - - void SetTextColor(uint16_t color) - { - _TextColor = color; - SetHighlighted(_highlighted); - } - - void SetHighlightBackgroundColor(uint16_t color) - { - _backgroundHighlightColor = color; - SetHighlighted(_highlighted); - } - - void SetHighlightTextColor(uint16_t color) - { - _textHighlightColor = color; - SetHighlighted(_highlighted); - } - - void SetHighlighted(bool highlighted) - { - _highlighted = highlighted; - if (highlighted) - { - _currentTextColor = _textHighlightColor; - _currentBackgroundColor = _backgroundHighlightColor; - - } else - { - _currentTextColor = _TextColor; - _currentBackgroundColor = _BackgroundColor; - } + painter->DrawText(_x + _width / 2, _y + textPosY, _label, GetCurrentColor(Colors::Text), + TextAlign::TEXT_ALIGN_CENTER, strlen(_label)); } }; diff --git a/Firmware/UI/Widgets/ToggleButton.h b/Firmware/UI/Widgets/ToggleButton.h index e092b23..678fcf8 100644 --- a/Firmware/UI/Widgets/ToggleButton.h +++ b/Firmware/UI/Widgets/ToggleButton.h @@ -28,8 +28,8 @@ class ToggleButton : public IButton public: explicit ToggleButton(const char* label, uint16_t x = 0, uint16_t y = 0, uint16_t width = 0, uint16_t height = 0) : - IButton(x, y, width, height), _label(label), _cornerRadius(3), _highlighted(false), _checked(true), - _currentTextColor((uint16_t)Color565::Black), _textColor(_currentTextColor), + IButton(0, 0, nullptr, x, y, width, height), _label(label), _cornerRadius(3), _highlighted(false), + _checked(true), _currentTextColor((uint16_t)Color565::Black), _textColor(_currentTextColor), _currentBackgroundColor(utils::RGB565(220, 220, 220)), _backgroundColor(_currentBackgroundColor), _textDisabledColor(utils::RGB565(180, 180, 180)), _backgroundHighlightColor((uint16_t)Color565::AXIOM_Blue), _textHighlightColor((uint16_t)Color565::Black)