فهرست منبع

[FL-1404] iButton long names fix (#528)

* ibutton: long names partial fix\
* ibutton: limit max filename length to 22 chars
* elwrapping long names to a new line
* Proper m-string size usage

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
its your bedtime 4 سال پیش
والد
کامیت
6ec9c6cc49

+ 1 - 1
applications/archive/archive_views.c

@@ -48,7 +48,7 @@ static void render_item_menu(Canvas* canvas, ArchiveViewModel* model) {
 }
 }
 
 
 void archive_trim_file_ext(string_t name) {
 void archive_trim_file_ext(string_t name) {
-    size_t str_len = strlen(string_get_cstr(name));
+    size_t str_len = string_size(name);
     char* buff_ptr = stringi_get_cstr(name);
     char* buff_ptr = stringi_get_cstr(name);
     char* end = buff_ptr + str_len;
     char* end = buff_ptr + str_len;
     while(end > buff_ptr && *end != '.' && *end != '\\' && *end != '/') {
     while(end > buff_ptr && *end != '.' && *end != '\\' && *end != '/') {

+ 25 - 1
applications/gui/elements.c

@@ -184,11 +184,35 @@ void elements_multiline_text_aligned(
 
 
     do {
     do {
         end = strchr(start, '\n');
         end = strchr(start, '\n');
+
         if(end) {
         if(end) {
             string_set_strn(str, start, end - start);
             string_set_strn(str, start, end - start);
         } else {
         } else {
             string_set_str(str, start);
             string_set_str(str, start);
         }
         }
+
+        uint16_t len_px = canvas_string_width(canvas, string_get_cstr(str));
+        uint8_t px_left =
+            canvas_width(canvas) - (x - (horizontal == AlignCenter ? len_px / 2 : 0));
+
+        // hacky
+        if(len_px > px_left) {
+            string_t buff;
+            string_init_set(buff, str);
+            size_t s_len = string_size(str);
+            uint8_t end_pos = s_len - ((len_px - px_left) / (len_px / s_len) + 2);
+
+            string_left(buff, end_pos);
+            string_cat(buff, "-");
+            string_right(str, end_pos);
+
+            canvas_draw_str_aligned(canvas, x, y, horizontal, vertical, string_get_cstr(buff));
+            string_clear(buff);
+
+            start = end + 1;
+            y += font_height;
+        }
+
         canvas_draw_str_aligned(canvas, x, y, horizontal, vertical, string_get_cstr(str));
         canvas_draw_str_aligned(canvas, x, y, horizontal, vertical, string_get_cstr(str));
         start = end + 1;
         start = end + 1;
         y += font_height;
         y += font_height;
@@ -271,7 +295,7 @@ void elements_string_fit_width(Canvas* canvas, string_t string, uint8_t width) {
     uint16_t len_px = canvas_string_width(canvas, string_get_cstr(string));
     uint16_t len_px = canvas_string_width(canvas, string_get_cstr(string));
 
 
     if(len_px > width) {
     if(len_px > width) {
-        size_t s_len = strlen(string_get_cstr(string));
+        size_t s_len = string_size(string);
         uint8_t end_pos = s_len - ((len_px - width) / ((len_px / s_len) + 2) + 2);
         uint8_t end_pos = s_len - ((len_px - width) / ((len_px / s_len) + 2) + 2);
 
 
         string_mid(string, 0, end_pos);
         string_mid(string, 0, end_pos);

+ 2 - 2
applications/gui/modules/file_select.c

@@ -40,7 +40,7 @@ static void file_select_draw_callback(Canvas* canvas, void* _model) {
     string_t string_buff;
     string_t string_buff;
     const uint8_t item_height = 16;
     const uint8_t item_height = 16;
     const uint8_t item_width = 123;
     const uint8_t item_width = 123;
-    const uint8_t max_width = 100;
+    const uint8_t text_max_width = 115;
 
 
     canvas_clear(canvas);
     canvas_clear(canvas);
     canvas_set_font(canvas, FontSecondary);
     canvas_set_font(canvas, FontSecondary);
@@ -61,7 +61,7 @@ static void file_select_draw_callback(Canvas* canvas, void* _model) {
             }
             }
 
 
             string_init_set(string_buff, model->filename[i]);
             string_init_set(string_buff, model->filename[i]);
-            elements_string_fit_width(canvas, string_buff, max_width);
+            elements_string_fit_width(canvas, string_buff, text_max_width);
             canvas_draw_str(
             canvas_draw_str(
                 canvas, 6, (i * item_height) + item_height - 4, string_get_cstr(string_buff));
                 canvas, 6, (i * item_height) + item_height - 4, string_get_cstr(string_buff));
 
 

+ 1 - 1
applications/ibutton/helpers/key-info.h

@@ -2,7 +2,7 @@
 #include <stdint.h>
 #include <stdint.h>
 
 
 static const uint8_t IBUTTON_KEY_DATA_SIZE = 8;
 static const uint8_t IBUTTON_KEY_DATA_SIZE = 8;
-static const uint8_t IBUTTON_KEY_NAME_SIZE = 64;
+static const uint8_t IBUTTON_KEY_NAME_SIZE = 22;
 
 
 enum class iButtonKeyType : uint8_t {
 enum class iButtonKeyType : uint8_t {
     KeyDallas,
     KeyDallas,

+ 1 - 1
applications/ibutton/scene/ibutton-scene-delete-confirm.cpp

@@ -41,7 +41,7 @@ void iButtonSceneDeleteConfirm::on_enter(iButtonApp* app) {
         break;
         break;
     }
     }
 
 
-    dialog_ex_set_text(dialog_ex, app->get_text_store(), 64, 26, AlignCenter, AlignCenter);
+    dialog_ex_set_text(dialog_ex, app->get_text_store(), 64, 20, AlignCenter, AlignCenter);
     dialog_ex_set_left_button_text(dialog_ex, "Back");
     dialog_ex_set_left_button_text(dialog_ex, "Back");
     dialog_ex_set_right_button_text(dialog_ex, "Delete");
     dialog_ex_set_right_button_text(dialog_ex, "Delete");
     dialog_ex_set_result_callback(dialog_ex, callback);
     dialog_ex_set_result_callback(dialog_ex, callback);

+ 5 - 5
applications/ibutton/scene/ibutton-scene-emulate.cpp

@@ -51,17 +51,17 @@ void iButtonSceneEmulate::on_enter(iButtonApp* app) {
 
 
     switch(line_count) {
     switch(line_count) {
     case 3:
     case 3:
-        popup_set_header(popup, "iButton", 92, 18, AlignCenter, AlignBottom);
-        popup_set_text(popup, app->get_text_store(), 92, 22, AlignCenter, AlignTop);
+        popup_set_header(popup, "iButton", 82, 18, AlignCenter, AlignBottom);
+        popup_set_text(popup, app->get_text_store(), 82, 22, AlignCenter, AlignTop);
         break;
         break;
 
 
     default:
     default:
-        popup_set_header(popup, "iButton", 92, 24, AlignCenter, AlignBottom);
-        popup_set_text(popup, app->get_text_store(), 92, 28, AlignCenter, AlignTop);
+        popup_set_header(popup, "iButton", 82, 24, AlignCenter, AlignBottom);
+        popup_set_text(popup, app->get_text_store(), 82, 28, AlignCenter, AlignTop);
         break;
         break;
     }
     }
 
 
-    popup_set_icon(popup, 10, 10, I_iButtonKey_49x44);
+    popup_set_icon(popup, 2, 10, I_iButtonKey_49x44);
 
 
     view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
     view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
     app->get_key_worker()->start_emulate(app->get_key());
     app->get_key_worker()->start_emulate(app->get_key());

+ 1 - 1
applications/ibutton/scene/ibutton-scene-save-name.cpp

@@ -22,7 +22,7 @@ void iButtonSceneSaveName::on_enter(iButtonApp* app) {
 
 
     text_input_set_header_text(text_input, "Name the key");
     text_input_set_header_text(text_input, "Name the key");
     text_input_set_result_callback(
     text_input_set_result_callback(
-        text_input, callback, app, app->get_text_store(), app->get_text_store_size());
+        text_input, callback, app, app->get_text_store(), IBUTTON_KEY_NAME_SIZE);
 
 
     view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewTextInput);
     view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewTextInput);
 }
 }

+ 1 - 1
applications/ibutton/scene/ibutton-scene-write-success.cpp

@@ -11,7 +11,7 @@ void iButtonSceneWriteSuccess::on_enter(iButtonApp* app) {
     auto callback = cbc::obtain_connector(this, &iButtonSceneWriteSuccess::popup_callback);
     auto callback = cbc::obtain_connector(this, &iButtonSceneWriteSuccess::popup_callback);
 
 
     popup_set_icon(popup, 0, 12, I_iButtonDolphinVerySuccess_108x52);
     popup_set_icon(popup, 0, 12, I_iButtonDolphinVerySuccess_108x52);
-    popup_set_text(popup, "Successful writing!", 47, 14, AlignLeft, AlignBottom);
+    popup_set_text(popup, "Successfully written!", 44, 14, AlignLeft, AlignBottom);
 
 
     popup_set_callback(popup, callback);
     popup_set_callback(popup, callback);
     popup_set_context(popup, app);
     popup_set_context(popup, app);

+ 5 - 5
applications/ibutton/scene/ibutton-scene-write.cpp

@@ -46,17 +46,17 @@ void iButtonSceneWrite::on_enter(iButtonApp* app) {
 
 
     switch(line_count) {
     switch(line_count) {
     case 3:
     case 3:
-        popup_set_header(popup, "iButton", 92, 18, AlignCenter, AlignBottom);
-        popup_set_text(popup, app->get_text_store(), 92, 22, AlignCenter, AlignTop);
+        popup_set_header(popup, "iButton", 82, 18, AlignCenter, AlignBottom);
+        popup_set_text(popup, app->get_text_store(), 82, 22, AlignCenter, AlignTop);
         break;
         break;
 
 
     default:
     default:
-        popup_set_header(popup, "iButton", 92, 24, AlignCenter, AlignBottom);
-        popup_set_text(popup, app->get_text_store(), 92, 28, AlignCenter, AlignTop);
+        popup_set_header(popup, "iButton", 82, 24, AlignCenter, AlignBottom);
+        popup_set_text(popup, app->get_text_store(), 82, 28, AlignCenter, AlignTop);
         break;
         break;
     }
     }
 
 
-    popup_set_icon(popup, 10, 10, I_iButtonKey_49x44);
+    popup_set_icon(popup, 2, 10, I_iButtonKey_49x44);
 
 
     view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
     view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
 
 

+ 2 - 2
lib/args/args.c

@@ -3,14 +3,14 @@
 size_t args_get_first_word_length(string_t args) {
 size_t args_get_first_word_length(string_t args) {
     size_t ws = string_search_char(args, ' ');
     size_t ws = string_search_char(args, ' ');
     if(ws == STRING_FAILURE) {
     if(ws == STRING_FAILURE) {
-        ws = strlen(string_get_cstr(args));
+        ws = string_size(args);
     }
     }
 
 
     return ws;
     return ws;
 }
 }
 
 
 size_t args_length(string_t args) {
 size_t args_length(string_t args) {
-    return strlen(string_get_cstr(args));
+    return string_size(args);
 }
 }
 
 
 bool args_read_string_and_trim(string_t args, string_t word) {
 bool args_read_string_and_trim(string_t args, string_t word) {