On Tue Jun 13 19:10:31 2023 +0000, Esme Povirk wrote:
I made an attempt at simplification (untested):
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) { if (crumbs_visible_n == 0) { /* fit as much of the last crumb as possible */ crumb1->current_w = max_crumbs_w - w; w = max_crumbs_w; crumbs_visible_n += 1; /* try to also fit the next crumb */ continue; } else if (crumbs_visible_n == 1) { INT min_crumb_width = (crumbs_visible_n == 1) ? MulDiv(56, info->dpi_x, USER_DEFAULT_SCREEN_DPI) : 1; min_crumb_width = min(min_crumb_width, crumb1->full_w); if (w + min_crumb_width <= max_crumbs_w) { /* fit as much of this crumb as possible */ crumb1->current_w = max_crumbs_w - w; w = max_crumbs_w; } else { /* take space away from the last crumb to get this one to the minimum */ struct crumb *last_crumb = (struct crumb *)list_tail(&info->crumbs); last_crumb->current_w = max(0, max_crumbs_w - min_crumb_width); crumb1->current_w = min_crumb_width; w = last_crumb->current_w + crumb1->current_w; } crumbs_visible_n += 1; } break; } w = next_w; crumbs_visible_n += 1; }
It's still complicated, but it can use some bits of the loop and reduce the special cases for fewer than 2 items.
Nice, starting point calculations (`prev_x`) are missing, but after including them and giving it a quick test, does seem to work.