Skip to content

Commit

Permalink
Desktop: dummy mode improvements. Fixes: correct scrolling text, corr…
Browse files Browse the repository at this point in the history
…ect AM/PM in Clock. (#2160)

* Show passport instead of app if SD/app is missing 
* Desktop: cleanup dummy mode code and add more apps
* Gui: fix incorrect trimming in scrollable text

Signed-off-by: Kowalski Dragon (kowalski7cc) <[email protected]>
Co-authored-by: あく <[email protected]>
  • Loading branch information
kowalski7cc and skotopes authored Dec 20, 2022
1 parent 797eab8 commit a9c2b4d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion applications/plugins/clock/clock_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static void clock_render_callback(Canvas* canvas, void* ctx) {
31,
AlignLeft,
AlignCenter,
(data->datetime.hour > 12) ? "AM" : "PM");
(data->datetime.hour > 12) ? "PM" : "AM");
}

canvas_set_font(canvas, FontSecondary);
Expand Down
33 changes: 27 additions & 6 deletions applications/services/desktop/scenes/desktop_scene_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

#define TAG "DesktopSrv"

#define MUSIC_PLAYER_APP EXT_PATH("/apps/Misc/music_player.fap")
#define SNAKE_GAME_APP EXT_PATH("/apps/Games/snake_game.fap")
#define CLOCK_APP EXT_PATH("/apps/Tools/clock.fap")

static void desktop_scene_main_new_idle_animation_callback(void* context) {
furi_assert(context);
Desktop* desktop = context;
Expand Down Expand Up @@ -60,6 +64,19 @@ static void desktop_switch_to_app(Desktop* desktop, const FlipperApplication* fl
}
#endif

static void desktop_scene_main_open_app_or_profile(Desktop* desktop, const char* path) {
do {
LoaderStatus status = loader_start(desktop->loader, FAP_LOADER_APP_NAME, path);
if(status == LoaderStatusOk) break;
FURI_LOG_E(TAG, "loader_start failed: %d", status);

status = loader_start(desktop->loader, "Passport", NULL);
if(status != LoaderStatusOk) {
FURI_LOG_E(TAG, "loader_start failed: %d", status);
}
} while(false);
}

void desktop_scene_main_callback(DesktopEvent event, void* context) {
Desktop* desktop = (Desktop*)context;
view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
Expand Down Expand Up @@ -181,12 +198,16 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
}
break;
}
case DesktopMainEventOpenGameMenu: {
LoaderStatus status = loader_start(
desktop->loader, FAP_LOADER_APP_NAME, EXT_PATH("/apps/Games/snake_game.fap"));
if(status != LoaderStatusOk) {
FURI_LOG_E(TAG, "loader_start failed: %d", status);
}
case DesktopMainEventOpenGame: {
desktop_scene_main_open_app_or_profile(desktop, SNAKE_GAME_APP);
break;
}
case DesktopMainEventOpenClock: {
desktop_scene_main_open_app_or_profile(desktop, CLOCK_APP);
break;
}
case DesktopMainEventOpenMusicPlayer: {
desktop_scene_main_open_app_or_profile(desktop, MUSIC_PLAYER_APP);
break;
}
case DesktopLockedEventUpdate:
Expand Down
4 changes: 3 additions & 1 deletion applications/services/desktop/views/desktop_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ typedef enum {
DesktopMainEventOpenPassport,
DesktopMainEventOpenPowerOff,

DesktopMainEventOpenGameMenu,
DesktopMainEventOpenGame,
DesktopMainEventOpenClock,
DesktopMainEventOpenMusicPlayer,

DesktopLockedEventUnlocked,
DesktopLockedEventUpdate,
Expand Down
6 changes: 3 additions & 3 deletions applications/services/desktop/views/desktop_view_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ bool desktop_main_input_callback(InputEvent* event, void* context) {
} else {
if(event->type == InputTypeShort) {
if(event->key == InputKeyOk) {
main_view->callback(DesktopMainEventOpenGameMenu, main_view->context);
main_view->callback(DesktopMainEventOpenGame, main_view->context);
} else if(event->key == InputKeyUp) {
main_view->callback(DesktopMainEventOpenLockMenu, main_view->context);
} else if(event->key == InputKeyDown) {
main_view->callback(DesktopMainEventOpenPassport, main_view->context);
main_view->callback(DesktopMainEventOpenMusicPlayer, main_view->context);
} else if(event->key == InputKeyLeft) {
main_view->callback(DesktopMainEventOpenPassport, main_view->context);
main_view->callback(DesktopMainEventOpenClock, main_view->context);
}
// Right key is handled by animation manager
}
Expand Down
7 changes: 4 additions & 3 deletions applications/services/gui/elements.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ void elements_scrollable_text_line(
}

// Calculate scroll size
size_t scroll_size = furi_string_size(string);
size_t scroll_size = furi_string_size(line);
size_t right_width = 0;
for(size_t i = scroll_size; i > 0; i--) {
right_width += canvas_glyph_width(canvas, furi_string_get_char(line, i));
Expand All @@ -579,10 +579,11 @@ void elements_scrollable_text_line(
furi_string_right(line, scroll);
}

do {
len_px = canvas_string_width(canvas, furi_string_get_cstr(line));
while(len_px > width) {
furi_string_left(line, furi_string_size(line) - 1);
len_px = canvas_string_width(canvas, furi_string_get_cstr(line));
} while(len_px > width);
}

if(ellipsis) {
furi_string_cat(line, "...");
Expand Down

0 comments on commit a9c2b4d

Please sign in to comment.