[FL-1235] Cut long names (#494)
* fix typo, elements_string_fit_width added * add string_fit_witdt to fileselect module Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
		
							parent
							
								
									502f449904
								
							
						
					
					
						commit
						1cfb16d9a7
					
				| @ -200,7 +200,7 @@ static uint32_t archive_previous_callback(void* context) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* file menu */ | /* file menu */ | ||||||
| static void archive_add_to_favorites(ArchiveApp* archive) { | static void archive_add_to_favourites(ArchiveApp* archive) { | ||||||
|     furi_assert(archive); |     furi_assert(archive); | ||||||
| 
 | 
 | ||||||
|     FS_Common_Api* common_api = &archive->fs_api->common; |     FS_Common_Api* common_api = &archive->fs_api->common; | ||||||
| @ -212,7 +212,7 @@ static void archive_add_to_favorites(ArchiveApp* archive) { | |||||||
|     string_cat(buffer_src, "/"); |     string_cat(buffer_src, "/"); | ||||||
|     string_cat(buffer_src, archive->browser.name); |     string_cat(buffer_src, archive->browser.name); | ||||||
| 
 | 
 | ||||||
|     string_init_set_str(buffer_dst, "/favorites/"); |     string_init_set_str(buffer_dst, "/favourites/"); | ||||||
|     string_cat(buffer_dst, archive->browser.name); |     string_cat(buffer_dst, archive->browser.name); | ||||||
| 
 | 
 | ||||||
|     common_api->rename(string_get_cstr(buffer_src), string_get_cstr(buffer_dst)); |     common_api->rename(string_get_cstr(buffer_src), string_get_cstr(buffer_dst)); | ||||||
| @ -345,7 +345,7 @@ static void archive_file_menu_callback(ArchiveApp* archive) { | |||||||
|     case 1: |     case 1: | ||||||
| 
 | 
 | ||||||
|         string_set(archive->browser.name, selected->name); |         string_set(archive->browser.name, selected->name); | ||||||
|         archive_add_to_favorites(archive); |         archive_add_to_favourites(archive); | ||||||
|         archive_close_file_menu(archive); |         archive_close_file_menu(archive); | ||||||
|         break; |         break; | ||||||
|     case 2: |     case 2: | ||||||
| @ -521,7 +521,7 @@ ArchiveApp* archive_alloc() { | |||||||
|     view_dispatcher_attach_to_gui( |     view_dispatcher_attach_to_gui( | ||||||
|         archive->view_dispatcher, archive->gui, ViewDispatcherTypeFullscreen); |         archive->view_dispatcher, archive->gui, ViewDispatcherTypeFullscreen); | ||||||
| 
 | 
 | ||||||
|     view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveTabFavorites); |     view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveTabFavourites); | ||||||
| 
 | 
 | ||||||
|     return archive; |     return archive; | ||||||
| } | } | ||||||
|  | |||||||
| @ -23,7 +23,7 @@ typedef enum { | |||||||
| } ArchiveViewEnum; | } ArchiveViewEnum; | ||||||
| 
 | 
 | ||||||
| typedef enum { | typedef enum { | ||||||
|     ArchiveTabFavorites, |     ArchiveTabFavourites, | ||||||
|     ArchiveTabIButton, |     ArchiveTabIButton, | ||||||
|     ArchiveTabNFC, |     ArchiveTabNFC, | ||||||
|     ArchiveTabSubOne, |     ArchiveTabSubOne, | ||||||
| @ -42,7 +42,7 @@ static const char* known_ext[] = { | |||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| static const char* tab_default_paths[] = { | static const char* tab_default_paths[] = { | ||||||
|     [ArchiveTabFavorites] = "favorites", |     [ArchiveTabFavourites] = "favourites", | ||||||
|     [ArchiveTabIButton] = "ibutton", |     [ArchiveTabIButton] = "ibutton", | ||||||
|     [ArchiveTabNFC] = "nfc", |     [ArchiveTabNFC] = "nfc", | ||||||
|     [ArchiveTabSubOne] = "subone", |     [ArchiveTabSubOne] = "subone", | ||||||
|  | |||||||
| @ -1,7 +1,7 @@ | |||||||
| #include "archive_views.h" | #include "archive_views.h" | ||||||
| 
 | 
 | ||||||
| static const char* ArchiveTabNames[] = | static const char* ArchiveTabNames[] = | ||||||
|     {"Favorites", "iButton", "NFC", "SubOne", "Rfid", "Infared", "Browser"}; |     {"Favourites", "iButton", "NFC", "SubOne", "Rfid", "Infared", "Browser"}; | ||||||
| 
 | 
 | ||||||
| static const IconName ArchiveItemIcons[] = { | static const IconName ArchiveItemIcons[] = { | ||||||
|     [ArchiveFileTypeIButton] = I_ibutt_10px, |     [ArchiveFileTypeIButton] = I_ibutt_10px, | ||||||
| @ -59,20 +59,6 @@ static void trim_file_ext(string_t name) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void format_filename_buffer(Canvas* canvas, string_t name, ArchiveFileTypeEnum type) { |  | ||||||
|     furi_assert(name); |  | ||||||
| 
 |  | ||||||
|     size_t s_len = strlen(string_get_cstr(name)); |  | ||||||
|     uint16_t len_px = canvas_string_width(canvas, string_get_cstr(name)); |  | ||||||
| 
 |  | ||||||
|     if(is_known_app(type)) trim_file_ext(name); |  | ||||||
| 
 |  | ||||||
|     if(len_px > MAX_LEN_PX) { |  | ||||||
|         string_mid(name, 0, s_len - (size_t)((len_px - MAX_LEN_PX) / ((len_px / s_len) + 2) + 2)); |  | ||||||
|         string_cat(name, "..."); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void archive_draw_frame(Canvas* canvas, uint16_t idx, bool scrollbar) { | static void archive_draw_frame(Canvas* canvas, uint16_t idx, bool scrollbar) { | ||||||
|     canvas_set_color(canvas, ColorBlack); |     canvas_set_color(canvas, ColorBlack); | ||||||
|     canvas_draw_box(canvas, 0, 15 + idx * FRAME_HEIGHT, scrollbar ? 122 : 127, FRAME_HEIGHT); |     canvas_draw_box(canvas, 0, 15 + idx * FRAME_HEIGHT, scrollbar ? 122 : 127, FRAME_HEIGHT); | ||||||
| @ -101,7 +87,9 @@ static void draw_list(Canvas* canvas, ArchiveViewModel* model) { | |||||||
|         ArchiveFile_t* file = files_array_get(model->files, CLAMP(idx, array_size - 1, 0)); |         ArchiveFile_t* file = files_array_get(model->files, CLAMP(idx, array_size - 1, 0)); | ||||||
| 
 | 
 | ||||||
|         string_set(str_buff, file->name); |         string_set(str_buff, file->name); | ||||||
|         format_filename_buffer(canvas, str_buff, file->type); | 
 | ||||||
|  |         if(is_known_app(file->type)) trim_file_ext(str_buff); | ||||||
|  |         elements_string_fit_width(canvas, str_buff, MAX_LEN_PX); | ||||||
| 
 | 
 | ||||||
|         if(model->idx == idx) { |         if(model->idx == idx) { | ||||||
|             archive_draw_frame(canvas, i, scrollbar); |             archive_draw_frame(canvas, i, scrollbar); | ||||||
|  | |||||||
| @ -1,7 +1,6 @@ | |||||||
| #include "elements.h" | #include "elements.h" | ||||||
| #include <assets_icons.h> | #include <assets_icons.h> | ||||||
| #include <gui/icon_i.h> | #include <gui/icon_i.h> | ||||||
| #include <m-string.h> |  | ||||||
| #include <furi.h> | #include <furi.h> | ||||||
| #include "canvas_i.h" | #include "canvas_i.h" | ||||||
| #include <string.h> | #include <string.h> | ||||||
| @ -257,4 +256,19 @@ void elements_slightly_rounded_frame( | |||||||
|     canvas_draw_dot(canvas, x + width - 1, y); |     canvas_draw_dot(canvas, x + width - 1, y); | ||||||
|     canvas_draw_dot(canvas, x, y + height - 1); |     canvas_draw_dot(canvas, x, y + height - 1); | ||||||
|     canvas_invert_color(canvas); |     canvas_invert_color(canvas); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | void elements_string_fit_width(Canvas* canvas, string_t string, uint8_t width) { | ||||||
|  |     furi_assert(canvas); | ||||||
|  |     furi_assert(string); | ||||||
|  | 
 | ||||||
|  |     uint16_t len_px = canvas_string_width(canvas, string_get_cstr(string)); | ||||||
|  | 
 | ||||||
|  |     if(len_px > width) { | ||||||
|  |         size_t s_len = strlen(string_get_cstr(string)); | ||||||
|  |         uint8_t end_pos = s_len - ((len_px - width) / ((len_px / s_len) + 2) + 2); | ||||||
|  | 
 | ||||||
|  |         string_mid(string, 0, end_pos); | ||||||
|  |         string_cat(string, "..."); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | |||||||
| @ -1,6 +1,7 @@ | |||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
|  | #include <m-string.h> | ||||||
| #include "canvas.h" | #include "canvas.h" | ||||||
| 
 | 
 | ||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
| @ -105,6 +106,13 @@ void elements_slightly_rounded_frame( | |||||||
|     uint8_t width, |     uint8_t width, | ||||||
|     uint8_t height); |     uint8_t height); | ||||||
| 
 | 
 | ||||||
|  | /*
 | ||||||
|  |  * Trim string buffer to fit width in pixels | ||||||
|  |  * @param string - string to trim | ||||||
|  |  * @param width - max width | ||||||
|  |  */ | ||||||
|  | void elements_string_fit_width(Canvas* canvas, string_t string, uint8_t width); | ||||||
|  | 
 | ||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  | |||||||
| @ -37,8 +37,10 @@ static bool file_select_init_inner(FileSelect* file_select); | |||||||
| static void file_select_draw_callback(Canvas* canvas, void* _model) { | static void file_select_draw_callback(Canvas* canvas, void* _model) { | ||||||
|     FileSelectModel* model = _model; |     FileSelectModel* model = _model; | ||||||
| 
 | 
 | ||||||
|  |     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; | ||||||
| 
 | 
 | ||||||
|     canvas_clear(canvas); |     canvas_clear(canvas); | ||||||
|     canvas_set_font(canvas, FontSecondary); |     canvas_set_font(canvas, FontSecondary); | ||||||
| @ -58,11 +60,12 @@ static void file_select_draw_callback(Canvas* canvas, void* _model) { | |||||||
|                 canvas_set_color(canvas, ColorBlack); |                 canvas_set_color(canvas, ColorBlack); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  |             string_init_set(string_buff, model->filename[i]); | ||||||
|  |             elements_string_fit_width(canvas, string_buff, max_width); | ||||||
|             canvas_draw_str( |             canvas_draw_str( | ||||||
|                 canvas, |                 canvas, 6, (i * item_height) + item_height - 4, string_get_cstr(string_buff)); | ||||||
|                 6, | 
 | ||||||
|                 (i * item_height) + item_height - 4, |             string_clear(string_buff); | ||||||
|                 string_get_cstr(model->filename[i])); |  | ||||||
|         } |         } | ||||||
|     } else { |     } else { | ||||||
|         canvas_draw_str(canvas, 6, item_height, "Empty folder"); |         canvas_draw_str(canvas, 6, item_height, "Empty folder"); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 its your bedtime
						its your bedtime