Skip to content

Commit

Permalink
Improve UI
Browse files Browse the repository at this point in the history
  • Loading branch information
NaejEL committed Nov 11, 2022
1 parent e12ba00 commit b3c662a
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 38 deletions.
2 changes: 1 addition & 1 deletion i2ctools.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int32_t i2ctools_app(void* p) {
}
} else if(event.key == InputKeyDown && event.type == InputTypeRelease) {
if(i2ctools->main_view->current_view == MAIN_VIEW) {
if(i2ctools->main_view->menu_index < MENU_SIZE) {
if(i2ctools->main_view->menu_index < MENU_SIZE - 1) {
i2ctools->main_view->menu_index++;
}
} else if(i2ctools->main_view->current_view == SCAN_VIEW) {
Expand Down
Binary file added images/i2ctools_main_76x59.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions views/main_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ void draw_main_view(Canvas* canvas, i2cMainView* main_view) {
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_draw_rframe(canvas, 0, 0, 128, 64, 3);
canvas_draw_icon(canvas, 2, 13, &I_passport_bad3_46x49);
canvas_draw_icon(canvas, 2, 2, &I_i2ctools_main_76x59);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 3, 3, AlignLeft, AlignTop, APP_NAME);
//canvas_draw_str_aligned(canvas, 3, 3, AlignLeft, AlignTop, APP_NAME);

switch(main_view->menu_index) {
case SCAN_VIEW:
Expand All @@ -15,7 +15,7 @@ void draw_main_view(Canvas* canvas, i2cMainView* main_view) {
canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
canvas_draw_str_aligned(
canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);
canvas_draw_rbox(canvas, 60, SCAN_MENU_Y - 2, 60, 13, 3);
canvas_draw_rbox(canvas, 80, SCAN_MENU_Y - 2, 43, 13, 3);
canvas_set_color(canvas, ColorWhite);
canvas_draw_str_aligned(
canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT);
Expand All @@ -27,7 +27,7 @@ void draw_main_view(Canvas* canvas, i2cMainView* main_view) {
canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT);
canvas_draw_str_aligned(
canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);
canvas_draw_rbox(canvas, 60, SNIFF_MENU_Y - 2, 60, 13, 3);
canvas_draw_rbox(canvas, 80, SNIFF_MENU_Y - 2, 43, 13, 3);
canvas_set_color(canvas, ColorWhite);
canvas_draw_str_aligned(
canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
Expand All @@ -39,7 +39,7 @@ void draw_main_view(Canvas* canvas, i2cMainView* main_view) {
canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT);
canvas_draw_str_aligned(
canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
canvas_draw_rbox(canvas, 60, SEND_MENU_Y - 2, 60, 13, 3);
canvas_draw_rbox(canvas, 80, SEND_MENU_Y - 2, 43, 13, 3);
canvas_set_color(canvas, ColorWhite);
canvas_draw_str_aligned(
canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);
Expand Down
6 changes: 3 additions & 3 deletions views/main_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
#define APP_NAME "I2C Tools"

#define SCAN_MENU_TEXT "Scan"
#define SCAN_MENU_X 75
#define SCAN_MENU_X 90
#define SCAN_MENU_Y 6

#define SNIFF_MENU_TEXT "Sniff"
#define SNIFF_MENU_X 75
#define SNIFF_MENU_X 90
#define SNIFF_MENU_Y 20

#define SEND_MENU_TEXT "Send"
#define SEND_MENU_X 75
#define SEND_MENU_X 90
#define SEND_MENU_Y 34

// Menu
Expand Down
29 changes: 11 additions & 18 deletions views/scanner_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ void draw_scanner_view(Canvas* canvas, i2cScanner* i2c_scanner) {
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_draw_rframe(canvas, 0, 0, 128, 64, 3);
canvas_draw_icon(canvas, 2, 13, &I_passport_happy3_46x49);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 3, 3, AlignLeft, AlignTop, SCAN_MENU_TEXT);

char count_text[46];
char count_text_fmt[] = "Found: %d";
Expand All @@ -23,21 +20,16 @@ void draw_scanner_view(Canvas* canvas, i2cScanner* i2c_scanner) {
}
snprintf(
count_text, sizeof(count_text), "0x%02x ", (int)i2c_scanner->addresses[idx_to_print]);
if(i < 3) {
x_pos = 50 + (i * 26);
const uint8_t x_start = 13;
if(i < 4) {
x_pos = x_start + (i * 26);
y_pos = 15;
} else if(i < 6) {
x_pos = 50 + ((i - 3) * 26);
} else if(i < 8) {
x_pos = x_start + ((i - 4) * 26);
y_pos = 25;
} else if(i < 9) {
x_pos = 50 + ((i - 6) * 26);
y_pos = 35;
} else if(i < 12) {
x_pos = 50 + ((i - 9) * 26);
y_pos = 45;
} else if(i < 15) {
x_pos = 50 + ((i - 12) * 26);
y_pos = 55;
x_pos = x_start + ((i - 8) * 26);
y_pos = 35;
} else {
break;
}
Expand All @@ -48,8 +40,9 @@ void draw_scanner_view(Canvas* canvas, i2cScanner* i2c_scanner) {
canvas_draw_rbox(canvas, 125, y_pos, 3, 10, 1);

// Button
canvas_draw_rbox(canvas, 70, 48, 45, 13, 3);
canvas_draw_rbox(canvas, 45, 48, 45, 13, 3);
canvas_set_color(canvas, ColorWhite);
canvas_draw_icon(canvas, 75, 50, &I_Ok_btn_9x9);
canvas_draw_str_aligned(canvas, 85, 51, AlignLeft, AlignTop, "Scan");
canvas_draw_icon(canvas, 50, 50, &I_Ok_btn_9x9);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 62, 50, AlignLeft, AlignTop, "Scan");
}
4 changes: 1 addition & 3 deletions views/scanner_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <i2cTools_icons.h>
#include "../i2cscanner.h"

#define SCAN_MENU_TEXT "Scan"
#define SCAN_MENU_X 75
#define SCAN_MENU_Y 6
#define SCAN_TEXT "SCAN"

void draw_scanner_view(Canvas* canvas, i2cScanner* i2c_scanner);
2 changes: 1 addition & 1 deletion views/sender_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void draw_sender_view(Canvas* canvas, i2cSender* i2c_sender) {
canvas_draw_rframe(canvas, 0, 0, 128, 64, 3);
canvas_draw_icon(canvas, 2, 13, &I_passport_happy2_46x49);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 3, 3, AlignLeft, AlignTop, SEND_MENU_TEXT);
canvas_draw_str_aligned(canvas, 3, 3, AlignLeft, AlignTop, SEND_TEXT);

if(!i2c_sender->scanner->scanned) {
scan_i2c_bus(i2c_sender->scanner);
Expand Down
4 changes: 1 addition & 3 deletions views/sender_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <i2cTools_icons.h>
#include "../i2csender.h"

#define SEND_MENU_TEXT "Send"
#define SEND_MENU_X 75
#define SEND_MENU_Y 34
#define SEND_TEXT "SEND"

void draw_sender_view(Canvas* canvas, i2cSender* i2c_sender);
2 changes: 1 addition & 1 deletion views/sniffer_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ void draw_sniffer_view(Canvas* canvas, i2cSniffer* i2c_sniffer) {
canvas_draw_icon(canvas, 2, 13, &I_passport_happy2_46x49);

canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 3, 3, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
canvas_draw_str_aligned(canvas, 3, 3, AlignLeft, AlignTop, SNIFF_TEXT);
canvas_set_font(canvas, FontSecondary);

// Button
Expand Down
4 changes: 1 addition & 3 deletions views/sniffer_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <i2cTools_icons.h>
#include "../i2csniffer.h"

#define SNIFF_MENU_TEXT "Sniff"
#define SNIFF_MENU_X 75
#define SNIFF_MENU_Y 20
#define SNIFF_TEXT "SNIFF"

void draw_sniffer_view(Canvas* canvas, i2cSniffer* i2c_sniffer);

0 comments on commit b3c662a

Please sign in to comment.