Skip to content

Commit

Permalink
Theme system (#2164)
Browse files Browse the repository at this point in the history
* Themes instead of Styles
* Colors changed to theme colors
* Reworked style management
* Theme settings app
* warn, menu dual set
* Added Aqua style
  • Loading branch information
htotoo committed May 27, 2024
1 parent a8203a6 commit ced8012
Show file tree
Hide file tree
Showing 143 changed files with 1,568 additions and 1,156 deletions.
2 changes: 1 addition & 1 deletion firmware/application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ set(CPPSRC
spectrum_color_lut.cpp
string_format.cpp
temperature_logger.cpp
theme.cpp
touch.cpp
tone_key.cpp
transmitter_model.cpp
Expand Down Expand Up @@ -258,7 +259,6 @@ set(CPPSRC
ui/ui_freqlist.cpp
ui/ui_tv.cpp
ui/ui_spectrum.cpp
ui/ui_styles.cpp
ui/ui_tabview.cpp
ui/ui_textentry.cpp
ui/ui_tone_key.cpp
Expand Down
22 changes: 10 additions & 12 deletions firmware/application/apps/analog_audio_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ namespace ui {

/* AMOptionsView *********************************************************/

static const Style& style_options_group = Styles::bg_blue;

AMOptionsView::AMOptionsView(
Rect parent_rect,
const Style* style)
Expand Down Expand Up @@ -297,13 +295,13 @@ void AnalogAudioView::set_options_widget(std::unique_ptr<Widget> new_widget) {
options_widget = std::move(new_widget);
} else {
// TODO: Lame hack to hide options view due to my bad paint/damage algorithm.
options_widget = std::make_unique<Rectangle>(options_view_rect, style_options_group.background);
options_widget = std::make_unique<Rectangle>(options_view_rect, Theme::getInstance()->option_active->background);
}
add_child(options_widget.get());
}

void AnalogAudioView::on_show_options_frequency() {
auto widget = std::make_unique<FrequencyOptionsView>(options_view_rect, &style_options_group);
auto widget = std::make_unique<FrequencyOptionsView>(options_view_rect, Theme::getInstance()->option_active);

widget->set_step(receiver_model.frequency_step());
widget->on_change_step = [this](rf::Frequency f) {
Expand All @@ -315,14 +313,14 @@ void AnalogAudioView::on_show_options_frequency() {
};

set_options_widget(std::move(widget));
field_frequency.set_style(&style_options_group);
field_frequency.set_style(Theme::getInstance()->option_active);
}

void AnalogAudioView::on_show_options_rf_gain() {
auto widget = std::make_unique<RadioGainOptionsView>(options_view_rect, &style_options_group);
auto widget = std::make_unique<RadioGainOptionsView>(options_view_rect, Theme::getInstance()->option_active);

set_options_widget(std::move(widget));
field_lna.set_style(&style_options_group);
field_lna.set_style(Theme::getInstance()->option_active);
}

void AnalogAudioView::on_show_options_modulation() {
Expand All @@ -331,25 +329,25 @@ void AnalogAudioView::on_show_options_modulation() {
const auto modulation = receiver_model.modulation();
switch (modulation) {
case ReceiverModel::Mode::AMAudio:
widget = std::make_unique<AMOptionsView>(options_view_rect, &style_options_group);
widget = std::make_unique<AMOptionsView>(options_view_rect, Theme::getInstance()->option_active);
waterfall.show_audio_spectrum_view(false);
text_ctcss.hidden(true);
break;

case ReceiverModel::Mode::NarrowbandFMAudio:
widget = std::make_unique<NBFMOptionsView>(nbfm_view_rect, &style_options_group);
widget = std::make_unique<NBFMOptionsView>(nbfm_view_rect, Theme::getInstance()->option_active);
waterfall.show_audio_spectrum_view(false);
text_ctcss.hidden(false);
break;

case ReceiverModel::Mode::WidebandFMAudio:
widget = std::make_unique<WFMOptionsView>(options_view_rect, &style_options_group);
widget = std::make_unique<WFMOptionsView>(options_view_rect, Theme::getInstance()->option_active);
waterfall.show_audio_spectrum_view(true);
text_ctcss.hidden(true);
break;

case ReceiverModel::Mode::SpectrumAnalysis:
widget = std::make_unique<SPECOptionsView>(this, nbfm_view_rect, &style_options_group);
widget = std::make_unique<SPECOptionsView>(this, nbfm_view_rect, Theme::getInstance()->option_active);
waterfall.show_audio_spectrum_view(false);
text_ctcss.hidden(true);
break;
Expand All @@ -360,7 +358,7 @@ void AnalogAudioView::on_show_options_modulation() {
}

set_options_widget(std::move(widget));
options_modulation.set_style(&style_options_group);
options_modulation.set_style(Theme::getInstance()->option_active);
}

void AnalogAudioView::on_frequency_step_changed(rf::Frequency f) {
Expand Down
1 change: 0 additions & 1 deletion firmware/application/apps/analog_audio_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "ui_freq_field.hpp"
#include "ui_spectrum.hpp"
#include "ui_record_view.hpp"
#include "ui_styles.hpp"
#include "app_settings.hpp"
#include "radio_state.hpp"
#include "tone_key.hpp"
Expand Down
8 changes: 4 additions & 4 deletions firmware/application/apps/ble_comm_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ class BLECommView : public View {
{24 * 8, 5, 6 * 8, 4}};

Labels label_send_adv{
{{0 * 8, 2 * 8}, "Send Advertisement:", Color::light_grey()}};
{{0 * 8, 2 * 8}, "Send Advertisement:", Theme::getInstance()->fg_light->foreground}};

ImageButton button_send_adv{
{21 * 8, 1 * 16, 10 * 8, 2 * 16},
&bitmap_play,
Color::green(),
Color::black()};
Theme::getInstance()->fg_green->foreground,
Theme::getInstance()->fg_green->background};

Checkbox check_log{
{24 * 8, 2 * 8},
Expand All @@ -163,7 +163,7 @@ class BLECommView : public View {
true};

Labels label_packets_sent{
{{0 * 8, 4 * 8}, "Packets Left:", Color::light_grey()}};
{{0 * 8, 4 * 8}, "Packets Left:", Theme::getInstance()->fg_light->foreground}};

Text text_packets_sent{
{13 * 8, 2 * 16, 12 * 8, 16},
Expand Down
14 changes: 7 additions & 7 deletions firmware/application/apps/ble_rx_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,23 @@ class BleRecentEntryDetailView : public View {
static constexpr uint8_t total_data_lines{5};

Labels label_mac_address{
{{0 * 8, 0 * 16}, "Mac Address:", Color::light_grey()}};
{{0 * 8, 0 * 16}, "Mac Address:", Theme::getInstance()->fg_light->foreground}};

Text text_mac_address{
{12 * 8, 0 * 16, 17 * 8, 16},
"-"};

Labels label_pdu_type{
{{0 * 8, 1 * 16}, "PDU Type:", Color::light_grey()}};
{{0 * 8, 1 * 16}, "PDU Type:", Theme::getInstance()->fg_light->foreground}};

Text text_pdu_type{
{9 * 8, 1 * 16, 17 * 8, 16},
"-"};

Labels labels{
{{0 * 8, 3 * 16}, "Len", Color::light_grey()},
{{5 * 8, 3 * 16}, "Type", Color::light_grey()},
{{10 * 8, 3 * 16}, "Value", Color::light_grey()},
{{0 * 8, 3 * 16}, "Len", Theme::getInstance()->fg_light->foreground},
{{5 * 8, 3 * 16}, "Type", Theme::getInstance()->fg_light->foreground},
{{10 * 8, 3 * 16}, "Value", Theme::getInstance()->fg_light->foreground},
};

Button button_send{
Expand Down Expand Up @@ -286,7 +286,7 @@ class BLERxView : public View {
{24 * 8, 5, 6 * 8, 4}};

Labels label_sort{
{{0 * 8, 3 * 8}, "Sort:", Color::light_grey()}};
{{0 * 8, 3 * 8}, "Sort:", Theme::getInstance()->fg_light->foreground}};

OptionsField options_sort{
{5 * 8, 3 * 8},
Expand Down Expand Up @@ -318,7 +318,7 @@ class BLERxView : public View {
"Find"};

Labels label_found{
{{5 * 8, 6 * 8}, "Found:", Color::light_grey()}};
{{5 * 8, 6 * 8}, "Found:", Theme::getInstance()->fg_light->foreground}};

Text text_found_count{
{11 * 8, 3 * 16, 20 * 8, 16},
Expand Down
16 changes: 8 additions & 8 deletions firmware/application/apps/ble_tx_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ class BLETxView : public View {
ImageButton button_play{
{28 * 8, 2 * 16, 2 * 8, 1 * 16},
&bitmap_play,
Color::green(),
Color::black()};
Theme::getInstance()->fg_green->foreground,
Theme::getInstance()->fg_green->background};

Labels label_speed{
{{0 * 8, 6 * 8}, "Speed:", Color::light_grey()}};
{{0 * 8, 6 * 8}, "Speed:", Theme::getInstance()->fg_light->foreground}};

OptionsField options_speed{
{7 * 8, 6 * 8},
Expand Down Expand Up @@ -254,7 +254,7 @@ class BLETxView : public View {
{"CONNECT_REQ", PKT_TYPE_CONNECT_REQ}}};

Labels label_marked_data{
{{0 * 8, 4 * 16}, "Marked Data:", Color::light_grey()}};
{{0 * 8, 4 * 16}, "Marked Data:", Theme::getInstance()->fg_light->foreground}};

OptionsField marked_data_sequence{
{12 * 8, 8 * 8},
Expand All @@ -264,28 +264,28 @@ class BLETxView : public View {
{"Random", 2}}};

Labels label_packet_index{
{{0 * 8, 12 * 8}, "Packet Index:", Color::light_grey()}};
{{0 * 8, 12 * 8}, "Packet Index:", Theme::getInstance()->fg_light->foreground}};

Text text_packet_index{
{13 * 8, 6 * 16, 12 * 8, 16},
"-"};

Labels label_packets_sent{
{{0 * 8, 14 * 8}, "Repeat Count:", Color::light_grey()}};
{{0 * 8, 14 * 8}, "Repeat Count:", Theme::getInstance()->fg_light->foreground}};

Text text_packets_sent{
{13 * 8, 7 * 16, 12 * 8, 16},
"-"};

Labels label_mac_address{
{{0 * 8, 16 * 8}, "Mac Address:", Color::light_grey()}};
{{0 * 8, 16 * 8}, "Mac Address:", Theme::getInstance()->fg_light->foreground}};

Text text_mac_address{
{12 * 8, 8 * 16, 20 * 8, 16},
"-"};

Labels label_data_packet{
{{0 * 8, 9 * 16}, "Packet Data:", Color::light_grey()}};
{{0 * 8, 9 * 16}, "Packet Data:", Theme::getInstance()->fg_light->foreground}};

