[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:
@@ -1,7 +1,6 @@
|
||||
#include "elements.h"
|
||||
#include <assets_icons.h>
|
||||
#include <gui/icon_i.h>
|
||||
#include <m-string.h>
|
||||
#include <furi.h>
|
||||
#include "canvas_i.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, y + height - 1);
|
||||
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
|
||||
|
||||
#include <stdint.h>
|
||||
#include <m-string.h>
|
||||
#include "canvas.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -105,6 +106,13 @@ void elements_slightly_rounded_frame(
|
||||
uint8_t width,
|
||||
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
|
||||
}
|
||||
#endif
|
||||
|
@@ -37,8 +37,10 @@ static bool file_select_init_inner(FileSelect* file_select);
|
||||
static void file_select_draw_callback(Canvas* canvas, void* _model) {
|
||||
FileSelectModel* model = _model;
|
||||
|
||||
string_t string_buff;
|
||||
const uint8_t item_height = 16;
|
||||
const uint8_t item_width = 123;
|
||||
const uint8_t max_width = 100;
|
||||
|
||||
canvas_clear(canvas);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
@@ -58,11 +60,12 @@ static void file_select_draw_callback(Canvas* canvas, void* _model) {
|
||||
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,
|
||||
6,
|
||||
(i * item_height) + item_height - 4,
|
||||
string_get_cstr(model->filename[i]));
|
||||
canvas, 6, (i * item_height) + item_height - 4, string_get_cstr(string_buff));
|
||||
|
||||
string_clear(string_buff);
|
||||
}
|
||||
} else {
|
||||
canvas_draw_str(canvas, 6, item_height, "Empty folder");
|
||||
|
Reference in New Issue
Block a user