Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added custom theme builder #161

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ main/autogen_lang.*
tools/bsdiff
.idea/
managed_components/
.DS_Store
.DS_Store
.vscode/
dependencies.lock.esp32s3
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"idf.adapterTargetName": "esp32s3",
"idf.port": "/dev/ttyACM0",
"idf.openOcdConfigs": [
"board/esp32s3-builtin.cfg"
],
"files.associations": {
"storage.h": "c"
}
}
108 changes: 93 additions & 15 deletions dependencies.lock.esp32s3
Original file line number Diff line number Diff line change
@@ -1,81 +1,159 @@
dependencies:
espressif/button:
component_hash: 1f5297fe16f0ee988dbb14b6f4c91782fe2baf85025bb15cc1e0093edd3fb2ee
dependencies:
- name: espressif/cmake_utilities
registry_url: https://components.espressif.com/
require: private
version: 0.*
- name: idf
require: private
version: '>=4.0'
source:
service_url: https://api.components.espressif.com/
registry_url: https://components.espressif.com/
type: service
version: 3.2.0
espressif/cbor:
component_hash: 440f4ee4504841cc9b4f3a8ef755776a612ac9dace355514c68b999868f990ff
dependencies:
- name: idf
require: private
version: '>=4.3'
source:
service_url: https://api.components.espressif.com/
registry_url: https://components.espressif.com/
type: service
version: 0.6.0~1
espressif/cmake_utilities:
component_hash: 351350613ceafba240b761b4ea991e0f231ac7a9f59a9ee901f751bddc0bb18f
dependencies:
- name: idf
require: private
version: '>=4.1'
source:
service_url: https://api.components.espressif.com/
registry_url: https://components.espressif.com/
type: service
version: 0.5.3
espressif/esp-dsp:
component_hash: 3e7bbd487f1357a1d4944d0c85966d049501ea281b8a4c7f93f7cfedd5b7f23d
dependencies:
- name: idf
require: private
version: '>=4.2'
source:
service_url: https://api.components.espressif.com/
registry_url: https://components.espressif.com/
type: service
version: 1.4.12
espressif/esp32-camera:
component_hash: a1933162caca04a3a3bb0dca00bb56fcb3c50cd3779ab2f2b03ad8536e9bd0d0
dependencies: []
source:
service_url: https://api.components.espressif.com/
registry_url: https://components.espressif.com/
type: service
version: 2.0.9
espressif/esp_lcd_touch:
component_hash: d4d8f2dc33205797169a97a02e0d89a8982f59fe0509129b54422052b8522f59
dependencies:
- name: idf
require: private
version: '>=4.4.2'
source:
service_url: https://api.components.espressif.com/
registry_url: https://components.espressif.com/
type: service
version: 1.1.1
espressif/esp_lcd_touch_ft5x06:
component_hash: 97759953d9436a365e9427078c5b04ecce4e6a50f50cf62c68cd6bfa229b812c
dependencies:
- name: espressif/esp_lcd_touch
registry_url: https://components.espressif.com/
require: public
version: ^1.0.4
- name: idf
require: private
version: '>=4.4.2'
source:
service_url: https://api.components.espressif.com/
registry_url: https://components.espressif.com/
type: service
version: 1.0.6
espressif/esp_tinyusb:
component_hash: f151d680d6847bfcfd5d8eb6d1c3ff926c208e6b963b2e83643a141bc70baa15
dependencies:
- name: idf
require: private
version: '>=5.0'
- name: espressif/tinyusb
registry_url: https://components.espressif.com/
require: public
version: '>=0.14.2'
source:
service_url: https://api.components.espressif.com/
registry_url: https://components.espressif.com/
type: service
version: 1.4.4
espressif/libsodium:
component_hash: f6e982479a2389cb6868e8fb761cf23aba6c355a8090b3e906299807775f58a3
dependencies:
- name: idf
require: private
version: '>=4.2'
source:
service_url: https://api.components.espressif.com/
registry_url: https://components.espressif.com/
type: service
version: 1.0.20~1
espressif/nghttp:
component_hash: 5e55c2fc982f7ddd257818be86f50d60705f3fd3a39d709c399434e81d458e1e
dependencies:
- name: idf
require: private
version: '>=5.0'
source:
service_url: https://api.components.espressif.com/
registry_url: https://components.espressif.com/
type: service
version: 1.58.0
espressif/tinyusb:
component_hash: 256fd8aee92ae9f1014538b8601508907a2da386b64f6d42f35a67f9288d1b20
dependencies:
- name: idf
require: private
version: '>=5.0'
source:
service_url: https://api.components.espressif.com/
registry_url: https://components.espressif.com/
type: service
targets:
- esp32s2
- esp32s3
- esp32p4
version: 0.15.0~9
espressif/usb_host_msc:
component_hash: fb036253308af19de381558560f3a57ead7d2139cf5212b684a408caeb7753cb
dependencies:
- name: idf
require: private
version: '>=4.4.1'
source:
service_url: https://api.components.espressif.com/
registry_url: https://components.espressif.com/
type: service
targets:
- esp32s2
- esp32s3
- esp32p4
version: 1.1.2
idf:
component_hash: null
source:
type: idf
version: 5.2.2
manifest_hash: a71d5a8d6dfacd88754066af10bbd322320a68f03e2842b3633eb0f7b4644801
direct_dependencies:
- espressif/button
- espressif/cbor
- espressif/cmake_utilities
- espressif/esp-dsp
- espressif/esp32-camera
- espressif/esp_lcd_touch
- espressif/esp_lcd_touch_ft5x06
- espressif/esp_tinyusb
- espressif/libsodium
- espressif/nghttp
- espressif/tinyusb
- espressif/usb_host_msc
- idf
manifest_hash: f87516193b33af3806bb180876292cbd0a4407775edbdef8169afdad9f537888
target: esp32s3
version: 1.0.0
version: 2.0.0
6 changes: 6 additions & 0 deletions main/button_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ typedef enum {
BTN_SETTINGS_DISPLAY_BRIGHTNESS,
BTN_SETTINGS_DISPLAY_ORIENTATION,
BTN_SETTINGS_DISPLAY_THEME,
BTN_SETTINGS_CREATE_CUSTOM_THEME,
BTN_THEME_SAVE,
BTN_COLOR_RED,
BTN_COLOR_GREEN,
BTN_COLOR_BLUE,
BTN_SETTINGS_CUSTOM_THEME_EXIT,
BTN_SETTINGS_XPUB_EXPORT,
BTN_SETTINGS_QR_PINSERVER,
BTN_SETTINGS_TEMPORARY_WALLET_LOGIN,
Expand Down
11 changes: 10 additions & 1 deletion main/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const color_t GUI_BLOCKSTREAM_HIGHTLIGHT_ORANGE = 0xE0D3;
const color_t GUI_BLOCKSTREAM_HIGHTLIGHT_BLUE = 0xD318;
const color_t GUI_BLOCKSTREAM_HIGHTLIGHT_DARKGREY = 0xA210;
const color_t GUI_BLOCKSTREAM_HIGHTLIGHT_LIGHTGREY = 0xB294;
color_t CUSTOM_THEME_COLOR = 0x4c04;


typedef struct _activity_holder_t activity_holder_t;
struct _activity_holder_t {
Expand Down Expand Up @@ -110,6 +112,10 @@ extern const uint8_t statusbar_logo_start[] asm("_binary_statusbar_small_bin_gz_
extern const uint8_t statusbar_logo_end[] asm("_binary_statusbar_small_bin_gz_end");
#endif

void initialize_custom_theme_color(void) {
CUSTOM_THEME_COLOR = storage_get_custom_theme_color();
}

static void make_status_bar(void)
{
gui_view_node_t* status_parent = NULL;
Expand Down Expand Up @@ -220,8 +226,11 @@ void gui_set_highlight_color(const uint8_t theme)
case 4:
gui_highlight_color = GUI_BLOCKSTREAM_HIGHTLIGHT_LIGHTGREY;
break;
case 5:
gui_highlight_color = CUSTOM_THEME_COLOR; //custom theme
break;
default:
gui_highlight_color = GUI_BLOCKSTREAM_HIGHTLIGHT_DEFAULT; // jade green
gui_highlight_color = GUI_BLOCKSTREAM_HIGHTLIGHT_DEFAULT; //jade green
break;
}
}
Expand Down
5 changes: 4 additions & 1 deletion main/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extern const color_t GUI_BLOCKSTREAM_HIGHTLIGHT_ORANGE;
extern const color_t GUI_BLOCKSTREAM_HIGHTLIGHT_BLUE;
extern const color_t GUI_BLOCKSTREAM_HIGHTLIGHT_DARKGREY;
extern const color_t GUI_BLOCKSTREAM_HIGHTLIGHT_LIGHTGREY;
extern color_t CUSTOM_THEME_COLOR;

// -------------- Configuration -----------------

Expand Down Expand Up @@ -49,7 +50,7 @@ extern uint8_t GUI_DEFAULT_FONT;
#define GUI_SPLIT_FILL_REMAINING 0xFF

// Number of GUI themes
#define GUI_NUM_DISPLAY_THEMES 5
#define GUI_NUM_DISPLAY_THEMES 6

// Bits used to enable or disable a border
#define GUI_BORDER_TOP_BIT 0
Expand Down Expand Up @@ -399,6 +400,8 @@ typedef struct {
gui_view_node_t* last_activity_next_button;
} linked_activities_info_t;

void initialize_custom_theme_color(void);

gui_event_t gui_get_click_event(void);
void gui_set_click_event(bool use_wheel_click);

Expand Down
89 changes: 88 additions & 1 deletion main/process/dashboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ gui_activity_t* make_uninitialised_settings_activity(void);
gui_activity_t* make_locked_settings_activity(void);
gui_activity_t* make_unlocked_settings_activity(void);

gui_activity_t* make_custom_theme_activity(gui_view_node_t** red_textbox, gui_view_node_t** green_textbox, gui_view_node_t** blue_textbox);

gui_activity_t* make_wallet_settings_activity(void);
gui_activity_t* make_device_settings_activity(void);
gui_activity_t* make_usbstorage_settings_activity(bool unlocked);
Expand Down Expand Up @@ -1823,7 +1825,7 @@ static void update_home_screen_item_highlight_color(gui_view_node_t* item)
static void handle_display_theme(void)
{
static const char* THEME_NAMES[GUI_NUM_DISPLAY_THEMES]
= { "Jade Green", "Bitcoin Orange", "Liquid Blue", "Cypherpunk Black", "Open-Source Opal" };
= { "Jade Green", "Bitcoin Orange", "Liquid Blue", "Cypherpunk Black", "Open-Source Opal", "Custom Theme" };
JADE_ASSERT(GUI_NUM_DISPLAY_THEMES < GUI_FLAGS_THEMES_MASK);

const uint8_t initial_gui_flags = storage_get_gui_flags();
Expand Down Expand Up @@ -1876,6 +1878,87 @@ static void handle_display_theme(void)
}
}



void generate_color_string(char* buffer, size_t size, const char* color_name, int color_value) {
snprintf(buffer, size, "%s{%d}", color_name, color_value);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually 'const' int params where possible.
We usually JADE_ASSERT pointers and sizes/length params to functions.
We usually JADE_ASSERT the result of snprintf calls.

}

void handle_color_activity(const char* color_name, int* color, gui_view_node_t* color_text, gui_activity_t* parent_act) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert comments as above

gui_view_node_t* color_c_text = NULL;
char color_str[20];
generate_color_string(color_str, sizeof(color_str), color_name, *color);

gui_activity_t* act = make_carousel_activity(color_name, NULL, &color_c_text);
gui_update_text(color_c_text, color_str);
gui_set_current_activity(act);

int32_t ev_id;
while (gui_activity_wait_event(act, GUI_EVENT, ESP_EVENT_ANY_ID, NULL, &ev_id, NULL, 0)) {
if (ev_id == GUI_WHEEL_LEFT_EVENT) {
*color = (*color - 8 + 256) % 256;
Copy link
Collaborator

@JamieDriver JamieDriver Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe have a 'const uint16_t limit = UINT8_MAX + 1' rather than 256 or a #define ?
Maybe #define the '8' step size also.

} else if (ev_id == GUI_WHEEL_RIGHT_EVENT) {
*color = (*color + 8) % 256;
} else if (ev_id == gui_get_click_event()) {
break;
}

// Update color string and repaint
generate_color_string(color_str, sizeof(color_str), color_name, *color);
gui_update_text(color_c_text, color_str);
gui_repaint(color_c_text->parent);
Copy link
Collaborator

@JamieDriver JamieDriver Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gui_repaint() shouldn't be needed - it should do this itself.

}

// Update the original color text and return to the main activity
gui_update_text(color_text, color_str);
gui_set_current_activity(parent_act);
}

