Compare commits

...

4 Commits

Author SHA1 Message Date
Andy Williams 58bcf4074c Merge branch 'master' into elm_code_wrap 2018-07-22 17:08:36 +01:00
Andy Williams 2101cd686b elm_code: Update wrap to chose the right number of rows for each file line.
Unfortunately this crashes deep within evas_textgrid, not sure why yet
2018-01-15 11:42:27 +00:00
Andy Williams 90d71577ae elm_code: Correctly highlight and select multiple rows per line 2018-01-06 21:25:42 +00:00
Andy Williams 570252ef76 elm_code: Start testing wrap with 2 rows per line 2018-01-06 20:28:44 +00:00
1 changed files with 107 additions and 47 deletions

View File

@ -98,7 +98,24 @@ _elm_code_widget_efl_object_finalize(Eo *obj, Elm_Code_Widget_Data *pd)
EOLIAN static void
_elm_code_widget_class_constructor(Efl_Class *klass EINA_UNUSED)
{
}
unsigned int
_elm_code_widget_wrap_rows_get(Elm_Code_Widget *widget, Elm_Code_Line *line)
{
unsigned int cols;
if (!line)
return 1;
// TODO handle unicode and tabs
cols = elm_code_widget_columns_get(widget);
cols -= elm_obj_code_widget_text_left_gutter_width_get(widget);
if (line->length < cols)
return 1;
return (int)((double)(line->length + cols - 1) / cols);
}
void
@ -226,12 +243,13 @@ _elm_code_widget_line_in_scope(Elm_Code_Line *line, Elm_Code_Line *fromline)
return EINA_TRUE;
}
static void
_elm_code_widget_fill_line_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells,
int width, Elm_Code_Line *line)
_elm_code_widget_fill_empty_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells,
int width, Elm_Code_Line *line)
{
char *number = NULL;
int gutter, g;
int gutter;
unsigned int x = 0;
Elm_Code_Widget_Data *pd;
Elm_Code_Line *cursor_line;
@ -241,22 +259,57 @@ _elm_code_widget_fill_line_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c
if (width < gutter)
return;
cells[gutter-1].codepoint = status_icons[line->status];
cells[gutter-1].bold = 1;
cells[gutter-1].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG;
if (pd->show_line_numbers)
{
for (; x < (unsigned int) gutter - 1; x++)
{
cells[x].codepoint = 0;
cells[x].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG;
cells[x].bg = ELM_CODE_WIDGET_COLOR_GUTTER_BG;
}
}
cells[x].bold = 1;
cells[x].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG;
if (line->status == ELM_CODE_STATUS_TYPE_DEFAULT)
{
cursor_line = elm_code_file_line_get(line->file, pd->cursor_line);
if (_elm_code_widget_line_in_scope(line, cursor_line))
cells[gutter-1].bg = ELM_CODE_WIDGET_COLOR_GUTTER_SCOPE_BG;
cells[x].bg = ELM_CODE_WIDGET_COLOR_GUTTER_SCOPE_BG;
else
cells[gutter-1].bg = ELM_CODE_WIDGET_COLOR_GUTTER_BG;
cells[x].bg = ELM_CODE_WIDGET_COLOR_GUTTER_BG;
}
else
{
cells[gutter-1].bg = line->status;
cells[x].bg = line->status;
}
for (x++; x < (unsigned int) width; x++)
{
cells[x].codepoint = 0;
cells[x].bold = 0;
cells[x].bg = _elm_code_widget_status_type_get(widget, line, x - gutter + 1);
}
}
static void
_elm_code_widget_fill_line_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells,
int width, Elm_Code_Line *line)
{
char *number = NULL;
int gutter, g;
Elm_Code_Widget_Data *pd;
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
gutter = elm_code_widget_text_left_gutter_width_get(widget);
if (width < gutter)
return;
cells[gutter-1].codepoint = status_icons[line->status];
if (pd->show_line_numbers)
{
if (line->number > 0)
@ -268,11 +321,6 @@ _elm_code_widget_fill_line_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c
{
if (number)
cells[g].codepoint = *(number + g);
else
cells[g].codepoint = 0;
cells[g].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG;
cells[g].bg = ELM_CODE_WIDGET_COLOR_GUTTER_BG;
}
if (number)
@ -343,11 +391,12 @@ _elm_code_widget_fill_cursor(Elm_Code_Widget *widget, unsigned int number, int g
}
static void
_elm_code_widget_fill_selection(Elm_Code_Widget *widget, Elm_Code_Line *line, Evas_Textgrid_Cell *cells,
int gutter, int w)
_elm_code_widget_fill_selection(Elm_Code_Widget *widget, Elm_Code_Line *line, Evas_Object *grid,
int gutter, int w, unsigned int rows)
{
Elm_Code_Widget_Data *pd;
unsigned int x, start, end;
unsigned int x, r, start, end;
Evas_Textgrid_Cell *cells;
Elm_Code_Widget_Selection_Data *selection;
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
@ -369,8 +418,18 @@ _elm_code_widget_fill_selection(Elm_Code_Widget *widget, Elm_Code_Line *line, Ev
end = w;
free(selection);
cells = evas_object_textgrid_cellrow_get(grid, 0);
for (x = gutter + start - 1; x < gutter + end && x < (unsigned int) w; x++)
cells[x].bg = ELM_CODE_WIDGET_COLOR_SELECTION;
if (end == (unsigned int) w && rows > 1)
{
for (r = 1; r < rows; r++)
{
cells = evas_object_textgrid_cellrow_get(grid, r);
for (x = gutter; x < gutter + end && x < (unsigned int) w; x++)
cells[x].bg = ELM_CODE_WIDGET_COLOR_SELECTION;
}
}
}
static void
@ -378,7 +437,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line)
{
char *chr;
Eina_Unicode unichr;
unsigned int length, x, charwidth, i, w;
unsigned int length, x, charwidth, w, rows, r;
int chrpos, gutter;
Evas_Object *grid;
Evas_Textgrid_Cell *cells;
@ -394,47 +453,38 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line)
w = elm_code_widget_columns_get(widget);
grid = eina_list_nth(pd->grids, line->number - 1);
cells = evas_object_textgrid_cellrow_get(grid, 0);
rows = _elm_code_widget_wrap_rows_get(widget, line);
for (r = 0; r < rows; r++)
_elm_code_widget_fill_empty_line(widget, evas_object_textgrid_cellrow_get(grid, r), w, line);
_elm_code_widget_fill_line_gutter(widget, cells, w, line);
length = elm_code_widget_line_text_column_width_get(widget, line);
chrpos = 0;
chr = (char *)elm_code_line_text_get(line, NULL);
// TODO wrap content
for (x = gutter; x < (unsigned int) w && x < length + gutter; x+=charwidth)
{
unichr = eina_unicode_utf8_next_get(chr, &chrpos);
cells[x].codepoint = unichr;
cells[x].bold = 0;
cells[x].fg = ELM_CODE_TOKEN_TYPE_DEFAULT;
cells[x].bg = _elm_code_widget_status_type_get(widget, line, x - gutter + 1);
charwidth = 1;
if (unichr == '\t')
charwidth = elm_code_widget_text_tabwidth_at_column_get(widget, x - gutter + 1);
for (i = x + 1; i < x + charwidth && i < (unsigned int) w; i++)
{
cells[i].codepoint = 0;
cells[i].bg = _elm_code_widget_status_type_get(widget, line, i - gutter + 1);
}
_elm_code_widget_fill_whitespace(widget, unichr, &cells[x]);
}
for (; x < (unsigned int) w; x++)
{
cells[x].codepoint = 0;
cells[x].bold = 0;
cells[x].bg = _elm_code_widget_status_type_get(widget, line, x - gutter + 1);
}
_elm_code_widget_fill_line_gutter(widget, cells, w, line);
_elm_code_widget_fill_line_tokens(widget, cells, w, line);
_elm_code_widget_fill_selection(widget, line, cells, gutter, w);
_elm_code_widget_fill_selection(widget, line, grid, gutter, w, rows);
_elm_code_widget_fill_cursor(widget, line->number, gutter, w);
if (line->number < elm_code_file_lines_get(line->file))
_elm_code_widget_fill_whitespace(widget, '\n', &cells[length + gutter]);
evas_object_textgrid_update_add(grid, 0, 0, w, 1);
evas_object_textgrid_update_add(grid, 0, 0, w, rows);
}
static void
@ -1171,7 +1221,10 @@ _elm_code_widget_mouse_up_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj E
y = event->canvas.y;
hasline = _elm_code_widget_position_at_coordinates_get(widget, pd, x, y, &row, &col);
if (!hasline)
return;
{
elm_code_widget_selection_clear(widget);
return;
}
if (col <= 0)
_elm_code_widget_clicked_gutter_cb(widget, row);
@ -1911,6 +1964,9 @@ _elm_code_widget_ensure_n_grid_rows(Elm_Code_Widget *widget, int rows)
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
existing = eina_list_count(pd->grids);
if (rows == existing)
return;
// trim unneeded rows in our rendering
if (rows < existing)
{
@ -1921,12 +1977,9 @@ _elm_code_widget_ensure_n_grid_rows(Elm_Code_Widget *widget, int rows)
elm_box_unpack(pd->gridbox, grid);
pd->grids = eina_list_remove_list(pd->grids, eina_list_last(pd->grids));
}
rows = existing;
return;
}
if (rows == existing)
return;
for (i = existing; i < rows; i++)
{
grid = evas_object_textgrid_add(pd->gridbox);
@ -1956,8 +2009,9 @@ _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline)
Evas_Object *grid;
Evas_Coord ww, wh, old_width, old_height;
int w, h, cw = 0, ch = 0, gutter;
unsigned int line_width;
unsigned int line_width, rows;
Elm_Code_Widget_Data *pd;
Eina_Bool wrap = EINA_TRUE;
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
gutter = elm_obj_code_widget_text_left_gutter_width_get(widget);
@ -1984,20 +2038,26 @@ _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline)
_elm_code_widget_ensure_n_grid_rows(widget, h);
_elm_code_widget_cell_size_get(widget, &cw, &ch);
if (w*cw > ww)
if (!wrap && w*cw > ww)
ww = w*cw;
if (h*ch > wh)
wh = h*ch;
if (cw > 0 && ww/cw > w)
if (wrap || (cw > 0 && ww/cw > w))
pd->col_count = ww/cw;
else
pd->col_count = w;
EINA_LIST_FOREACH(pd->grids, item, grid)
{
evas_object_textgrid_size_set(grid, pd->col_count, 1);
evas_object_size_hint_min_set(grid, ww, ch);
int oldw, oldh;
rows = _elm_code_widget_wrap_rows_get(widget, line);
evas_object_textgrid_size_get(grid, &oldw, &oldh);
ecore_thread_main_loop_begin();
evas_object_textgrid_size_set(grid, pd->col_count, rows);
evas_object_size_hint_min_set(grid, ww, ch * rows);
ecore_thread_main_loop_end();
}
if (!newline)