Compare commits
4 Commits
master
...
devs/ajwil
Author | SHA1 | Date |
---|---|---|
Andy Williams | 58bcf4074c | |
Andy Williams | 2101cd686b | |
Andy Williams | 90d71577ae | |
Andy Williams | 570252ef76 |
|
@ -98,7 +98,24 @@ _elm_code_widget_efl_object_finalize(Eo *obj, Elm_Code_Widget_Data *pd)
|
||||||
EOLIAN static void
|
EOLIAN static void
|
||||||
_elm_code_widget_class_constructor(Efl_Class *klass EINA_UNUSED)
|
_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
|
void
|
||||||
|
@ -226,12 +243,13 @@ _elm_code_widget_line_in_scope(Elm_Code_Line *line, Elm_Code_Line *fromline)
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_elm_code_widget_fill_line_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells,
|
_elm_code_widget_fill_empty_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells,
|
||||||
int width, Elm_Code_Line *line)
|
int width, Elm_Code_Line *line)
|
||||||
{
|
{
|
||||||
char *number = NULL;
|
int gutter;
|
||||||
int gutter, g;
|
unsigned int x = 0;
|
||||||
Elm_Code_Widget_Data *pd;
|
Elm_Code_Widget_Data *pd;
|
||||||
Elm_Code_Line *cursor_line;
|
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)
|
if (width < gutter)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cells[gutter-1].codepoint = status_icons[line->status];
|
if (pd->show_line_numbers)
|
||||||
cells[gutter-1].bold = 1;
|
{
|
||||||
cells[gutter-1].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG;
|
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)
|
if (line->status == ELM_CODE_STATUS_TYPE_DEFAULT)
|
||||||
{
|
{
|
||||||
cursor_line = elm_code_file_line_get(line->file, pd->cursor_line);
|
cursor_line = elm_code_file_line_get(line->file, pd->cursor_line);
|
||||||
if (_elm_code_widget_line_in_scope(line, 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
|
else
|
||||||
cells[gutter-1].bg = ELM_CODE_WIDGET_COLOR_GUTTER_BG;
|
cells[x].bg = ELM_CODE_WIDGET_COLOR_GUTTER_BG;
|
||||||
}
|
}
|
||||||
else
|
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 (pd->show_line_numbers)
|
||||||
{
|
{
|
||||||
if (line->number > 0)
|
if (line->number > 0)
|
||||||
|
@ -268,11 +321,6 @@ _elm_code_widget_fill_line_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c
|
||||||
{
|
{
|
||||||
if (number)
|
if (number)
|
||||||
cells[g].codepoint = *(number + g);
|
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)
|
if (number)
|
||||||
|
@ -343,11 +391,12 @@ _elm_code_widget_fill_cursor(Elm_Code_Widget *widget, unsigned int number, int g
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_elm_code_widget_fill_selection(Elm_Code_Widget *widget, Elm_Code_Line *line, Evas_Textgrid_Cell *cells,
|
_elm_code_widget_fill_selection(Elm_Code_Widget *widget, Elm_Code_Line *line, Evas_Object *grid,
|
||||||
int gutter, int w)
|
int gutter, int w, unsigned int rows)
|
||||||
{
|
{
|
||||||
Elm_Code_Widget_Data *pd;
|
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;
|
Elm_Code_Widget_Selection_Data *selection;
|
||||||
|
|
||||||
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
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;
|
end = w;
|
||||||
free(selection);
|
free(selection);
|
||||||
|
|
||||||
|
cells = evas_object_textgrid_cellrow_get(grid, 0);
|
||||||
for (x = gutter + start - 1; x < gutter + end && x < (unsigned int) w; x++)
|
for (x = gutter + start - 1; x < gutter + end && x < (unsigned int) w; x++)
|
||||||
cells[x].bg = ELM_CODE_WIDGET_COLOR_SELECTION;
|
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
|
static void
|
||||||
|
@ -378,7 +437,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line)
|
||||||
{
|
{
|
||||||
char *chr;
|
char *chr;
|
||||||
Eina_Unicode unichr;
|
Eina_Unicode unichr;
|
||||||
unsigned int length, x, charwidth, i, w;
|
unsigned int length, x, charwidth, w, rows, r;
|
||||||
int chrpos, gutter;
|
int chrpos, gutter;
|
||||||
Evas_Object *grid;
|
Evas_Object *grid;
|
||||||
Evas_Textgrid_Cell *cells;
|
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);
|
w = elm_code_widget_columns_get(widget);
|
||||||
grid = eina_list_nth(pd->grids, line->number - 1);
|
grid = eina_list_nth(pd->grids, line->number - 1);
|
||||||
cells = evas_object_textgrid_cellrow_get(grid, 0);
|
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);
|
length = elm_code_widget_line_text_column_width_get(widget, line);
|
||||||
chrpos = 0;
|
chrpos = 0;
|
||||||
chr = (char *)elm_code_line_text_get(line, NULL);
|
chr = (char *)elm_code_line_text_get(line, NULL);
|
||||||
|
// TODO wrap content
|
||||||
for (x = gutter; x < (unsigned int) w && x < length + gutter; x+=charwidth)
|
for (x = gutter; x < (unsigned int) w && x < length + gutter; x+=charwidth)
|
||||||
{
|
{
|
||||||
unichr = eina_unicode_utf8_next_get(chr, &chrpos);
|
unichr = eina_unicode_utf8_next_get(chr, &chrpos);
|
||||||
|
|
||||||
cells[x].codepoint = unichr;
|
cells[x].codepoint = unichr;
|
||||||
cells[x].bold = 0;
|
|
||||||
cells[x].fg = ELM_CODE_TOKEN_TYPE_DEFAULT;
|
cells[x].fg = ELM_CODE_TOKEN_TYPE_DEFAULT;
|
||||||
cells[x].bg = _elm_code_widget_status_type_get(widget, line, x - gutter + 1);
|
|
||||||
|
|
||||||
charwidth = 1;
|
charwidth = 1;
|
||||||
if (unichr == '\t')
|
if (unichr == '\t')
|
||||||
charwidth = elm_code_widget_text_tabwidth_at_column_get(widget, x - gutter + 1);
|
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]);
|
_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_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);
|
_elm_code_widget_fill_cursor(widget, line->number, gutter, w);
|
||||||
if (line->number < elm_code_file_lines_get(line->file))
|
if (line->number < elm_code_file_lines_get(line->file))
|
||||||
_elm_code_widget_fill_whitespace(widget, '\n', &cells[length + gutter]);
|
_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
|
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;
|
y = event->canvas.y;
|
||||||
hasline = _elm_code_widget_position_at_coordinates_get(widget, pd, x, y, &row, &col);
|
hasline = _elm_code_widget_position_at_coordinates_get(widget, pd, x, y, &row, &col);
|
||||||
if (!hasline)
|
if (!hasline)
|
||||||
return;
|
{
|
||||||
|
elm_code_widget_selection_clear(widget);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (col <= 0)
|
if (col <= 0)
|
||||||
_elm_code_widget_clicked_gutter_cb(widget, row);
|
_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);
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
||||||
existing = eina_list_count(pd->grids);
|
existing = eina_list_count(pd->grids);
|
||||||
|
|
||||||
|
if (rows == existing)
|
||||||
|
return;
|
||||||
|
|
||||||
// trim unneeded rows in our rendering
|
// trim unneeded rows in our rendering
|
||||||
if (rows < existing)
|
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);
|
elm_box_unpack(pd->gridbox, grid);
|
||||||
pd->grids = eina_list_remove_list(pd->grids, eina_list_last(pd->grids));
|
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++)
|
for (i = existing; i < rows; i++)
|
||||||
{
|
{
|
||||||
grid = evas_object_textgrid_add(pd->gridbox);
|
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_Object *grid;
|
||||||
Evas_Coord ww, wh, old_width, old_height;
|
Evas_Coord ww, wh, old_width, old_height;
|
||||||
int w, h, cw = 0, ch = 0, gutter;
|
int w, h, cw = 0, ch = 0, gutter;
|
||||||
unsigned int line_width;
|
unsigned int line_width, rows;
|
||||||
Elm_Code_Widget_Data *pd;
|
Elm_Code_Widget_Data *pd;
|
||||||
|
Eina_Bool wrap = EINA_TRUE;
|
||||||
|
|
||||||
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
||||||
gutter = elm_obj_code_widget_text_left_gutter_width_get(widget);
|
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_ensure_n_grid_rows(widget, h);
|
||||||
_elm_code_widget_cell_size_get(widget, &cw, &ch);
|
_elm_code_widget_cell_size_get(widget, &cw, &ch);
|
||||||
if (w*cw > ww)
|
if (!wrap && w*cw > ww)
|
||||||
ww = w*cw;
|
ww = w*cw;
|
||||||
if (h*ch > wh)
|
if (h*ch > wh)
|
||||||
wh = h*ch;
|
wh = h*ch;
|
||||||
|
|
||||||
if (cw > 0 && ww/cw > w)
|
if (wrap || (cw > 0 && ww/cw > w))
|
||||||
pd->col_count = ww/cw;
|
pd->col_count = ww/cw;
|
||||||
else
|
else
|
||||||
pd->col_count = w;
|
pd->col_count = w;
|
||||||
|
|
||||||
EINA_LIST_FOREACH(pd->grids, item, grid)
|
EINA_LIST_FOREACH(pd->grids, item, grid)
|
||||||
{
|
{
|
||||||
evas_object_textgrid_size_set(grid, pd->col_count, 1);
|
int oldw, oldh;
|
||||||
evas_object_size_hint_min_set(grid, ww, ch);
|
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)
|
if (!newline)
|
||||||
|
|
Loading…
Reference in New Issue