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 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 struct terminal
*term
= dlg_data
->win
->term
;
28 int space_between_widgets
= 1;
31 struct color_pair
*color
= get_bfu_color(term
, "dialog.text");
34 if_assert_failed
return;
39 unsigned char *text
= widget_data
->widget
->text
;
46 label_length
= utf8_ptr2cells(text
, NULL
);
50 #endif /* CONFIG_UTF8 */
51 label_length
= (text
&& *text
) ? strlen(text
) : 0;
53 label_padding
= (label_length
> 0);
55 if (widget_data
->widget
->type
== WIDGET_CHECKBOX
) {
57 } else if (widget_is_textfield(widget_data
)) {
60 width
= utf8_ptr2cells(widget_data
->widget
->data
,
63 #endif /* CONFIG_UTF8 */
64 width
= widget_data
->widget
->datalen
;
66 /* TODO: handle all widget types. */
71 int_bounds(&label_length
, 0, w
- width
- label_padding
);
73 widget_width
= width
+ label_padding
+ label_length
;
74 if (line_width
+ widget_width
> w
) {
76 (*y
) += 2; /* Next line */
79 xpos
= x
+ line_width
;
82 if (widget_data
->widget
->type
== WIDGET_CHECKBOX
) {
83 /* Draw text at right of checkbox. */
87 int lb
= utf8_cells2bytes(
91 draw_dlg_text(term
, dlg_data
, xpos
+ width
96 #endif /* CONFIG_UTF8 */
98 draw_dlg_text(term
, dlg_data
, xpos
+ width
106 set_box(&widget_data
->box
, xpos
, *y
, width
, 1);
108 } else if (widget_is_textfield(widget_data
)) {
109 /* Draw label at left of widget. */
113 int lb
= utf8_cells2bytes(
117 draw_dlg_text(term
, dlg_data
, xpos
, *y
,
120 #endif /* CONFIG_UTF8 */
122 draw_dlg_text(term
, dlg_data
, xpos
, *y
,
128 set_box(&widget_data
->box
,
129 xpos
+ label_padding
+ label_length
, *y
,
134 line_width
+= widget_width
;
135 if (rw
) int_bounds(rw
, line_width
, w
);
136 line_width
+= space_between_widgets
;
144 group_layouter(struct dialog_data
*dlg_data
)
146 struct terminal
*term
= dlg_data
->win
->term
;
147 int w
= dialog_max_width(term
);
150 int n
= dlg_data
->number_of_widgets
- 2;
154 rw
= int_min(w
, utf8_ptr2cells(dlg_data
->dlg
->title
, NULL
));
156 #endif /* CONFIG_UTF8 */
157 rw
= int_min(w
, strlen(dlg_data
->dlg
->title
));
159 dlg_format_group(dlg_data
, dlg_data
->widgets_data
, n
,
163 dlg_format_buttons(dlg_data
, dlg_data
->widgets_data
+ n
, 2, 0, &y
, w
,
164 &rw
, ALIGN_CENTER
, 1);
168 draw_dialog(dlg_data
, w
, y
);
170 y
= dlg_data
->box
.y
+ DIALOG_TB
+ 1;
171 dlg_format_group(dlg_data
, dlg_data
->widgets_data
, n
,
172 dlg_data
->box
.x
+ DIALOG_LB
, &y
, w
, NULL
, 0);
175 dlg_format_buttons(dlg_data
, dlg_data
->widgets_data
+ n
, 2,
176 dlg_data
->box
.x
+ DIALOG_LB
, &y
, w
, &rw
, ALIGN_CENTER
, 0);