0
0
mirror of https://github.com/rkd77/elinks.git synced 2025-06-30 22:19:29 -04:00

[margins] Hard margins. Refs #360

Before there were "soft" margins, and some pages have not been displayed correctly.
Now, there are hard margins. So the document has margin 0.
And while displayed, document text if offset by option's margin.
Also document->width is calculated as term->width - 2 * margin if not
set preferred document width. There are some issues with scrolling, frames, etc,
but they can be resolved later.
This commit is contained in:
Witold Filipczyk 2025-01-09 18:45:33 +01:00
parent 94c6cd0767
commit f4589dc7f6
3 changed files with 29 additions and 12 deletions

View File

@ -870,12 +870,12 @@ init_html_parser(struct uri *uri, struct document *document,
elformat.color.link_number = options->default_color.link_number;
par_elformat.align = ALIGN_LEFT;
par_elformat.leftmargin = options->margin;
par_elformat.rightmargin = options->margin;
par_elformat.leftmargin = 0; //options->margin;
par_elformat.rightmargin = 0; //options->margin;
par_elformat.width = options->document_width;
par_elformat.list_level = par_elformat.list_number = 0;
par_elformat.dd_margin = options->margin;
par_elformat.dd_margin = 0; //options->margin;
par_elformat.flags = P_DISC;
par_elformat.color.background = options->default_style.color.background;

View File

@ -38,8 +38,13 @@ init_document_options(struct session *ses, struct document_options *doo)
doo->document_width = get_opt_int("document.browse.preferred_document_width", ses);
if (ses) {
if (doo->document_width <= 0 || doo->document_width > ses->tab->term->width)
doo->document_width = ses->tab->term->width;
if (doo->document_width <= 0 || doo->document_width > ses->tab->term->width) {
doo->document_width = ses->tab->term->width - 2 * doo->margin;
if (doo->document_width <= 0) {
doo->document_width = ses->tab->term->width;
}
}
} else {
/* Assume we are in -dump mode. Should we consolidate
* document.dump.width with document.browse.preferred_document_width ? */

View File

@ -298,7 +298,7 @@ draw_doc(struct session *ses, struct document_view *doc_view, int active)
struct color_pair color;
struct view_state *vs;
struct terminal *term;
struct el_box *box;
struct el_box *box, box_bg;
struct screen_char *last = NULL;
int vx, vy;
@ -310,10 +310,22 @@ draw_doc(struct session *ses, struct document_view *doc_view, int active)
box = &doc_view->box;
term = ses->tab->term;
copy_struct(&box_bg, box);
if (box->x == 0) {
int margin = get_opt_int("document.browse.margin_width", ses);
box->x += margin;
if (box->width > 2 * margin) {
box->width -= 2 * margin;
}
}
/* The code in this function assumes that both width and height are
* bigger than 1 so we have to bail out here. */
if (box->width < 2 || box->height < 2) return;
if (active) {
/* When redrawing the document after things like link menu we
* have to reset the cursor routing state. */
@ -335,9 +347,9 @@ draw_doc(struct session *ses, struct document_view *doc_view, int active)
if (!vs) {
int bgchar = get_opt_int("ui.background_char", ses);
#ifdef CONFIG_UTF8
draw_box(term, box, bgchar, 0, get_bfu_color(term, "desktop"));
draw_box(term, &box_bg, bgchar, 0, get_bfu_color(term, "desktop"));
#else
draw_box(term, box, (unsigned char)bgchar, 0, get_bfu_color(term, "desktop"));
draw_box(term, &box_bg, (unsigned char)bgchar, 0, get_bfu_color(term, "desktop"));
#endif
return;
}
@ -345,9 +357,9 @@ draw_doc(struct session *ses, struct document_view *doc_view, int active)
if (document_has_frames(doc_view->document)) {
int bgchar = get_opt_int("ui.background_char", ses);
#ifdef CONFIG_UTF8
draw_box(term, box, bgchar, 0, get_bfu_color(term, "desktop"));
draw_box(term, &box_bg, bgchar, 0, get_bfu_color(term, "desktop"));
#else
draw_box(term, box, (unsigned char)bgchar, 0, get_bfu_color(term, "desktop"));
draw_box(term, &box_bg, (unsigned char)bgchar, 0, get_bfu_color(term, "desktop"));
#endif
draw_frame_lines(term, doc_view->document->frame_desc, box->x, box->y, &color);
if (vs->current_link == -1)
@ -404,9 +416,9 @@ draw_doc(struct session *ses, struct document_view *doc_view, int active)
int bgchar = get_opt_int("ui.background_char", ses);
#ifdef CONFIG_UTF8
draw_box(term, box, bgchar, 0, get_bfu_color(term, "desktop"));
draw_box(term, &box_bg, bgchar, 0, get_bfu_color(term, "desktop"));
#else
draw_box(term, box, (unsigned char)bgchar, 0, get_bfu_color(term, "desktop"));
draw_box(term, &box_bg, (unsigned char)bgchar, 0, get_bfu_color(term, "desktop"));
#endif
if (!doc_view->document->height) {
return;