mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
Added support for double-width UTF-8 checkboxes and listbox in dialogs.
This commit is contained in:
parent
10303bb94a
commit
509fe2cf0d
@ -16,6 +16,9 @@
|
|||||||
#include "terminal/terminal.h"
|
#include "terminal/terminal.h"
|
||||||
#include "util/color.h"
|
#include "util/color.h"
|
||||||
|
|
||||||
|
/* Same as in src/bfu/checkbox.c */
|
||||||
|
#define CHECKBOX_LEN 3 /* "[X]" or "(X)" */
|
||||||
|
|
||||||
void
|
void
|
||||||
dlg_format_group(struct terminal *term,
|
dlg_format_group(struct terminal *term,
|
||||||
struct widget_data *widget_data,
|
struct widget_data *widget_data,
|
||||||
@ -33,13 +36,31 @@ dlg_format_group(struct terminal *term,
|
|||||||
int widget_width;
|
int widget_width;
|
||||||
int width;
|
int width;
|
||||||
unsigned char *text = widget_data->widget->text;
|
unsigned char *text = widget_data->widget->text;
|
||||||
int label_length = (text && *text) ? strlen(text) : 0;
|
int label_length;
|
||||||
int label_padding = (label_length > 0);
|
int label_padding;
|
||||||
|
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
if (term->utf8) {
|
||||||
|
if (text && *text)
|
||||||
|
label_length = utf8_ptr2cells(text, NULL);
|
||||||
|
else
|
||||||
|
label_length = 0;
|
||||||
|
} else
|
||||||
|
#endif /* CONFIG_UTF_8 */
|
||||||
|
label_length = (text && *text) ? strlen(text) : 0;
|
||||||
|
|
||||||
|
label_padding = (label_length > 0);
|
||||||
|
|
||||||
if (widget_data->widget->type == WIDGET_CHECKBOX) {
|
if (widget_data->widget->type == WIDGET_CHECKBOX) {
|
||||||
width = 3;
|
width = CHECKBOX_LEN;
|
||||||
} else if (widget_is_textfield(widget_data)) {
|
} else if (widget_is_textfield(widget_data)) {
|
||||||
width = widget_data->widget->datalen;
|
#ifdef CONFIG_UTF_8
|
||||||
|
if (term->utf8) {
|
||||||
|
width = utf8_ptr2cells(widget_data->widget->data,
|
||||||
|
NULL);
|
||||||
|
} else
|
||||||
|
#endif /* CONFIG_UTF_8 */
|
||||||
|
width = widget_data->widget->datalen;
|
||||||
} else {
|
} else {
|
||||||
/* TODO: handle all widget types. */
|
/* TODO: handle all widget types. */
|
||||||
widget_data++;
|
widget_data++;
|
||||||
@ -59,19 +80,50 @@ dlg_format_group(struct terminal *term,
|
|||||||
if (!format_only) {
|
if (!format_only) {
|
||||||
if (widget_data->widget->type == WIDGET_CHECKBOX) {
|
if (widget_data->widget->type == WIDGET_CHECKBOX) {
|
||||||
/* Draw text at right of checkbox. */
|
/* Draw text at right of checkbox. */
|
||||||
if (label_length)
|
if (label_length) {
|
||||||
draw_text(term, xpos + width + label_padding, *y,
|
#ifdef CONFIG_UTF_8
|
||||||
text, label_length,
|
if (term->utf8) {
|
||||||
0, color);
|
int lb = utf8_cells2bytes(
|
||||||
|
text,
|
||||||
|
label_length,
|
||||||
|
NULL);
|
||||||
|
draw_text(term, xpos + width
|
||||||
|
+ label_padding,
|
||||||
|
*y, text, lb, 0,
|
||||||
|
color);
|
||||||
|
} else
|
||||||
|
#endif /* CONFIG_UTF_8 */
|
||||||
|
{
|
||||||
|
draw_text(term, xpos + width
|
||||||
|
+ label_padding,
|
||||||
|
*y, text,
|
||||||
|
label_length, 0,
|
||||||
|
color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
set_box(&widget_data->box, xpos, *y, width, 1);
|
set_box(&widget_data->box, xpos, *y, width, 1);
|
||||||
|
|
||||||
} else if (widget_is_textfield(widget_data)) {
|
} else if (widget_is_textfield(widget_data)) {
|
||||||
/* Draw label at left of widget. */
|
/* Draw label at left of widget. */
|
||||||
if (label_length)
|
if (label_length) {
|
||||||
draw_text(term, xpos, *y,
|
#ifdef CONFIG_UTF_8
|
||||||
text, label_length,
|
if (term->utf8) {
|
||||||
0, color);
|
int lb = utf8_cells2bytes(
|
||||||
|
text,
|
||||||
|
label_length,
|
||||||
|
NULL);
|
||||||
|
draw_text(term, xpos, *y,
|
||||||
|
text, lb, 0, color);
|
||||||
|
} else
|
||||||
|
#endif /* CONFIG_UTF_8 */
|
||||||
|
{
|
||||||
|
draw_text(term, xpos, *y,
|
||||||
|
text, label_length,
|
||||||
|
0, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
set_box(&widget_data->box,
|
set_box(&widget_data->box,
|
||||||
xpos + label_padding + label_length, *y,
|
xpos + label_padding + label_length, *y,
|
||||||
width, 1);
|
width, 1);
|
||||||
@ -92,10 +144,16 @@ group_layouter(struct dialog_data *dlg_data)
|
|||||||
{
|
{
|
||||||
struct terminal *term = dlg_data->win->term;
|
struct terminal *term = dlg_data->win->term;
|
||||||
int w = dialog_max_width(term);
|
int w = dialog_max_width(term);
|
||||||
int rw = int_min(w, strlen(dlg_data->dlg->title));
|
int rw;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
int n = dlg_data->number_of_widgets - 2;
|
int n = dlg_data->number_of_widgets - 2;
|
||||||
|
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
if (term->utf8)
|
||||||
|
rw = int_min(w, utf8_ptr2cells(dlg_data->dlg->title, NULL));
|
||||||
|
else
|
||||||
|
#endif /* CONFIG_UTF_8 */
|
||||||
|
rw = int_min(w, strlen(dlg_data->dlg->title));
|
||||||
|
|
||||||
dlg_format_group(term, dlg_data->widgets_data, n,
|
dlg_format_group(term, dlg_data->widgets_data, n,
|
||||||
0, &y, w, &rw, 1);
|
0, &y, w, &rw, 1);
|
||||||
|
@ -453,6 +453,7 @@ display_listbox_item(struct listbox_item *item, void *data_, int *offset)
|
|||||||
} else {
|
} else {
|
||||||
unsigned char *text;
|
unsigned char *text;
|
||||||
struct listbox_ops *ops = data->box->ops;
|
struct listbox_ops *ops = data->box->ops;
|
||||||
|
int len_bytes;
|
||||||
|
|
||||||
assert(ops && ops->get_info);
|
assert(ops && ops->get_info);
|
||||||
|
|
||||||
@ -461,8 +462,14 @@ display_listbox_item(struct listbox_item *item, void *data_, int *offset)
|
|||||||
|
|
||||||
len = strlen(text);
|
len = strlen(text);
|
||||||
int_upper_bound(&len, int_max(0, data->widget_data->box.width - depth * 5));
|
int_upper_bound(&len, int_max(0, data->widget_data->box.width - depth * 5));
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
if (data->term->utf8)
|
||||||
|
len_bytes = utf8_cells2bytes(text, len, NULL);
|
||||||
|
else
|
||||||
|
#endif /* CONFIG_UTF_8 */
|
||||||
|
len_bytes = len;
|
||||||
|
|
||||||
draw_text(data->term, x, y, text, len, 0, text_color);
|
draw_text(data->term, x, y, text, len_bytes, 0, text_color);
|
||||||
|
|
||||||
mem_free(text);
|
mem_free(text);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user