On Mon Jun 12 18:48:07 2023 +0000, Vladislav Timonin wrote:
<details><summary>Sorry I'm being slow, something like this?</summary> ```c LIST_FOR_EACH_ENTRY_REV(crumb1, &info->crumbs, struct crumb, entry) { INT next_w = w + crumb1->full_w; crumb1->current_w = crumb1->full_w; if (next_w > max_crumbs_w) { /* always show at least 2 crumbs */ if (crumbs_visible_n < 2) { crumb1 = (struct crumb *)list_tail(&info->crumbs); crumb2 = (struct crumb *)list_tail(&crumb1->entry); if (&crumb2->entry == &info->crumbs) /* only 1 crumb in the list */ { if (crumbs_visible_n == 0) /* that doesn't fit on screen */ { crumb1->current_w = max_crumbs_w; crumbs_visible_n = 1; } prev_x = buttons_w + crumb1->current_w; } else { /* at least 2 crumbs in the list, 1 or 0 crumbs on screen */ /* last crumb should take as much space as possible */ INT min_crumb_w = MulDiv(56, info->dpi_x, USER_DEFAULT_SCREEN_DPI); INT crumb2_size = crumb2->full_w; if (crumb2_size > min_crumb_w) crumb2_size = min_crumb_w; /* calculate how much extra space is required to fit both crumbs */ w = (crumb1->full_w + crumb2_size) - max_crumbs_w; if (w > 0) { /* not enough space for last crumb, truncate it */ crumb1->current_w = max(0, crumb1->full_w - w); crumb2->current_w = crumb2_size; } else /* enough space for last crumb, let the previous crumb take leftover space */ crumb2->current_w = max_crumbs_w - crumb1->full_w; crumbs_visible_n = 2; prev_x = buttons_w + crumb1->current_w + crumb2->current_w; } } break; } w = next_w; crumbs_visible_n += 1; prev_x = buttons_w + w; } ``` </details> Moving the `if (crumbs_visible_n < 2)` branch into the `if (next_w > max_crumbs_w)`, and recalculating `else` of `crumbs_visible_n < 2` on each iteration.
Oh, I forgot how complicated the logic is there, guess it can't be simplified that way.
It would be really nice to simplify it though.