Skip to content

Commit

Permalink
Picopass: add subheader to loclass UI (#197)
Browse files Browse the repository at this point in the history
Co-authored-by: あく <alleteam@gmail.com>
  • Loading branch information
bettse and skotopes authored Apr 8, 2024
1 parent 21ca5d4 commit 3d31963
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions scenes/picopass_scene_loclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void picopass_scene_loclass_on_enter(void* context) {

loclass_set_callback(picopass->loclass, picopass_loclass_result_callback, picopass);
loclass_set_header(picopass->loclass, "Loclass");
loclass_set_subheader(picopass->loclass, "Hold To Reader");

picopass_blink_emulate_start(picopass);
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewLoclass);
Expand Down
26 changes: 25 additions & 1 deletion views/loclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ struct Loclass {
typedef struct {
FuriString* header;
uint8_t num_macs;
FuriString* subheader;
} LoclassViewModel;

static void loclass_draw_callback(Canvas* canvas, void* model) {
LoclassViewModel* m = model;

char draw_str[32] = {};
canvas_set_font(canvas, FontSecondary);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 64, 0, AlignCenter, AlignTop, furi_string_get_cstr(m->header));
canvas_set_font(canvas, FontSecondary);

if(m->num_macs == 255) {
return;
Expand All @@ -37,6 +39,9 @@ static void loclass_draw_callback(Canvas* canvas, void* model) {

elements_progress_bar_with_text(canvas, 0, 20, 128, progress, draw_str);

canvas_draw_str_aligned(
canvas, 64, 45, AlignCenter, AlignBottom, furi_string_get_cstr(m->subheader));

elements_button_center(canvas, "Skip");
}

Expand All @@ -61,13 +66,20 @@ Loclass* loclass_alloc() {
view_set_context(loclass->view, loclass);
with_view_model(
loclass->view, LoclassViewModel * model, { model->header = furi_string_alloc(); }, false);
with_view_model(
loclass->view,
LoclassViewModel * model,
{ model->subheader = furi_string_alloc(); },
false);
return loclass;
}

void loclass_free(Loclass* loclass) {
furi_assert(loclass);
with_view_model(
loclass->view, LoclassViewModel * model, { furi_string_free(model->header); }, false);
with_view_model(
loclass->view, LoclassViewModel * model, { furi_string_free(model->subheader); }, false);
view_free(loclass->view);
free(loclass);
}
Expand All @@ -80,6 +92,7 @@ void loclass_reset(Loclass* loclass) {
{
model->num_macs = 0;
furi_string_reset(model->header);
furi_string_reset(model->subheader);
},
false);
}
Expand All @@ -104,6 +117,17 @@ void loclass_set_header(Loclass* loclass, const char* header) {
loclass->view, LoclassViewModel * model, { furi_string_set(model->header, header); }, true);
}

void loclass_set_subheader(Loclass* loclass, const char* subheader) {
furi_assert(loclass);
furi_assert(subheader);

with_view_model(
loclass->view,
LoclassViewModel * model,
{ furi_string_set(model->subheader, subheader); },
true);
}

void loclass_set_num_macs(Loclass* loclass, uint16_t num_macs) {
furi_assert(loclass);
with_view_model(
Expand Down
2 changes: 2 additions & 0 deletions views/loclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ void loclass_set_callback(Loclass* loclass, LoclassCallback callback, void* cont

void loclass_set_header(Loclass* loclass, const char* header);

void loclass_set_subheader(Loclass* loclass, const char* subheader);

void loclass_set_num_macs(Loclass* loclass, uint16_t num_macs);

0 comments on commit 3d31963

Please sign in to comment.