From c3bfebb6e60efb7c0f3ddfeaac89bebf4ab91514 Mon Sep 17 00:00:00 2001 From: Alexander Bays Date: Sat, 1 Mar 2025 22:50:56 -0600 Subject: [PATCH] GUI: Add marquee 'Text Scroll' option (#363) * GUI: Add marquee 'Text Scroll' option - Adds the tiny `Text Scroll` option under `MNTM > Interface > General` to either use the standard scroll, or a new marquee style back and forth on any scrollable text. - `elements_scrollable_text_line_centered` renamed to `elements_scrollable_text_line_ex` to be more general. Has `bool marquee`. * Unnecessary switch here * Apply setting internally * Revert a few usages * Update changelog * Last thing --------- Co-authored-by: Willy-JL <49810075+Willy-JL@users.noreply.github.com> --- CHANGELOG.md | 1 + .../momentum_app_scene_interface_general.c | 19 ++++++++++++ applications/services/gui/elements.c | 31 ++++++++++++++++--- applications/services/gui/modules/menu.c | 2 +- lib/momentum/settings.c | 2 ++ lib/momentum/settings.h | 1 + 6 files changed, 51 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ecf6c543..419f73a5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - OFW: NFC: Disney Infinity KDF plugin (by @bettse) - Archive: Add item count to directory info scene (#378 by @956MB) - Clock: 12 hour "midnight format" in Momentum Settings (#341 by @956MB) +- GUI: Add marquee 'Text Scroll' option in Momentum Settings (#363 by @956MB) - UL: Input: Vibro on Button press option (by @Dmitry422) - Desktop: - UL: Option to prevent Auto Lock when connected to USB/RPC (by @Dmitry422) diff --git a/applications/main/momentum_app/scenes/momentum_app_scene_interface_general.c b/applications/main/momentum_app/scenes/momentum_app_scene_interface_general.c index 11a29b4cc..9ca573950 100644 --- a/applications/main/momentum_app/scenes/momentum_app_scene_interface_general.c +++ b/applications/main/momentum_app/scenes/momentum_app_scene_interface_general.c @@ -1,6 +1,7 @@ #include "../momentum_app.h" enum VarItemListIndex { + VarItemListIndexScrollType, VarItemListIndexMidnightFormat, }; @@ -9,6 +10,14 @@ void momentum_app_scene_interface_general_var_item_list_callback(void* context, view_dispatcher_send_custom_event(app->view_dispatcher, index); } +static void momentum_app_scene_interface_general_scroll_marquee_changed(VariableItem* item) { + MomentumApp* app = variable_item_get_context(item); + bool value = variable_item_get_current_value_index(item); + variable_item_set_current_value_text(item, value ? "Marquee" : "Standard"); + momentum_settings.scroll_marquee = value; + app->save_settings = true; +} + static void momentum_app_scene_interface_general_midnight_format_changed(VariableItem* item) { MomentumApp* app = variable_item_get_context(item); bool value = variable_item_get_current_value_index(item); @@ -22,6 +31,16 @@ void momentum_app_scene_interface_general_on_enter(void* context) { VariableItemList* var_item_list = app->var_item_list; VariableItem* item; + item = variable_item_list_add( + var_item_list, + "Text Scroll", + 2, + momentum_app_scene_interface_general_scroll_marquee_changed, + app); + variable_item_set_current_value_index(item, momentum_settings.scroll_marquee); + variable_item_set_current_value_text( + item, momentum_settings.scroll_marquee ? "Marquee" : "Standard"); + item = variable_item_list_add( var_item_list, "Clock Midnight Format", diff --git a/applications/services/gui/elements.c b/applications/services/gui/elements.c index 88c0c4f37..20396aae9 100644 --- a/applications/services/gui/elements.c +++ b/applications/services/gui/elements.c @@ -15,6 +15,8 @@ #include #include +#include + typedef struct { int32_t x; int32_t y; @@ -698,8 +700,9 @@ void elements_scrollable_text_line_centered( FuriString* line = furi_string_alloc_set(string); size_t len_px = canvas_string_width(canvas, furi_string_get_cstr(line)); + bool marquee = momentum_settings.scroll_marquee; if(len_px > width) { - if(centered) { + if(centered && !marquee) { centered = false; x -= width / 2; } @@ -717,11 +720,31 @@ void elements_scrollable_text_line_centered( scroll_size--; if(!scroll_size) break; } + // Ensure that we have something to scroll if(scroll_size) { - scroll_size += 3; - scroll = scroll % scroll_size; - furi_string_right(line, scroll); + if(marquee) { + const size_t delay = 3; // positions before/after scroll to delay + size_t total_scroll = (scroll_size * 2) + (delay * 2); + size_t use_scroll = scroll % total_scroll; + + if(use_scroll < scroll_size) { + furi_string_right(line, use_scroll); + } else if(use_scroll < (scroll_size + delay)) { + // Delay right + furi_string_right(line, scroll_size); + } else if(use_scroll < (scroll_size * 2 + delay)) { + size_t reverse_pos = scroll_size - (use_scroll - (scroll_size + delay)); + furi_string_right(line, reverse_pos); + } else { + // Delay left + furi_string_right(line, 0); + } + } else { + scroll_size += 3; + scroll = scroll % scroll_size; + furi_string_right(line, scroll); + } } len_px = canvas_string_width(canvas, furi_string_get_cstr(line)); diff --git a/applications/services/gui/modules/menu.c b/applications/services/gui/modules/menu.c index 9e66b9d27..3329eecb6 100644 --- a/applications/services/gui/modules/menu.c +++ b/applications/services/gui/modules/menu.c @@ -210,7 +210,7 @@ static void menu_draw_callback(Canvas* canvas, void* _model) { canvas, pos_x, pos_y - height / 2 - 8, - 126, + 124, name, scroll_counter, false, diff --git a/lib/momentum/settings.c b/lib/momentum/settings.c index 72f0f6f95..dcb798f3b 100644 --- a/lib/momentum/settings.c +++ b/lib/momentum/settings.c @@ -32,6 +32,7 @@ MomentumSettings momentum_settings = { .show_internal_tab = false, // OFF .browser_path_mode = BrowserPathOff, // OFF .favorite_timeout = 0, // OFF + .scroll_marquee = false, // OFF .dark_mode = false, // OFF .rgb_backlight = false, // OFF .butthurt_timer = 21600, // 6 H @@ -103,6 +104,7 @@ static const struct { {setting_bool(show_internal_tab)}, {setting_enum(browser_path_mode, BrowserPathModeCount)}, {setting_uint(favorite_timeout, 0, 60)}, + {setting_bool(scroll_marquee)}, {setting_bool(dark_mode)}, {setting_bool(rgb_backlight)}, {setting_uint(butthurt_timer, 0, 172800)}, diff --git a/lib/momentum/settings.h b/lib/momentum/settings.h index e379dd246..6ba0f935c 100644 --- a/lib/momentum/settings.h +++ b/lib/momentum/settings.h @@ -89,6 +89,7 @@ typedef struct { bool show_internal_tab; BrowserPathMode browser_path_mode; uint32_t favorite_timeout; + bool scroll_marquee; bool dark_mode; bool rgb_backlight; uint32_t butthurt_timer;