Consolidate styles (#1116)

* Consolidate styles into a Styles class and clean up code

* Format

* Add style_bg_dark_grey for nav bar

* Fix bugs found in PR

* Rename styles

* Add bg_white style

---------

Co-authored-by: kallanreed <kallanreed@outlook.com>
Co-authored-by: gullradriel <3157857+gullradriel@users.noreply.github.com>
This commit is contained in:
Kyle Reed
2023-06-07 08:33:32 -07:00
committed by GitHub
parent 496b124baf
commit 0f28fefc82
52 changed files with 299 additions and 400 deletions

View File

@@ -69,9 +69,9 @@ void FreqManUIList::paint(Painter& painter) {
if (freqlist_db.size() == 0)
return;
// coloration if file is too big
Style* text_color = &style_default;
auto text_color = &Styles::white;
if (freqlist_db.size() > FREQMAN_MAX_PER_FILE)
text_color = &style_yellow;
text_color = &Styles::yellow;
uint8_t nb_lines = 0;
for (uint8_t it = current_index; it < freqlist_db.size(); it++) {
uint8_t line_height = (int)nb_lines * char_height;
@@ -84,7 +84,7 @@ void FreqManUIList::paint(Painter& painter) {
Color::white());
painter.draw_string(
{0, r.location().y() + (int)nb_lines * char_height},
style_highlight, description);
Styles::bg_white, description);
} else {
painter.draw_string(
{0, r.location().y() + (int)nb_lines * char_height},

View File

@@ -23,9 +23,9 @@
#define __UI_FREQLIST_H__
#include "ui.hpp"
#include "ui_font_fixed_5x8.hpp"
#include "ui_widget.hpp"
#include "ui_painter.hpp"
#include "ui_styles.hpp"
#include "event_m0.hpp"
#include "message.hpp"
#include "freqman.hpp"
@@ -62,21 +62,6 @@ class FreqManUIList : public Widget {
void set_db(freqman_db& db);
private:
Style style_default{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::white(),
};
Style style_highlight{
.font = font::fixed_8x16,
.background = Color::white(),
.foreground = Color::black(),
};
Style style_yellow{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::yellow(),
};
static constexpr int8_t char_height = 16;
bool instant_exec_{false};
freqman_db freqlist_db{};

View File

@@ -26,7 +26,6 @@
#include "ui.hpp"
#include "file.hpp"
#include "ui_navigation.hpp"
#include "ui_font_fixed_8x16.hpp"
#include "portapack.hpp"

View File

@@ -26,7 +26,6 @@
#include "ui.hpp"
#include "ui_navigation.hpp"
#include "ui_font_fixed_8x16.hpp"
#include "qrcodegen.hpp"
#include "portapack.hpp"

View File

@@ -0,0 +1,105 @@
/*
* Copyright (C) 2023 Kyle Reed
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "ui_styles.hpp"
#include "ui_painter.hpp"
#include "ui_font_fixed_5x8.hpp"
#include "ui_font_fixed_8x16.hpp"
using namespace ui;
const Style Styles::white{
.font = ui::font::fixed_8x16,
.background = ui::Color::black(),
.foreground = ui::Color::white(),
};
const Style Styles::bg_white{
.font = ui::font::fixed_8x16,
.background = ui::Color::white(),
.foreground = ui::Color::black(),
};
const Style Styles::white_small{
.font = font::fixed_5x8,
.background = Color::black(),
.foreground = Color::white(),
};
const Style Styles::yellow{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::yellow(),
};
const Style Styles::green{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::green(),
};
const Style Styles::red{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::red(),
};
const Style Styles::blue{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::blue(),
};
const Style Styles::bg_blue{
.font = font::fixed_8x16,
.background = Color::blue(),
.foreground = Color::white(),
};
const Style Styles::light_grey{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::light_grey(),
};
const Style Styles::grey{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::grey(),
};
const Style Styles::dark_grey{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::dark_grey(),
};
const Style Styles::bg_dark_grey{
.font = font::fixed_8x16,
.background = Color::dark_grey(),
.foreground = Color::white(),
};
const Style Styles::orange{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::orange(),
};

View File

@@ -0,0 +1,73 @@
/*
* Copyright (C) 2023 Kyle Reed
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef __UI_STYLES_H__
#define __UI_STYLES_H__
#include "ui_painter.hpp"
namespace ui {
class Styles {
public:
/* White foreground. */
static const Style white;
/* White background. */
static const Style bg_white;
/* White foreground, small font. */
static const Style white_small;
/* Yellow foreground. */
static const Style yellow;
/* Green foreground. */
static const Style green;
/* Red foreground. */
static const Style red;
/* Blue foreground. */
static const Style blue;
/* Blue background. */
static const Style bg_blue;
/* Light grey foreground. */
static const Style light_grey;
/* Grey foreground. */
static const Style grey;
/* Dark grey foreground. */
static const Style dark_grey;
/* Dark grey background. */
static const Style bg_dark_grey;
/* Orange foreground. */
static const Style orange;
};
} // namespace ui
#endif /*__UI_STYLES_H__*/

View File

@@ -21,6 +21,7 @@
*/
#include "ui_tabview.hpp"
#include "ui_font_fixed_8x16.hpp"
#include "portapack.hpp"
using namespace portapack;

View File

@@ -26,9 +26,9 @@
#include "ui.hpp"
#include "ui_navigation.hpp"
#include "ui_painter.hpp"
#include "ui_styles.hpp"
#include "ui_widget.hpp"
#include "ui_receiver.hpp"
#include "ui_font_fixed_8x16.hpp"
#include "rf_path.hpp"
@@ -73,36 +73,12 @@ class TransmitterView : public View {
void set_transmitting(const bool transmitting);
private:
const Style style_start{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::green(),
};
const Style style_stop{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::red(),
};
const Style style_locked{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::dark_grey(),
};
const Style style_power_low{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::yellow(),
};
const Style style_power_med{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::orange(),
};
const Style style_power_high{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::red(),
};
const Style& style_start = Styles::green;
const Style style_stop = Styles::red;
const Style style_locked = Styles::dark_grey;
const Style style_power_low = Styles::yellow;
const Style style_power_med = Styles::orange;
const Style style_power_high = Styles::red;
bool lock_{false};
bool transmitting_{false};
@@ -168,21 +144,9 @@ class TransmitterView2 : public View {
void paint(Painter& painter) override;
private:
const Style style_power_low{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::yellow(),
};
const Style style_power_med{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::orange(),
};
const Style style_power_high{
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::red(),
};
const Style& style_power_low = Styles::yellow;
const Style& style_power_med = Styles::orange;
const Style& style_power_high = Styles::red;
Text text_gain_amp{
{0, 3 * 8, 5 * 8, 1 * 16},