diff options
Diffstat (limited to 'desktop/textarea.c')
-rw-r--r-- | desktop/textarea.c | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/desktop/textarea.c b/desktop/textarea.c index a12ed3282..9b14773cf 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -75,6 +75,17 @@ struct textarea { int vis_width; /**< Visible width, in pixels */ int vis_height; /**< Visible height, in pixels */ + int pad_top; + int pad_right; + int pad_bottom; + int pad_left; + + int border_width; + colour border_col; + + plot_font_style_t fstyle; /**< Text style */ + plot_font_style_t sel_fstyle; /**< Text style */ + char *text; /**< UTF-8 text */ unsigned int text_alloc; /**< Size of allocated text */ unsigned int text_len; /**< Length of text, in bytes */ @@ -92,8 +103,6 @@ struct textarea { int sel_start; /**< Character index of sel start(inclusive) */ int sel_end; /**< Character index of sel end(exclusive) */ - plot_font_style_t fstyle; /**< Text style */ - int line_count; /**< Count of lines */ #define LINE_CHUNK_SIZE 16 struct line_info *lines; /**< Line info array */ @@ -238,7 +247,6 @@ static bool textarea_select_fragment(struct textarea * ta) static bool textarea_scroll_visible(struct textarea *ta) { int x0, x1, y0, y1, x, y; - int index, b_off; bool scrolled = false; if (ta->caret_pos.char_off == -1) @@ -249,21 +257,8 @@ static bool textarea_scroll_visible(struct textarea *ta) y0 = 0; y1 = ta->vis_height; - index = textarea_get_caret(ta); - - /* find byte offset of caret position */ - for (b_off = 0; index-- > 0; - b_off = utf8_next(ta->text, ta->text_len, b_off)) - ; /* do nothing */ - - nsfont.font_width(&ta->fstyle, - ta->text + ta->lines[ta->caret_pos.line].b_start, - b_off - ta->lines[ta->caret_pos.line].b_start, - &x); - - /* top-left of caret */ - x += MARGIN_LEFT - ta->scroll_x; - y = ta->line_height * ta->caret_pos.line - ta->scroll_y; + x = ta->caret_x - ta->scroll_x; + y = ta->caret_y - ta->scroll_y; /* check and change vertical scroll */ if (y < y0) { @@ -622,8 +617,7 @@ static bool textarea_replace_text(struct textarea *ta, unsigned int start, /* exported interface, documented in textarea.h */ -struct textarea *textarea_create(int width, int height, - textarea_flags flags, const plot_font_style_t *style, +struct textarea *textarea_create(const textarea_setup *setup, textarea_redraw_request_callback redraw_request, void *data) { struct textarea *ret; @@ -641,14 +635,30 @@ struct textarea *textarea_create(int width, int height, ret->redraw_request = redraw_request; ret->data = data; - ret->vis_width = width; - ret->vis_height = height; + + ret->flags = setup->flags; + ret->vis_width = setup->width; + ret->vis_height = setup->height; + + ret->pad_top = setup->pad_top; + ret->pad_right = setup->pad_right; + ret->pad_bottom = setup->pad_bottom; + ret->pad_left = setup->pad_left; + + ret->border_width = setup->border_width; + ret->border_col = setup->border_col; + + ret->fstyle = setup->text; + + ret->sel_fstyle = setup->text; + ret->sel_fstyle.foreground = setup->selected_text; + ret->sel_fstyle.background = setup->selected_bg; + ret->scroll_x = 0; ret->scroll_y = 0; ret->drag_start_char = 0; - ret->flags = flags; ret->text = malloc(64); if (ret->text == NULL) { LOG(("malloc failed")); @@ -660,11 +670,10 @@ struct textarea *textarea_create(int width, int height, ret->text_len = 1; ret->text_utf8_len = 0; - ret->fstyle = *style; - ret->line_height = FIXTOINT(FDIV((FMUL(FLTTOFIX(1.2), FMUL(nscss_screen_dpi, - INTTOFIX((style->size / FONT_SIZE_SCALE))))), F_72)); + INTTOFIX((setup->text.size / + FONT_SIZE_SCALE))))), F_72)); ret->caret_pos.line = ret->caret_pos.char_off = 0; ret->caret_x = MARGIN_LEFT; @@ -817,10 +826,14 @@ bool textarea_set_caret(struct textarea *ta, int caret) ta->caret_y = y; if (textarea_scroll_visible(ta)) { + /* Scrolled; redraw everything */ ta->redraw_request(ta->data, 0, 0, ta->vis_width, ta->vis_height); } else { + /* Just caret moved, redraw it */ + x -= ta->scroll_x; + y -= ta->scroll_y; x0 = max(x - 1, MARGIN_LEFT); y0 = max(y + text_y_offset, 0); x1 = min(x + 1, ta->vis_width - MARGIN_RIGHT); @@ -861,7 +874,7 @@ int textarea_get_caret(struct textarea *ta) /* exported interface, documented in textarea.h */ -void textarea_redraw(struct textarea *ta, int x, int y, +void textarea_redraw(struct textarea *ta, int x, int y, colour bg, const struct rect *clip, const struct redraw_context *ctx) { const struct plotter_table *plot = ctx->plot; |