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"
19 /* Same as in src/bfu/checkbox.c */
20 #define CHECKBOX_LEN 3 /* "[X]" or "(X)" */
23 dlg_format_group(struct terminal
*term
, struct dialog_data
*dlg_data
,
24 struct widget_data
*widget_data
,
25 int n
, int x
, int *y
, int w
, int *rw
, int format_only
)
27 int space_between_widgets
= 1;
30 struct color_pair
*color
= get_bfu_color(term
, "dialog.text");
33 if_assert_failed
return;
38 unsigned char *text
= widget_data
->widget
->text
;
45 label_length
= utf8_ptr2cells(text
, NULL
);
49 #endif /* CONFIG_UTF8 */
50 label_length
= (text
&& *text
) ? strlen(text
) : 0;
52 label_padding
= (label_length
> 0);
54 if (widget_data
->widget
->type
== WIDGET_CHECKBOX
) {
56 } else if (widget_is_textfield(widget_data
)) {
59 width
= utf8_ptr2cells(widget_data
->widget
->data
,
62 #endif /* CONFIG_UTF8 */
63 width
= widget_data
->widget
->datalen
;
65 /* TODO: handle all widget types. */
70 int_bounds(&label_length
, 0, w
- width
- label_padding
);
72 widget_width
= width
+ label_padding
+ label_length
;
73 if (line_width
+ widget_width
> w
) {
75 (*y
) += 2; /* Next line */
78 xpos
= x
+ line_width
;
81 if (widget_data
->widget
->type
== WIDGET_CHECKBOX
) {
82 /* Draw text at right of checkbox. */
86 int lb
= utf8_cells2bytes(
90 draw_dlg_text(term
, dlg_data
, xpos
+ width
95 #endif /* CONFIG_UTF8 */
97 draw_dlg_text(term
, dlg_data
, xpos
+ width
105 set_box(&widget_data
->box
, xpos
, *y
, width
, 1);
107 } else if (widget_is_textfield(widget_data
)) {
108 /* Draw label at left of widget. */
112 int lb
= utf8_cells2bytes(
116 draw_dlg_text(term
, dlg_data
, xpos
, *y
,
119 #endif /* CONFIG_UTF8 */
121 draw_dlg_text(term
, dlg_data
, xpos
, *y
,
127 set_box(&widget_data
->box
,
128 xpos
+ label_padding
+ label_length
, *y
,
133 line_width
+= widget_width
;
134 if (rw
) int_bounds(rw
, line_width
, w
);
135 line_width
+= space_between_widgets
;
143 group_layouter(struct dialog_data
*dlg_data
)
145 struct terminal
*term
= dlg_data
->win
->term
;
146 int w
= dialog_max_width(term
);
149 int n
= dlg_data
->number_of_widgets
- 2;
153 rw
= int_min(w
, utf8_ptr2cells(dlg_data
->dlg
->title
, NULL
));
155 #endif /* CONFIG_UTF8 */
156 rw
= int_min(w
, strlen(dlg_data
->dlg
->title
));
158 dlg_format_group(term
, dlg_data
, dlg_data
->widgets_data
, n
,
162 dlg_format_buttons(term
, dlg_data
, dlg_data
->widgets_data
+ n
, 2, 0, &y
, w
,
163 &rw
, ALIGN_CENTER
, 1);
167 draw_dialog(dlg_data
, w
, y
);
169 y
= dlg_data
->box
.y
+ DIALOG_TB
+ 1;
170 dlg_format_group(term
, dlg_data
, dlg_data
->widgets_data
, n
,
171 dlg_data
->box
.x
+ DIALOG_LB
, &y
, w
, NULL
, 0);
174 dlg_format_buttons(term
, dlg_data
, dlg_data
->widgets_data
+ n
, 2,
175 dlg_data
->box
.x
+ DIALOG_LB
, &y
, w
, &rw
, ALIGN_CENTER
, 0);