Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #2155 to 24.05 #2156

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contrib/bsddialog/lib/barbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ do_mixedgauge(struct bsddialog_conf *conf, const char *text, int rows, int cols,
for (i = 0; i < (int)nminibars; i++)
max_minibarlen = MAX(max_minibarlen,
(int)strcols(CHECK_STR(minilabels[i])));
max_minibarlen += 3 + 16; /* seps + [...] */
max_minibarlen += 3 + 15; /* seps + [...] */
max_minibarlen = MAX(max_minibarlen, MIN_WMGBOX); /* mainbar */

if (prepare_dialog(conf, text, rows, cols, &d) != 0)
Expand All @@ -247,7 +247,7 @@ do_mixedgauge(struct bsddialog_conf *conf, const char *text, int rows, int cols,
hnotext = maxh;
}
if (maxw < max_minibarlen) {
label_len_cap = maxw - (3 + 16); /* seps + [...] */
label_len_cap = maxw - (3 + 15); /* seps + [...] */
max_minibarlen = maxw;
}
}
Expand Down
48 changes: 33 additions & 15 deletions contrib/bsddialog/lib/lib_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
* [static] text_properties();
* [static] text_autosize();
* [static] text_size();
* [static] widget_decor_height(htext, hnotext, bool buttons);
* [static] widget_decor_width();
* [static] widget_min_height(conf, htext, hnotext, bool buttons);
* [static] widget_min_width(conf, wtext, minw, buttons);
* set_widget_size();
Expand Down Expand Up @@ -755,23 +757,44 @@ text_size(struct bsddialog_conf *conf, int rows, int cols, const char *text,
}

static int
widget_min_height(struct bsddialog_conf *conf, int htext, int hnotext,
bool withbuttons)
widget_decor_height(int htext, int hnotext, bool withbuttons)
{
int min;
int h;

/* dialog borders */
min = BORDERS;
h = BORDERS;

/* text */
min += htext;
h += htext;

/* specific widget lines without text */
min += hnotext;
h += hnotext;

/* buttons */
if (withbuttons)
min += HBUTTONS; /* buttons and their up-border */
h += HBUTTONS; /* buttons and their up-border */

return (h);
}

static int
widget_decor_width(void)
{
int w;

/* dialog borders */
w = BORDERS;

return (w);
}

static int
widget_min_height(struct bsddialog_conf *conf, int htext, int hnotext,
bool withbuttons)
{
int min;

min = widget_decor_height(htext, hnotext, withbuttons);

/* conf.auto_minheight */
min = MAX(min, (int)conf->auto_minheight);
Expand Down Expand Up @@ -812,8 +835,7 @@ widget_min_width(struct bsddialog_conf *conf, int wtext, int minwidget,
min = MAX(min, wbottomtitle + 4);
}

/* dialog borders */
min += BORDERS;
min += widget_decor_width();
/* conf.auto_minwidth */
min = MAX(min, (int)conf->auto_minwidth);

Expand Down Expand Up @@ -895,21 +917,17 @@ int widget_maxsize(struct bsddialog_conf *conf, int rows, int cols, int *maxh,
if (text_size(conf, rows, cols, text, bs, 0, 0, &htext, &wtext) != 0)
return (BSDDIALOG_ERROR);

/*
* XXX: Should possibly clear conf->auto_min{height,width}
* temporarily.
*/
minheight = widget_min_height(conf, htext, 0, bs->nbuttons > 0);
if (h < minheight)
RETURN_FMTERROR("Current rows: %d, needed at least: %d",
h, minheight);
*maxh = h - minheight;
*maxh = h - widget_decor_height(htext, 0, bs->nbuttons > 0);

minwidth = widget_min_width(conf, wtext, 0, bs);
if (w < minwidth)
RETURN_FMTERROR("Current cols: %d, needed at least %d",
w, minwidth);
*maxw = w - minwidth;
*maxw = w - widget_decor_width();

return (0);
}
Expand Down