Desktop: dummy mode improvements. Fixes: correct scrolling text, correct 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) <kowalski7cc@users.noreply.github.com>
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Kowalski Dragon 2022-12-20 14:57:58 +01:00 committed by GitHub
parent 797eab8924
commit a9c2b4d6a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 14 deletions

View File

@ -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);

View File

@ -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;
@ -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);
@ -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:

View File

@ -10,7 +10,9 @@ typedef enum {
DesktopMainEventOpenPassport,
DesktopMainEventOpenPowerOff,
DesktopMainEventOpenGameMenu,
DesktopMainEventOpenGame,
DesktopMainEventOpenClock,
DesktopMainEventOpenMusicPlayer,
DesktopLockedEventUnlocked,
DesktopLockedEventUpdate,

View File

@ -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
}

View File

@ -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));
@ -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, "...");