1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-07-26 16:45:12 -04:00

[bfu] draw_*_node

This commit is contained in:
Witold Filipczyk 2022-03-17 19:11:13 +01:00
parent 179e30aa12
commit 4b93f841a8
3 changed files with 96 additions and 12 deletions

View File

@ -112,6 +112,7 @@ dlg_format_field(struct dialog_data *dlg_data,
static int *prev_y; /* Assert the uniqueness of y */ /* TODO: get rid of this !! --Zas */
char *label = widget_data->widget->text;
struct color_pair *text_color = NULL;
unsigned int text_color_node = 0;
int label_width = 0;
int float_label = widget_data->widget->info.field.flags & (INPFIELD_FLOAT|INPFIELD_FLOAT2);
@ -131,9 +132,13 @@ dlg_format_field(struct dialog_data *dlg_data,
}
if (label && *label) {
if (!format_only) text_color = get_bfu_color(term, "dialog.text");
if (!format_only) {
// text_color = get_bfu_color(term, "dialog.text");
text_color_node = get_bfu_color_node(term, "dialog.text");
}
dlg_format_text_do(dlg_data, label, x, y, w, rw, text_color, ALIGN_LEFT, format_only);
// dlg_format_text_do(dlg_data, label, x, y, w, rw, text_color, ALIGN_LEFT, format_only);
dlg_format_text_do_node(dlg_data, label, x, y, w, rw, text_color_node, ALIGN_LEFT, format_only);
}
/* XXX: We want the field and label on the same line if the terminal
@ -141,9 +146,13 @@ dlg_format_field(struct dialog_data *dlg_data,
if (label && *label && float_label) {
if (widget_data->widget->info.field.flags & INPFIELD_FLOAT) {
(*y) -= INPUTFIELD_HEIGHT;
dlg_format_text_do(dlg_data, INPUTFIELD_FLOAT_SEPARATOR,
// dlg_format_text_do(dlg_data, INPUTFIELD_FLOAT_SEPARATOR,
// x + label_width, y, w, rw,
// text_color, ALIGN_LEFT, format_only);
dlg_format_text_do_node(dlg_data, INPUTFIELD_FLOAT_SEPARATOR,
x + label_width, y, w, rw,
text_color, ALIGN_LEFT, format_only);
text_color_node, ALIGN_LEFT, format_only);
w -= INPUTFIELD_FLOAT_SEPARATOR_LEN + INPUTFIELD_FLOATLABEL_PADDING;
x += INPUTFIELD_FLOAT_SEPARATOR_LEN + INPUTFIELD_FLOATLABEL_PADDING;
}
@ -266,6 +275,7 @@ display_field_do(struct dialog_data *dlg_data, struct widget_data *widget_data,
{
struct terminal *term = dlg_data->win->term;
struct color_pair *color;
unsigned int color_node;
int sel = is_selected_widget(dlg_data, widget_data);
#ifdef CONFIG_UTF8
int len = 0, left = 0;
@ -289,12 +299,23 @@ display_field_do(struct dialog_data *dlg_data, struct widget_data *widget_data,
int_lower_bound(&widget_data->info.field.vpos, 0);
}
color = get_bfu_color(term, "dialog.field");
if (color)
draw_box(term, &widget_data->box, ' ', 0, color);
// color = get_bfu_color(term, "dialog.field");
color_node = get_bfu_color_node(term, "dialog.field");
// if (color) {
// draw_box(term, &widget_data->box, ' ', 0, color);
// }
if (color_node) {
draw_box_node(term, &widget_data->box, ' ', 0, color_node);
}
// color = get_bfu_color(term, "dialog.field-text");
// if (color) {
color_node = get_bfu_color_node(term, "dialog.field-text");
if (color_node) {
color = get_bfu_color(term, "dialog.field-text");
if (color) {
char *text = widget_data->cdata + widget_data->info.field.vpos;
int len, w;
@ -313,15 +334,18 @@ display_field_do(struct dialog_data *dlg_data, struct widget_data *widget_data,
if (term->utf8_cp)
w = utf8_cells2bytes(text, w, NULL);
#endif /* CONFIG_UTF8 */
draw_dlg_text(dlg_data, widget_data->box.x, widget_data->box.y,
text, w, 0, color);
// draw_dlg_text(dlg_data, widget_data->box.x, widget_data->box.y,
// text, w, 0, color);
draw_dlg_text_node(dlg_data, widget_data->box.x, widget_data->box.y,
text, w, 0, color_node);
} else {
struct el_box box;
copy_box(&box, &widget_data->box);
box.width = w;
draw_box(term, &box, '*', 0, color);
// draw_box(term, &box, '*', 0, color);
draw_box_node(term, &box, '*', 0, color_node);
}
}

View File

@ -264,6 +264,61 @@ dlg_format_text_do(struct dialog_data *dlg_data,
}
}
/* Format text according to dialog box and alignment. */
void
dlg_format_text_do_node(struct dialog_data *dlg_data,
const char *text,
int x, int *y, int width, int *real_width,
unsigned int color_node, format_align_T align,
int format_only)
{
#ifdef CONFIG_UTF8
struct terminal *term = dlg_data->win->term;
#endif
int line_width;
int firstline = 1;
for (; *text; text += line_width, (*y)++) {
int shift;
int cells = 0;
/* Skip first leading \n or space. */
if (!firstline && isspace(*text))
text++;
else
firstline = 0;
if (!*text) break;
#ifdef CONFIG_UTF8
line_width = split_line(text, width, &cells, term->utf8_cp);
#else
line_width = split_line(text, width, &cells);
#endif /* CONFIG_UTF8 */
/* split_line() may return 0. */
if (line_width < 1) {
line_width = 1; /* Infinite loop prevention. */
continue;
}
if (real_width) int_lower_bound(real_width, cells);
if (format_only || !line_width) continue;
/* Calculate the number of chars to indent */
if (align == ALIGN_CENTER)
shift = (width - cells) / 2;
else if (align == ALIGN_RIGHT)
shift = width - cells;
else
shift = 0;
assert(cells <= width && shift < width);
draw_dlg_text_node(dlg_data, x + shift, *y, text, line_width, 0, color_node);
}
}
void
dlg_format_text(struct dialog_data *dlg_data,
struct widget_data *widget_data,

View File

@ -54,6 +54,11 @@ void dlg_format_text_do(struct dialog_data *dlg_data,
const char *text, int x, int *y, int w, int *rw,
struct color_pair *scolor, format_align_T align, int format_only);
void dlg_format_text_do_node(struct dialog_data *dlg_data,
const char *text, int x, int *y, int w, int *rw,
unsigned int scolor_node, format_align_T align, int format_only);
void
dlg_format_text(struct dialog_data *dlg_data, struct widget_data *widget_data,
int x, int *y, int dlg_width, int *real_width, int height, int format_only);