// Main custom theme handler
static void handle_custom_theme(void) {
gui_view_node_t* red_text = NULL;
gui_view_node_t* green_text = NULL;
gui_view_node_t* blue_text = NULL;

int red = 0, green = 0, blue = 0;
char red_text_str[20], green_text_str[20], blue_text_str[20];

generate_color_string(red_text_str, sizeof(red_text_str), "Red", red);
generate_color_string(green_text_str, sizeof(green_text_str), "Green", green);
generate_color_string(blue_text_str, sizeof(blue_text_str), "Blue", blue);

gui_activity_t* act = make_custom_theme_activity(&red_text, &green_text, &blue_text);
int32_t ev_id;

while (true) {
gui_set_current_activity(act);
bool ret = gui_activity_wait_event(act, GUI_BUTTON_EVENT, ESP_EVENT_ANY_ID, NULL, &ev_id, NULL, 0);
if (ret) {
if (ev_id == BTN_THEME_SAVE) {
// Save the current color combination as the custom theme color
CUSTOM_THEME_COLOR = (red << 16) | (green << 8) | blue;
storage_set_custom_theme_color(CUSTOM_THEME_COLOR);
break;
} else if (ev_id == BTN_SETTINGS_CUSTOM_THEME_EXIT) {
// Exit the custom theme screen
break;
} else if (ev_id == BTN_COLOR_RED) {
// Handle red color adjustment
handle_color_activity("Red", &red, red_text, act);
} else if (ev_id == BTN_COLOR_GREEN) {
// Handle green color adjustment
handle_color_activity("Green", &green, green_text, act);
} else if (ev_id == BTN_COLOR_BLUE) {
// Handle blue color adjustment
handle_color_activity("Blue", &blue, blue_text, act);
}
}
}
}




static void handle_flip_orientation(void)
{
const uint8_t initial_gui_flags = storage_get_gui_flags();
Expand Down Expand Up @@ -2191,6 +2274,10 @@ static void handle_settings(const bool startup_menu)
// Change to 'Device' menu
act = make_display_settings_activity();
break;
case BTN_SETTINGS_CREATE_CUSTOM_THEME:
// Change to 'Create Custom Theme' menu
handle_custom_theme();
break;

case BTN_SETTINGS_AUTHENTICATION:
case BTN_SETTINGS_OTP_EXIT:
Expand Down
Loading