summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--desktop/textarea.c67
-rw-r--r--desktop/textarea.h45
-rw-r--r--desktop/tree.c25
3 files changed, 92 insertions, 45 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;
diff --git a/desktop/textarea.h b/desktop/textarea.h
index e4fa2c7aa..641d39c73 100644
--- a/desktop/textarea.h
+++ b/desktop/textarea.h
@@ -36,6 +36,26 @@ typedef enum textarea_flags {
TEXTAREA_READONLY = (1 << 2)
} textarea_flags;
+typedef struct textarea_setup {
+ textarea_flags flags; /**< Setup flags */
+
+ int width; /**< Textarea width */
+ int height; /**< Textarea height */
+
+ int pad_top; /**< Textarea top padding */
+ int pad_right; /**< Textarea right padding */
+ int pad_bottom; /**< Textarea bottom padding */
+ int pad_left; /**< Textarea left padding */
+
+ int border_width; /**< Textarea border width */
+ colour border_col; /**< Textarea border colour */
+
+ colour selected_text; /**< Textarea selected text colour */
+ colour selected_bg; /**< Textarea selection background colour */
+ plot_font_style_t text; /**< Font and textarea background colour */
+
+} textarea_setup;
+
struct textarea;
@@ -45,17 +65,12 @@ typedef void(*textarea_redraw_request_callback)(void *data, int x, int y,
/**
* Create a text area
*
- * \param width width of the text area
- * \param height width of the text area
- * \param flags text area flags
- * \param style font style
- * \param redraw_start_callback will be called when textarea wants to redraw
- * \param redraw_end_callback will be called when textarea finisjes redrawing
- * \param data user specified data which will be passed to redraw callbacks
+ * \param setup textarea settings and style
+ * \param redraw_callback will be called when textarea wants to redraw
+ * \param data user specified data which will be passed to callbacks
* \return Opaque handle for textarea or 0 on error
*/
-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);
/**
@@ -106,14 +121,14 @@ int textarea_get_caret(struct textarea *ta);
/**
* Handle redraw requests for text areas
*
- * \param redraw Redraw request block
- * \param x0 left X coordinate of redraw area
- * \param y0 top Y coordinate of redraw area
- * \param x1 right X coordinate of redraw area
- * \param y1 bottom Y coordinate of redraw area
+ * \param ta textarea to render
+ * \param x x coordinate of textarea top
+ * \param y y coordinate of textarea left
+ * \param bg background colour under textarea
+ * \param clip clip rectangle
* \param ctx current redraw context
*/
-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);
/**
diff --git a/desktop/tree.c b/desktop/tree.c
index 250bdd861..a48b615a0 100644
--- a/desktop/tree.c
+++ b/desktop/tree.c
@@ -2078,7 +2078,10 @@ void tree_draw(struct tree *tree, int x, int y,
y = y + tree->editing->box.y;
if (tree->editing->type == NODE_ELEMENT_TEXT_PLUS_ICON)
x += NODE_INSTEP;
- textarea_redraw(tree->textarea, x, y, &clip, &new_ctx);
+ textarea_redraw(tree->textarea, x, y,
+ plot_style_fill_tree_background.
+ fill_colour,
+ &clip, &new_ctx);
}
}
@@ -2935,6 +2938,7 @@ void tree_start_edit(struct tree *tree, struct node_element *element)
{
struct node *parent;
int width, height;
+ textarea_setup ta_setup;
assert(tree != NULL);
assert(element != NULL);
@@ -2959,8 +2963,23 @@ void tree_start_edit(struct tree *tree, struct node_element *element)
if (element->type == NODE_ELEMENT_TEXT_PLUS_ICON)
width -= NODE_INSTEP;
- tree->textarea = textarea_create(width, height, TEXTAREA_DEFAULT,
- &plot_fstyle, tree_textarea_redraw_request, tree);
+ ta_setup.flags = TEXTAREA_DEFAULT;
+ ta_setup.width = width;
+ ta_setup.height = height;
+ ta_setup.pad_top = 0;
+ ta_setup.pad_right = 4;
+ ta_setup.pad_bottom = 0;
+ ta_setup.pad_left = 4;
+ ta_setup.border_width = 1;
+ ta_setup.border_col = 0x000000;
+ ta_setup.selected_text = 0xffffff;
+ ta_setup.selected_bg = 0x000000;
+ ta_setup.text = plot_fstyle;
+ ta_setup.text.foreground = 0x000000;
+ ta_setup.text.background = 0xffffff;
+
+ tree->textarea = textarea_create(&ta_setup,
+ tree_textarea_redraw_request, tree);
if (tree->textarea == NULL) {
tree_stop_edit(tree, false);
return;