elm_code: display a line-width marker if requested

This commit is contained in:
Andy Williams 2015-02-23 21:52:49 +00:00
parent 724bf617cb
commit 71fa2d13c8
4 changed files with 55 additions and 4 deletions

View File

@ -37,4 +37,5 @@ typedef struct
unsigned int cursor_line, cursor_col; unsigned int cursor_line, cursor_col;
Eina_Bool editable, focussed; Eina_Bool editable, focussed;
Eina_Bool show_line_numbers; Eina_Bool show_line_numbers;
unsigned int line_width_marker;
} Elm_Code_Widget_Data; } Elm_Code_Widget_Data;

View File

@ -108,6 +108,22 @@ _elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int count, int start
} }
} }
static unsigned int
_elm_code_widget_status_type_get(Elm_Code_Widget *widget, Elm_Code_Status_Type set_type, unsigned int col)
{
Elm_Code_Widget_Data *pd;
pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
if (set_type != ELM_CODE_STATUS_TYPE_DEFAULT)
return set_type;
if (pd->line_width_marker == col)
return ELM_CODE_WIDGET_COLOR_GUTTER_BG;
return ELM_CODE_STATUS_TYPE_DEFAULT;
}
static void static void
_elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells,
unsigned int count, Elm_Code_Line *line) unsigned int count, Elm_Code_Line *line)
@ -203,14 +219,14 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line)
for (x = gutter; x < (unsigned int) w && x < length + gutter; x++) for (x = gutter; x < (unsigned int) w && x < length + gutter; x++)
{ {
cells[x].codepoint = *chr; cells[x].codepoint = *chr;
cells[x].bg = line->status; cells[x].bg = _elm_code_widget_status_type_get(widget, line->status, x - gutter + 1);
chr++; chr++;
} }
for (; x < (unsigned int) w; x++) for (; x < (unsigned int) w; x++)
{ {
cells[x].codepoint = 0; cells[x].codepoint = 0;
cells[x].bg = line->status; cells[x].bg = _elm_code_widget_status_type_get(widget, line->status, x - gutter + 1);
} }
_elm_code_widget_fill_line_tokens(widget, cells, w, line); _elm_code_widget_fill_line_tokens(widget, cells, w, line);
@ -241,7 +257,7 @@ _elm_code_widget_empty_line(Elm_Code_Widget *widget, unsigned int number)
for (x = gutter; x < (unsigned int) w; x++) for (x = gutter; x < (unsigned int) w; x++)
{ {
cells[x].codepoint = 0; cells[x].codepoint = 0;
cells[x].bg = ELM_CODE_STATUS_TYPE_DEFAULT; cells[x].bg = _elm_code_widget_status_type_get(widget, ELM_CODE_STATUS_TYPE_DEFAULT, x - gutter + 1);
} }
evas_object_textgrid_update_add(pd->grid, 0, number - 1, w, 1); evas_object_textgrid_update_add(pd->grid, 0, number - 1, w, 1);
@ -709,6 +725,19 @@ _elm_code_widget_line_numbers_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd)
return pd->show_line_numbers; return pd->show_line_numbers;
} }
EOLIAN static void
_elm_code_widget_line_width_marker_set(Eo *obj, Elm_Code_Widget_Data *pd, unsigned int col)
{
pd->line_width_marker = col;
_elm_code_widget_fill(obj);
}
EOLIAN static unsigned int
_elm_code_widget_line_width_marker_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd)
{
return pd->line_width_marker;
}
EOLIAN static void EOLIAN static void
_elm_code_widget_cursor_position_set(Eo *obj, Elm_Code_Widget_Data *pd, unsigned int col, unsigned int line) _elm_code_widget_cursor_position_set(Eo *obj, Elm_Code_Widget_Data *pd, unsigned int col, unsigned int line)
{ {

View File

@ -103,6 +103,26 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text)
Eina_Bool line_numbers; /*@ Whether or not line numbers (or their placeholder) should be shown */ Eina_Bool line_numbers; /*@ Whether or not line numbers (or their placeholder) should be shown */
} }
} }
line_width_marker {
set {
/*@
Set where the line width market should be shown.
Passing a non-zero value will set which line width to mark with a vertical line.
Passing 0 will hide this marker.
@ingroup Features */
}
get {
/*@
Get the position of the line width marker, any positive return indicates where the marker appears.
@ingroup Features */
}
values {
uint line_width_marker; /*@ Where to display a line width marker, if at all */
}
}
cursor_position { cursor_position {
set { set {
/*@ /*@

View File

@ -611,7 +611,8 @@ edi_editor_add(Evas_Object *parent, Edi_Mainview_Item *item)
elm_code_widget_code_set(code), elm_code_widget_code_set(code),
elm_code_widget_font_size_set(_edi_cfg->font.size), elm_code_widget_font_size_set(_edi_cfg->font.size),
elm_code_widget_editable_set(EINA_TRUE), elm_code_widget_editable_set(EINA_TRUE),
elm_code_widget_line_numbers_set(EINA_TRUE)); elm_code_widget_line_numbers_set(EINA_TRUE),
elm_code_widget_line_width_marker_set(80));
editor = calloc(1, sizeof(*editor)); editor = calloc(1, sizeof(*editor));
editor->entry = widget; editor->entry = widget;