Skip to content

Commit 2283ee3

Browse files
committed
bsddialog: Fix widget_maxsize to only take into account window decor
For the height this doesn't matter unless auto_minheight is non-zero, but for the width it does, as it would subtract off the maximum of various things including the text width, which is clearly nonsense here. All we want to do is compute how much space for content there is; what's on other lines doesn't matter. Fixes: 64f7073 ("bsddialog: Optionally truncate long mixedgauge labels and screens")
1 parent 2a34c40 commit 2283ee3

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

contrib/bsddialog/lib/lib_util.c

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
* [static] text_properties();
6969
* [static] text_autosize();
7070
* [static] text_size();
71+
* [static] widget_decor_height(htext, hnotext, bool buttons);
72+
* [static] widget_decor_width();
7173
* [static] widget_min_height(conf, htext, hnotext, bool buttons);
7274
* [static] widget_min_width(conf, wtext, minw, buttons);
7375
* set_widget_size();
@@ -755,23 +757,44 @@ text_size(struct bsddialog_conf *conf, int rows, int cols, const char *text,
755757
}
756758

757759
static int
758-
widget_min_height(struct bsddialog_conf *conf, int htext, int hnotext,
759-
bool withbuttons)
760+
widget_decor_height(int htext, int hnotext, bool withbuttons)
760761
{
761-
int min;
762+
int h;
762763

763764
/* dialog borders */
764-
min = BORDERS;
765+
h = BORDERS;
765766

766767
/* text */
767-
min += htext;
768+
h += htext;
768769

769770
/* specific widget lines without text */
770-
min += hnotext;
771+
h += hnotext;
771772

772773
/* buttons */
773774
if (withbuttons)
774-
min += HBUTTONS; /* buttons and their up-border */
775+
h += HBUTTONS; /* buttons and their up-border */
776+
777+
return (h);
778+
}
779+
780+
static int
781+
widget_decor_width(void)
782+
{
783+
int w;
784+
785+
/* dialog borders */
786+
w = BORDERS;
787+
788+
return (w);
789+
}
790+
791+
static int
792+
widget_min_height(struct bsddialog_conf *conf, int htext, int hnotext,
793+
bool withbuttons)
794+
{
795+
int min;
796+
797+
min = widget_decor_height(htext, hnotext, withbuttons);
775798

776799
/* conf.auto_minheight */
777800
min = MAX(min, (int)conf->auto_minheight);
@@ -812,8 +835,7 @@ widget_min_width(struct bsddialog_conf *conf, int wtext, int minwidget,
812835
min = MAX(min, wbottomtitle + 4);
813836
}
814837

815-
/* dialog borders */
816-
min += BORDERS;
838+
min += widget_decor_width();
817839
/* conf.auto_minwidth */
818840
min = MAX(min, (int)conf->auto_minwidth);
819841

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

898-
/*
899-
* XXX: Should possibly clear conf->auto_min{height,width}
900-
* temporarily.
901-
*/
902920
minheight = widget_min_height(conf, htext, 0, bs->nbuttons > 0);
903921
if (h < minheight)
904922
RETURN_FMTERROR("Current rows: %d, needed at least: %d",
905923
h, minheight);
906-
*maxh = h - minheight;
924+
*maxh = h - widget_decor_height(htext, 0, bs->nbuttons > 0);
907925

908926
minwidth = widget_min_width(conf, wtext, 0, bs);
909927
if (w < minwidth)
910928
RETURN_FMTERROR("Current cols: %d, needed at least %d",
911929
w, minwidth);
912-
*maxw = w - minwidth;
930+
*maxw = w - widget_decor_width();
913931

914932
return (0);
915933
}

0 commit comments

Comments
 (0)