From 71fa2d13c865cae5e72bdce31b1ea6bcdf481194 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 23 Feb 2015 21:52:49 +0000 Subject: [PATCH] elm_code: display a line-width marker if requested --- elm_code/src/lib/elm_code_private.h | 1 + elm_code/src/lib/elm_code_widget.c | 35 ++++++++++++++++++++++++++--- elm_code/src/lib/elm_code_widget.eo | 20 +++++++++++++++++ src/bin/editor/edi_editor.c | 3 ++- 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/elm_code/src/lib/elm_code_private.h b/elm_code/src/lib/elm_code_private.h index 854d4b6..e46a468 100644 --- a/elm_code/src/lib/elm_code_private.h +++ b/elm_code/src/lib/elm_code_private.h @@ -37,4 +37,5 @@ typedef struct unsigned int cursor_line, cursor_col; Eina_Bool editable, focussed; Eina_Bool show_line_numbers; + unsigned int line_width_marker; } Elm_Code_Widget_Data; diff --git a/elm_code/src/lib/elm_code_widget.c b/elm_code/src/lib/elm_code_widget.c index 9673c9a..134be96 100644 --- a/elm_code/src/lib/elm_code_widget.c +++ b/elm_code/src/lib/elm_code_widget.c @@ -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 _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, 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++) { 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++; } for (; x < (unsigned int) w; x++) { 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); @@ -241,7 +257,7 @@ _elm_code_widget_empty_line(Elm_Code_Widget *widget, unsigned int number) for (x = gutter; x < (unsigned int) w; x++) { 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); @@ -709,6 +725,19 @@ _elm_code_widget_line_numbers_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) 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 _elm_code_widget_cursor_position_set(Eo *obj, Elm_Code_Widget_Data *pd, unsigned int col, unsigned int line) { diff --git a/elm_code/src/lib/elm_code_widget.eo b/elm_code/src/lib/elm_code_widget.eo index 0608e81..9ee6aa4 100644 --- a/elm_code/src/lib/elm_code_widget.eo +++ b/elm_code/src/lib/elm_code_widget.eo @@ -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 */ } } + 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 { set { /*@ diff --git a/src/bin/editor/edi_editor.c b/src/bin/editor/edi_editor.c index 64924b1..4bec2a9 100644 --- a/src/bin/editor/edi_editor.c +++ b/src/bin/editor/edi_editor.c @@ -611,7 +611,8 @@ edi_editor_add(Evas_Object *parent, Edi_Mainview_Item *item) elm_code_widget_code_set(code), elm_code_widget_font_size_set(_edi_cfg->font.size), 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->entry = widget;