1 /* Widget group implementation. */
11 #include "bfu/dialog.h"
12 #include "bfu/button.h"
13 #include "bfu/group.h"
14 #include "intl/gettext/libintl.h"
15 #include "terminal/draw.h"
16 #include "terminal/terminal.h"
17 #include "util/color.h"
20 dlg_format_group(struct terminal
*term
,
21 struct widget_data
*widget_data
,
22 int n
, int x
, int *y
, int w
, int *rw
)
24 int space_between_widgets
= 1;
27 struct color_pair
*color
= get_bfu_color(term
, "dialog.text");
30 if_assert_failed
return;
35 unsigned char *text
= widget_data
->widget
->text
;
36 int label_length
= (text
&& *text
) ? strlen(text
) : 0;
37 int label_padding
= (label_length
> 0);
39 if (widget_data
->widget
->type
== WIDGET_CHECKBOX
) {
41 } else if (widget_is_textfield(widget_data
)) {
42 width
= widget_data
->widget
->datalen
;
44 /* TODO: handle all widget types. */
49 int_bounds(&label_length
, 0, w
- width
- label_padding
);
51 widget_width
= width
+ label_padding
+ label_length
;
52 if (line_width
+ widget_width
> w
) {
54 (*y
) += 2; /* Next line */
57 xpos
= x
+ line_width
;
60 if (widget_data
->widget
->type
== WIDGET_CHECKBOX
) {
61 /* Draw text at right of checkbox. */
63 draw_text(term
, xpos
+ width
+ label_padding
, *y
,
67 set_box(&widget_data
->box
, xpos
, *y
, width
, 1);
69 } else if (widget_is_textfield(widget_data
)) {
70 /* Draw label at left of widget. */
72 draw_text(term
, xpos
, *y
,
76 set_box(&widget_data
->box
,
77 xpos
+ label_padding
+ label_length
, *y
,
82 line_width
+= widget_width
;
83 if (rw
) int_bounds(rw
, line_width
, w
);
84 line_width
+= space_between_widgets
;
92 group_layouter(struct dialog_data
*dlg_data
)
94 struct terminal
*term
= dlg_data
->win
->term
;
95 int w
= dialog_max_width(term
);
96 int rw
= int_min(w
, strlen(dlg_data
->dlg
->title
));
98 int n
= dlg_data
->number_of_widgets
- 2;
100 dlg_format_group(NULL
, dlg_data
->widgets_data
, n
,
104 dlg_format_buttons(NULL
, dlg_data
->widgets_data
+ n
, 2, 0, &y
, w
,
109 draw_dialog(dlg_data
, w
, y
);
111 y
= dlg_data
->box
.y
+ DIALOG_TB
+ 1;
112 dlg_format_group(term
, dlg_data
->widgets_data
, n
,
113 dlg_data
->box
.x
+ DIALOG_LB
, &y
, w
, NULL
);
116 dlg_format_buttons(term
, dlg_data
->widgets_data
+ n
, 2,
117 dlg_data
->box
.x
+ DIALOG_LB
, &y
, w
, &rw
, ALIGN_CENTER
);