[FL-1472] Infrared: long names fix (#679)

* Infrared app: fix long button names
* Ble: fix missing icon on start without config.
* Gui: slow but nice string fitting.
* Gui: fit header string in button menu

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
its your bedtime 2021-09-02 12:02:34 +03:00 committed by GitHub
parent 420c03bb58
commit ae08c88bd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 15 deletions

View File

@ -48,11 +48,11 @@ int32_t bt_srv() {
furi_record_create("bt", bt);
furi_hal_bt_init();
if(bt->bt_settings.enabled) {
if(!furi_hal_bt_wait_startup()) {
FURI_LOG_E(BT_SERVICE_TAG, "Core2 startup failed");
} else {
view_port_enabled_set(bt->statusbar_view_port, true);
if(!furi_hal_bt_wait_startup()) {
FURI_LOG_E(BT_SERVICE_TAG, "Core2 startup failed");
} else {
view_port_enabled_set(bt->statusbar_view_port, true);
if(bt->bt_settings.enabled) {
bool bt_app_started = furi_hal_bt_start_app();
if(!bt_app_started) {
FURI_LOG_E(BT_SERVICE_TAG, "BT App start failed");

View File

@ -332,12 +332,12 @@ void elements_string_fit_width(Canvas* canvas, string_t string, uint8_t width) {
furi_assert(string);
uint16_t len_px = canvas_string_width(canvas, string_get_cstr(string));
if(len_px > width) {
size_t s_len = string_size(string);
uint8_t end_pos = s_len - ((len_px - width) / ((len_px / s_len) + 2) + 2);
string_mid(string, 0, end_pos);
width -= canvas_string_width(canvas, "...");
do {
string_left(string, string_size(string) - 1);
len_px = canvas_string_width(canvas, string_get_cstr(string));
} while(len_px > width);
string_cat(string, "...");
}
}

View File

@ -78,13 +78,20 @@ static void button_menu_draw_common_button(
} else {
canvas_draw_rframe(canvas, item_x, item_y, ITEM_WIDTH, ITEM_HEIGHT, 5);
}
string_t disp_str;
string_init_set_str(disp_str, text);
elements_string_fit_width(canvas, disp_str, ITEM_WIDTH - 6);
canvas_draw_str_aligned(
canvas,
item_x + (ITEM_WIDTH / 2),
item_y + (ITEM_HEIGHT / 2),
AlignCenter,
AlignCenter,
text);
string_get_cstr(disp_str));
string_clear(disp_str);
}
static void button_menu_view_draw_callback(Canvas* canvas, void* _model) {
@ -110,7 +117,11 @@ static void button_menu_view_draw_callback(Canvas* canvas, void* _model) {
canvas_draw_icon(canvas, 28, 123, &I_IrdaArrowDown_4x8);
}
canvas_draw_str_aligned(canvas, 32, 10, AlignCenter, AlignCenter, model->header);
string_t disp_str;
string_init_set_str(disp_str, model->header);
elements_string_fit_width(canvas, disp_str, ITEM_WIDTH - 6);
canvas_draw_str_aligned(canvas, 32, 10, AlignCenter, AlignCenter, string_get_cstr(disp_str));
string_clear(disp_str);
for(ButtonMenuItemArray_it(it, model->items); !ButtonMenuItemArray_end_p(it);
ButtonMenuItemArray_next(it), ++item_position) {

View File

@ -65,11 +65,18 @@ static void submenu_view_draw_callback(Canvas* canvas, void* _model) {
} else {
canvas_set_color(canvas, ColorBlack);
}
string_t disp_str;
string_init_set_str(disp_str, SubmenuItemArray_cref(it)->label);
elements_string_fit_width(canvas, disp_str, item_width - 20);
canvas_draw_str(
canvas,
6,
y_offset + (item_position * item_height) + item_height - 4,
SubmenuItemArray_cref(it)->label);
string_get_cstr(disp_str));
string_clear(disp_str);
}
position++;

View File

@ -47,8 +47,8 @@ class IrdaAppRemoteManager {
std::string make_remote_name(const std::string& full_name) const;
public:
static inline const uint32_t max_button_name_length = 31;
static inline const uint32_t max_remote_name_length = 31;
static inline const uint32_t max_button_name_length = 22;
static inline const uint32_t max_remote_name_length = 22;
bool add_remote_with_button(const char* button_name, const IrdaAppSignal& signal);
bool add_button(const char* button_name, const IrdaAppSignal& signal);