21
21
#define PROGRESS_BAR_MARGIN (3)
22
22
#define PROGRESS_BAR_HEIGHT (4)
23
23
24
+ typedef struct {
25
+ uint8_t progress_bar_x ;
26
+ uint8_t progress_bar_width ;
27
+ uint8_t code_total_length ;
28
+ uint8_t code_offset_x ;
29
+ uint8_t code_offset_x_inc ;
30
+ uint8_t code_offset_y ;
31
+ } UiPrecalculatedDimensions ;
32
+
24
33
typedef struct {
25
34
uint16_t current_token_index ;
26
35
char last_code [TOTP_TOKEN_DIGITS_MAX_COUNT + 1 ];
@@ -30,8 +39,7 @@ typedef struct {
30
39
NotificationMessage const * * notification_sequence_automation ;
31
40
FuriMutex * last_code_update_sync ;
32
41
TotpGenerateCodeWorkerContext * generate_code_worker_context ;
33
- uint8_t progress_bar_x ;
34
- uint8_t progress_bar_width ;
42
+ UiPrecalculatedDimensions ui_precalculated_dimensions ;
35
43
} SceneState ;
36
44
37
45
static const NotificationSequence *
@@ -133,29 +141,40 @@ static void update_totp_params(PluginState* const plugin_state) {
133
141
134
142
static void draw_totp_code (Canvas * const canvas , const SceneState * const scene_state ) {
135
143
uint8_t code_length = scene_state -> current_token -> digits ;
144
+ uint8_t offset_x = scene_state -> ui_precalculated_dimensions .code_offset_x ;
136
145
uint8_t char_width = modeNine_15ptFontInfo .charInfo [0 ].width ;
137
- uint8_t total_length = code_length * (char_width + modeNine_15ptFontInfo .spacePixels );
138
- uint8_t offset_x = (SCREEN_WIDTH - total_length ) >> 1 ;
139
- uint8_t offset_x_inc = char_width + modeNine_15ptFontInfo .spacePixels ;
140
- uint8_t offset_y = SCREEN_HEIGHT_CENTER - (modeNine_15ptFontInfo .height >> 1 );
146
+ uint8_t offset_x_inc = scene_state -> ui_precalculated_dimensions .code_offset_x_inc ;
141
147
for (uint8_t i = 0 ; i < code_length ; i ++ ) {
142
148
char ch = scene_state -> last_code [i ];
143
- uint8_t char_index = ch - modeNine_15ptFontInfo .startChar ;
144
- canvas_draw_xbm (
145
- canvas ,
146
- offset_x ,
147
- offset_y ,
148
- char_width ,
149
- modeNine_15ptFontInfo .height ,
150
- & modeNine_15ptFontInfo .data [modeNine_15ptFontInfo .charInfo [char_index ].offset ]);
149
+ if (ch >= modeNine_15ptFontInfo .startChar && ch <= modeNine_15ptFontInfo .endChar ) {
150
+ uint8_t char_index = ch - modeNine_15ptFontInfo .startChar ;
151
+ canvas_draw_xbm (
152
+ canvas ,
153
+ offset_x ,
154
+ scene_state -> ui_precalculated_dimensions .code_offset_y ,
155
+ char_width ,
156
+ modeNine_15ptFontInfo .height ,
157
+ & modeNine_15ptFontInfo .data [modeNine_15ptFontInfo .charInfo [char_index ].offset ]);
158
+ }
151
159
152
160
offset_x += offset_x_inc ;
153
161
}
154
162
}
155
163
156
164
static void on_new_token_code_generated (bool time_left , void * context ) {
165
+ const PluginState * plugin_state = context ;
166
+ SceneState * scene_state = plugin_state -> current_scene_state ;
167
+ uint8_t char_width = modeNine_15ptFontInfo .charInfo [0 ].width ;
168
+ scene_state -> ui_precalculated_dimensions .code_total_length =
169
+ scene_state -> current_token -> digits * (char_width + modeNine_15ptFontInfo .spacePixels );
170
+ scene_state -> ui_precalculated_dimensions .code_offset_x =
171
+ (SCREEN_WIDTH - scene_state -> ui_precalculated_dimensions .code_total_length ) >> 1 ;
172
+ scene_state -> ui_precalculated_dimensions .code_offset_x_inc =
173
+ char_width + modeNine_15ptFontInfo .spacePixels ;
174
+ scene_state -> ui_precalculated_dimensions .code_offset_y =
175
+ SCREEN_HEIGHT_CENTER - (modeNine_15ptFontInfo .height >> 1 );
176
+
157
177
if (time_left ) {
158
- PluginState * plugin_state = context ;
159
178
notification_message (
160
179
plugin_state -> notification_app ,
161
180
get_notification_sequence_new_token (plugin_state , plugin_state -> current_scene_state ));
@@ -164,10 +183,12 @@ static void on_new_token_code_generated(bool time_left, void* context) {
164
183
165
184
static void on_code_lifetime_updated_generated (float code_lifetime_percent , void * context ) {
166
185
SceneState * scene_state = context ;
167
- scene_state -> progress_bar_width =
186
+ scene_state -> ui_precalculated_dimensions . progress_bar_width =
168
187
(uint8_t )((float )(SCREEN_WIDTH - (PROGRESS_BAR_MARGIN << 1 )) * code_lifetime_percent );
169
- scene_state -> progress_bar_x =
170
- ((SCREEN_WIDTH - (PROGRESS_BAR_MARGIN << 1 ) - scene_state -> progress_bar_width ) >> 1 ) +
188
+ scene_state -> ui_precalculated_dimensions .progress_bar_x =
189
+ ((SCREEN_WIDTH - (PROGRESS_BAR_MARGIN << 1 ) -
190
+ scene_state -> ui_precalculated_dimensions .progress_bar_width ) >>
191
+ 1 ) +
171
192
PROGRESS_BAR_MARGIN ;
172
193
}
173
194
@@ -301,9 +322,9 @@ void totp_scene_generate_token_render(Canvas* const canvas, PluginState* plugin_
301
322
302
323
canvas_draw_box (
303
324
canvas ,
304
- scene_state -> progress_bar_x ,
325
+ scene_state -> ui_precalculated_dimensions . progress_bar_x ,
305
326
SCREEN_HEIGHT - PROGRESS_BAR_MARGIN - PROGRESS_BAR_HEIGHT ,
306
- scene_state -> progress_bar_width ,
327
+ scene_state -> ui_precalculated_dimensions . progress_bar_width ,
307
328
PROGRESS_BAR_HEIGHT );
308
329
309
330
if (plugin_state -> tokens_count > 1 ) {
0 commit comments