Console console{
{0, 9 * 18, 240, 240}};
Expand Down
4 changes: 2 additions & 2 deletions firmware/application/apps/capture_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class CaptureAppView : public View {
"rx_capture", app_settings::Mode::RX};

Labels labels{
{{0 * 8, 1 * 16}, "Rate:", Color::light_grey()},
{{11 * 8, 1 * 16}, "Format:", Color::light_grey()},
{{0 * 8, 1 * 16}, "Rate:", Theme::getInstance()->fg_light->foreground},
{{11 * 8, 1 * 16}, "Format:", Theme::getInstance()->fg_light->foreground},
};

RSSI rssi{
Expand Down
26 changes: 13 additions & 13 deletions firmware/application/apps/pocsag_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ void POCSAGAppView::refresh_ui() {
// Set console font style.
console.set_style(
settings_.enable_small_font
? &Styles::white_small
: &Styles::white);
? Theme::getInstance()->bg_darkest_small
: Theme::getInstance()->bg_darkest);

// Update filter button text.
std::string btn_text = "Filter Last";
Expand Down Expand Up @@ -260,19 +260,19 @@ void POCSAGAppView::handle_decoded(Timestamp timestamp, const std::string& prefi

static Color get_status_color(const POCSAGState& state) {
if (state.out_type == IDLE)
return Color::white();
return Theme::getInstance()->bg_darkest->foreground;

switch (state.mode) {
case STATE_CLEAR:
return Color::cyan();
return Theme::getInstance()->fg_cyan->foreground;
case STATE_HAVE_ADDRESS:
return Color::yellow();
return Theme::getInstance()->fg_yellow->foreground;
case STATE_GETTING_MSG:
return Color::green();
return Theme::getInstance()->fg_green->foreground;
}

// Shouldn't get here...
return Color::red();
return Theme::getInstance()->fg_red->foreground;
}

void POCSAGAppView::on_packet(const POCSAGPacketMessage* message) {
Expand All @@ -294,7 +294,7 @@ void POCSAGAppView::on_packet(const POCSAGPacketMessage* message) {
last_address = 0;
} else {
// Set color before to be able to see if decode gets stuck.
image_status.set_foreground(Color::magenta());
image_status.set_foreground(Theme::getInstance()->fg_magenta->foreground);
pocsag_state.codeword_index = 0;
pocsag_state.errors = 0;

Expand Down Expand Up @@ -332,8 +332,8 @@ void BaudIndicator::paint(Painter& painter) {
bot = (r % 10) + '0';
}

painter.draw_char(p, Styles::white_small, top);
painter.draw_char({p.x(), p.y() + 8}, Styles::white_small, bot);
painter.draw_char(p, *Theme::getInstance()->bg_darkest_small, top);
painter.draw_char({p.x(), p.y() + 8}, *Theme::getInstance()->bg_darkest_small, bot);
}

void BitsIndicator::paint(Painter&) {
Expand All @@ -343,17 +343,17 @@ void BitsIndicator::paint(Painter&) {

int x = p.x() + (i / height);
int y = p.y() + (i % height);
display.draw_pixel({x, y}, is_set ? Color::white() : Color::black());
display.draw_pixel({x, y}, is_set ? Theme::getInstance()->bg_darkest->foreground : Theme::getInstance()->bg_darkest->background);
}
}

void FrameIndicator::paint(Painter& painter) {
auto p = screen_pos();
painter.draw_rectangle({p, {2, height}}, has_sync_ ? Color::green() : Color::grey());
painter.draw_rectangle({p, {2, height}}, has_sync_ ? Theme::getInstance()->fg_green->foreground : Theme::getInstance()->bg_medium->background);

for (size_t i = 0; i < height; ++i) {
auto p2 = p + Point{2, 15 - (int)i};
painter.draw_hline(p2, 2, i < frame_count_ ? Color::white() : Color::black());
painter.draw_hline(p2, 2, i < frame_count_ ? Theme::getInstance()->bg_darkest->foreground : Theme::getInstance()->bg_darkest->background);
}
}

Expand Down
9 changes: 4 additions & 5 deletions firmware/application/apps/pocsag_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "ui_freq_field.hpp"
#include "ui_receiver.hpp"
#include "ui_rssi.hpp"
#include "ui_styles.hpp"

#include "app_settings.hpp"
#include "log_file.hpp"
Expand Down Expand Up @@ -141,8 +140,8 @@ class POCSAGSettingsView : public View {
POCSAGSettings& settings_;

Labels labels{
{{2 * 8, 12 * 16}, "Filter Mode:", Color::light_grey()},
{{2 * 8, 13 * 16}, "Filter Addr:", Color::light_grey()},
{{2 * 8, 12 * 16}, "Filter Mode:", Theme::getInstance()->fg_light->foreground},
{{2 * 8, 13 * 16}, "Filter Addr:", Theme::getInstance()->fg_light->foreground},
};

Checkbox check_log{
Expand Down Expand Up @@ -265,8 +264,8 @@ class POCSAGAppView : public View {
Image image_status{
{0 * 8 + 4, 1 * 16 + 2, 16, 16},
&bitmap_icon_pocsag,
Color::white(),
Color::black()};
Theme::getInstance()->bg_darkest->foreground,
Theme::getInstance()->bg_darkest->background};

Text text_packet_count{
{3 * 8, 1 * 16 + 2, 5 * 8, 16},
Expand Down
4 changes: 2 additions & 2 deletions firmware/application/apps/replay_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ class ReplayAppView : public View {
ImageButton button_play{
{28 * 8, 2 * 16, 2 * 8, 1 * 16},
&bitmap_play,
Color::green(),
Color::black()};
Theme::getInstance()->fg_green->foreground,
Theme::getInstance()->fg_green->background};

spectrum::WaterfallView waterfall{};

Expand Down
2 changes: 1 addition & 1 deletion firmware/application/apps/soundboard_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void SoundBoardView::refresh_list() {

for (size_t n = 0; n < file_list.size(); n++) {
menu_view.add_item({file_list[n].string().substr(0, 30),
ui::Color::dark_magenta(),
ui::Theme::getInstance()->fg_magenta->foreground,
nullptr,
[this](KeyEvent) {
on_select_entry();
Expand Down
4 changes: 2 additions & 2 deletions firmware/application/apps/soundboard_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class SoundBoardView : public View {
void on_select_entry();

Labels labels{
{{24 * 8, 180}, "Vol:", Color::light_grey()},
{{0, 180}, "Key:", Color::light_grey()}};
{{24 * 8, 180}, "Vol:", Theme::getInstance()->fg_light->foreground},
{{0, 180}, "Key:", Theme::getInstance()->fg_light->foreground}};

Button button_next_page{
{30 * 7, 25 * 8, 10 * 3, 2 * 14},
Expand Down
Loading

0 comments on commit ced8012

Please sign in to comment.