Add textarea_setup struct to textarea_create API.
This commit is contained in:
parent
ac03806a50
commit
5124b8a02a
|
@ -75,6 +75,17 @@ struct textarea {
|
||||||
int vis_width; /**< Visible width, in pixels */
|
int vis_width; /**< Visible width, in pixels */
|
||||||
int vis_height; /**< Visible height, 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 */
|
char *text; /**< UTF-8 text */
|
||||||
unsigned int text_alloc; /**< Size of allocated text */
|
unsigned int text_alloc; /**< Size of allocated text */
|
||||||
unsigned int text_len; /**< Length of text, in bytes */
|
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_start; /**< Character index of sel start(inclusive) */
|
||||||
int sel_end; /**< Character index of sel end(exclusive) */
|
int sel_end; /**< Character index of sel end(exclusive) */
|
||||||
|
|
||||||
plot_font_style_t fstyle; /**< Text style */
|
|
||||||
|
|
||||||
int line_count; /**< Count of lines */
|
int line_count; /**< Count of lines */
|
||||||
#define LINE_CHUNK_SIZE 16
|
#define LINE_CHUNK_SIZE 16
|
||||||
struct line_info *lines; /**< Line info array */
|
struct line_info *lines; /**< Line info array */
|
||||||
|
@ -608,8 +617,7 @@ static bool textarea_replace_text(struct textarea *ta, unsigned int start,
|
||||||
|
|
||||||
|
|
||||||
/* exported interface, documented in textarea.h */
|
/* exported interface, documented in textarea.h */
|
||||||
struct textarea *textarea_create(int width, int height,
|
struct textarea *textarea_create(const textarea_setup *setup,
|
||||||
textarea_flags flags, const plot_font_style_t *style,
|
|
||||||
textarea_redraw_request_callback redraw_request, void *data)
|
textarea_redraw_request_callback redraw_request, void *data)
|
||||||
{
|
{
|
||||||
struct textarea *ret;
|
struct textarea *ret;
|
||||||
|
@ -627,14 +635,30 @@ struct textarea *textarea_create(int width, int height,
|
||||||
|
|
||||||
ret->redraw_request = redraw_request;
|
ret->redraw_request = redraw_request;
|
||||||
ret->data = data;
|
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_x = 0;
|
||||||
ret->scroll_y = 0;
|
ret->scroll_y = 0;
|
||||||
ret->drag_start_char = 0;
|
ret->drag_start_char = 0;
|
||||||
|
|
||||||
|
|
||||||
ret->flags = flags;
|
|
||||||
ret->text = malloc(64);
|
ret->text = malloc(64);
|
||||||
if (ret->text == NULL) {
|
if (ret->text == NULL) {
|
||||||
LOG(("malloc failed"));
|
LOG(("malloc failed"));
|
||||||
|
@ -646,11 +670,10 @@ struct textarea *textarea_create(int width, int height,
|
||||||
ret->text_len = 1;
|
ret->text_len = 1;
|
||||||
ret->text_utf8_len = 0;
|
ret->text_utf8_len = 0;
|
||||||
|
|
||||||
ret->fstyle = *style;
|
|
||||||
|
|
||||||
ret->line_height = FIXTOINT(FDIV((FMUL(FLTTOFIX(1.2),
|
ret->line_height = FIXTOINT(FDIV((FMUL(FLTTOFIX(1.2),
|
||||||
FMUL(nscss_screen_dpi,
|
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_pos.line = ret->caret_pos.char_off = 0;
|
||||||
ret->caret_x = MARGIN_LEFT;
|
ret->caret_x = MARGIN_LEFT;
|
||||||
|
|
|
@ -36,6 +36,26 @@ typedef enum textarea_flags {
|
||||||
TEXTAREA_READONLY = (1 << 2)
|
TEXTAREA_READONLY = (1 << 2)
|
||||||
} textarea_flags;
|
} textarea_flags;
|
||||||
|
|
||||||
|
typedef struct textarea_setup {
|
||||||
|
textarea_flags flags;
|
||||||
|
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
|
||||||
|
int pad_top;
|
||||||
|
int pad_right;
|
||||||
|
int pad_bottom;
|
||||||
|
int pad_left;
|
||||||
|
|
||||||
|
int border_width;
|
||||||
|
colour border_col;
|
||||||
|
|
||||||
|
colour selected_text;
|
||||||
|
colour selected_bg;
|
||||||
|
plot_font_style_t text;
|
||||||
|
|
||||||
|
} textarea_setup;
|
||||||
|
|
||||||
|
|
||||||
struct textarea;
|
struct textarea;
|
||||||
|
|
||||||
|
@ -54,8 +74,7 @@ typedef void(*textarea_redraw_request_callback)(void *data, int x, int y,
|
||||||
* \param data user specified data which will be passed to redraw callbacks
|
* \param data user specified data which will be passed to redraw callbacks
|
||||||
* \return Opaque handle for textarea or 0 on error
|
* \return Opaque handle for textarea or 0 on error
|
||||||
*/
|
*/
|
||||||
struct textarea *textarea_create(int width, int height,
|
struct textarea *textarea_create(const textarea_setup *setup,
|
||||||
textarea_flags flags, const plot_font_style_t *style,
|
|
||||||
textarea_redraw_request_callback redraw_request, void *data);
|
textarea_redraw_request_callback redraw_request, void *data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2935,6 +2935,7 @@ void tree_start_edit(struct tree *tree, struct node_element *element)
|
||||||
{
|
{
|
||||||
struct node *parent;
|
struct node *parent;
|
||||||
int width, height;
|
int width, height;
|
||||||
|
textarea_setup ta_setup;
|
||||||
|
|
||||||
assert(tree != NULL);
|
assert(tree != NULL);
|
||||||
assert(element != NULL);
|
assert(element != NULL);
|
||||||
|
@ -2959,8 +2960,23 @@ void tree_start_edit(struct tree *tree, struct node_element *element)
|
||||||
if (element->type == NODE_ELEMENT_TEXT_PLUS_ICON)
|
if (element->type == NODE_ELEMENT_TEXT_PLUS_ICON)
|
||||||
width -= NODE_INSTEP;
|
width -= NODE_INSTEP;
|
||||||
|
|
||||||
tree->textarea = textarea_create(width, height, TEXTAREA_DEFAULT,
|
ta_setup.flags = TEXTAREA_DEFAULT;
|
||||||
&plot_fstyle, tree_textarea_redraw_request, tree);
|
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) {
|
if (tree->textarea == NULL) {
|
||||||
tree_stop_edit(tree, false);
|
tree_stop_edit(tree, false);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue