13 Jun
2023
13 Jun
'23
7:10 p.m.
On Tue Jun 13 18:23:33 2023 +0000, Esme Povirk wrote:
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. 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. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2993#note_35646