From b9b36e0768466640d4a8f33ef09aeba91530f771 Mon Sep 17 00:00:00 2001 From: Jochen Hoenicke Date: Tue, 6 Feb 2018 22:34:31 +0100 Subject: [PATCH] Remove duplicated code --- firmware/layout2.c | 14 +++----------- layout.c | 22 ++++++++++++++++------ layout.h | 2 ++ 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/firmware/layout2.c b/firmware/layout2.c index 528205b..fe6c920 100644 --- a/firmware/layout2.c +++ b/firmware/layout2.c @@ -320,9 +320,7 @@ void layoutResetWord(const char *word, int pass, int word_pos, bool last) oledDrawString(left, 2 * 9, word_pos < 10 ? index_str + 1 : index_str, FONT_STANDARD); oledDrawString(left, 3 * 9, word, FONT_STANDARD | FONT_DOUBLE); oledHLine(OLED_HEIGHT - 13); - oledDrawString(OLED_WIDTH - fontCharWidth(FONT_STANDARD, '\x06') - 1, OLED_HEIGHT - 8, "\x06", FONT_STANDARD); - oledDrawStringRight(OLED_WIDTH - fontCharWidth(FONT_STANDARD, '\x06') - 3, OLED_HEIGHT - 8, btnYes, FONT_STANDARD); - oledInvert(OLED_WIDTH - oledStringWidth(btnYes, FONT_STANDARD) - fontCharWidth(FONT_STANDARD, '\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1); + layoutButtonYes(btnYes); oledRefresh(); } @@ -500,16 +498,10 @@ void layoutAddress(const char *address, const char *desc, bool qrcode, bool igno } if (!qrcode) { - static const char *btnNo = _("QR Code"); - oledDrawString(2, OLED_HEIGHT - 8, btnNo, FONT_STANDARD); - oledInvert(0, OLED_HEIGHT - 9, oledStringWidth(btnNo, FONT_STANDARD) + 3, OLED_HEIGHT - 1); + layoutButtonNo(_("QR Code")); } - static const char *btnYes = _("Continue"); - oledDrawString(OLED_WIDTH - fontCharWidth(FONT_STANDARD, '\x06') - 1, OLED_HEIGHT - 8, "\x06", FONT_STANDARD); - oledDrawStringRight(OLED_WIDTH - fontCharWidth(FONT_STANDARD, '\x06') - 3, OLED_HEIGHT - 8, btnYes, FONT_STANDARD); - oledInvert(OLED_WIDTH - oledStringWidth(btnYes, FONT_STANDARD) - fontCharWidth(FONT_STANDARD, '\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1); - + layoutButtonYes(_("Continue")); oledRefresh(); } diff --git a/layout.c b/layout.c index f29aadb..cb8302b 100644 --- a/layout.c +++ b/layout.c @@ -22,6 +22,20 @@ #include "layout.h" #include "oled.h" +void layoutButtonNo(const char *btnNo) +{ + oledDrawString(1, OLED_HEIGHT - 8, "\x15", FONT_STANDARD); + oledDrawString(fontCharWidth(FONT_STANDARD, '\x15') + 3, OLED_HEIGHT - 8, btnNo, FONT_STANDARD); + oledInvert(0, OLED_HEIGHT - 9, fontCharWidth(FONT_STANDARD, '\x15') + oledStringWidth(btnNo, FONT_STANDARD) + 2, OLED_HEIGHT - 1); +} + +void layoutButtonYes(const char *btnYes) +{ + oledDrawString(OLED_WIDTH - fontCharWidth(FONT_STANDARD, '\x06') - 1, OLED_HEIGHT - 8, "\x06", FONT_STANDARD); + oledDrawStringRight(OLED_WIDTH - fontCharWidth(FONT_STANDARD, '\x06') - 3, OLED_HEIGHT - 8, btnYes, FONT_STANDARD); + oledInvert(OLED_WIDTH - oledStringWidth(btnYes, FONT_STANDARD) - fontCharWidth(FONT_STANDARD, '\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1); +} + void layoutDialog(const BITMAP *icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6) { int left = 0; @@ -47,14 +61,10 @@ void layoutDialog(const BITMAP *icon, const char *btnNo, const char *btnYes, con } } if (btnNo) { - oledDrawString(1, OLED_HEIGHT - 8, "\x15", FONT_STANDARD); - oledDrawString(fontCharWidth(FONT_STANDARD, '\x15') + 3, OLED_HEIGHT - 8, btnNo, FONT_STANDARD); - oledInvert(0, OLED_HEIGHT - 9, fontCharWidth(FONT_STANDARD, '\x15') + oledStringWidth(btnNo, FONT_STANDARD) + 2, OLED_HEIGHT - 1); + layoutButtonNo(btnNo); } if (btnYes) { - oledDrawString(OLED_WIDTH - fontCharWidth(FONT_STANDARD, '\x06') - 1, OLED_HEIGHT - 8, "\x06", FONT_STANDARD); - oledDrawStringRight(OLED_WIDTH - fontCharWidth(FONT_STANDARD, '\x06') - 3, OLED_HEIGHT - 8, btnYes, FONT_STANDARD); - oledInvert(OLED_WIDTH - oledStringWidth(btnYes, FONT_STANDARD) - fontCharWidth(FONT_STANDARD, '\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1); + layoutButtonYes(btnYes); } oledRefresh(); } diff --git a/layout.h b/layout.h index 5ea34ec..eea0432 100644 --- a/layout.h +++ b/layout.h @@ -24,6 +24,8 @@ #include #include "bitmaps.h" +void layoutButtonNo(const char *btnNo); +void layoutButtonYes(const char *btnYes); void layoutDialog(const BITMAP *icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6); void layoutProgressUpdate(bool refresh); void layoutProgress(const char *desc, int permil);