forked from enlightenment/edi
Add proper gravity control when lines are being added to the widget.
Most useful will be (0.0, 1.0) which will cause the display to act like 'tail'.
This commit is contained in:
parent
a0938ce656
commit
ae12a8406c
|
@ -8,9 +8,11 @@
|
|||
typedef struct
|
||||
{
|
||||
Elm_Code *code;
|
||||
Evas_Object *grid;
|
||||
Evas_Object *grid, *scroller;
|
||||
|
||||
Evas_Font_Size font_size;
|
||||
double gravity_x, gravity_y;
|
||||
|
||||
unsigned int cursor_line, cursor_col;
|
||||
Eina_Bool cursor_move_vetoed;
|
||||
Eina_Bool editable, focussed;
|
||||
|
@ -47,12 +49,26 @@ _elm_code_widget_class_constructor(Eo_Class *klass EINA_UNUSED)
|
|||
|
||||
}
|
||||
|
||||
static void
|
||||
_elm_code_widget_scroll_by(Elm_Code_Widget *widget, int by_x, int by_y)
|
||||
{
|
||||
Elm_Code_Widget_Data *pd;
|
||||
Evas_Coord x, y, w, h;
|
||||
|
||||
pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
||||
|
||||
elm_scroller_region_get(pd->scroller, &x, &y, &w, &h);
|
||||
x += by_x;
|
||||
y += by_y;
|
||||
elm_scroller_region_show(pd->scroller, x, y, w, h);
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_elm_code_widget_resize(Elm_Code_Widget *widget)
|
||||
{
|
||||
Elm_Code_Line *line;
|
||||
Eina_List *item;
|
||||
Evas_Coord ww, wh;
|
||||
Evas_Coord ww, wh, old_width, old_height;
|
||||
int w, h, cw, ch;
|
||||
Elm_Code_Widget_Data *pd;
|
||||
|
||||
|
@ -63,6 +79,8 @@ _elm_code_widget_resize(Elm_Code_Widget *widget)
|
|||
|
||||
evas_object_geometry_get(widget, NULL, NULL, &ww, &wh);
|
||||
evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch);
|
||||
old_width = ww;
|
||||
old_height = wh;
|
||||
|
||||
w = 0;
|
||||
h = elm_code_file_lines_get(pd->code->file);
|
||||
|
@ -78,6 +96,11 @@ _elm_code_widget_resize(Elm_Code_Widget *widget)
|
|||
evas_object_textgrid_size_set(pd->grid, ww/cw+1, wh/ch+1);
|
||||
evas_object_size_hint_min_set(pd->grid, w*cw, h*ch);
|
||||
|
||||
if (pd->gravity_x == 1.0 || pd->gravity_y == 1.0)
|
||||
_elm_code_widget_scroll_by(widget,
|
||||
(pd->gravity_x == 1.0 && ww > old_width) ? ww - old_width : 0,
|
||||
(pd->gravity_y == 1.0 && wh > old_height) ? wh - old_height : 0);
|
||||
|
||||
return h > 0 && w > 0;
|
||||
}
|
||||
|
||||
|
@ -519,6 +542,20 @@ _elm_code_widget_code_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd)
|
|||
return pd->code;
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_elm_code_widget_gravity_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, double x, double y)
|
||||
{
|
||||
pd->gravity_x = x;
|
||||
pd->gravity_y = y;
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_elm_code_widget_gravity_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, double *x, double *y)
|
||||
{
|
||||
*x = pd->gravity_x;
|
||||
*y = pd->gravity_y;
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_elm_code_widget_editable_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool editable)
|
||||
{
|
||||
|
@ -584,6 +621,7 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd)
|
|||
evas_object_size_hint_align_set(scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
evas_object_show(scroller);
|
||||
elm_box_pack_end(obj, scroller);
|
||||
pd->scroller = scroller;
|
||||
|
||||
grid = evas_object_textgrid_add(obj);
|
||||
evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
|
|
|
@ -37,6 +37,27 @@ class Elm_Code_Widget (Elm_Box, Elm_Interface_Scrollable,
|
|||
Evas_Font_Size font_size; /*@ The font size of the widgget */
|
||||
}
|
||||
}
|
||||
gravity {
|
||||
set {
|
||||
/*@
|
||||
Set how this widget's scroller should respond to new lines being added.
|
||||
|
||||
An x value of 0.0 will maintain the distance from the left edge, 1.0 will ensure the rightmost edge (of the longest line) is respected
|
||||
With 0.0 for y the view will keep it's position relative to the top whereas 1.0 will scroll downward as lines are added.
|
||||
|
||||
@ingroup Layout */
|
||||
}
|
||||
get {
|
||||
/*@
|
||||
Get the current x and y gravity of the widget's scroller
|
||||
|
||||
@ingroup Layout */
|
||||
}
|
||||
values {
|
||||
double x; /*@ The horizontal value of the scroller gravity - valid values are 0.0 and 1.0 */
|
||||
double y; /*@ The vertical gravity of the widget's scroller - valid values are 0.0 and 1.0 */
|
||||
}
|
||||
}
|
||||
editable {
|
||||
set {
|
||||
/*@
|
||||
|
|
|
@ -17,6 +17,14 @@ Evas_Font_Size _elm_code_widget_font_size_get(Eo *obj, Elm_Code_Widget_Data *pd)
|
|||
|
||||
EOAPI EO_FUNC_BODY(elm_code_widget_font_size_get, Evas_Font_Size, 0);
|
||||
|
||||
void _elm_code_widget_gravity_set(Eo *obj, Elm_Code_Widget_Data *pd, double x, double y);
|
||||
|
||||
EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_gravity_set, EO_FUNC_CALL(x, y), double x, double y);
|
||||
|
||||
void _elm_code_widget_gravity_get(Eo *obj, Elm_Code_Widget_Data *pd, double *x, double *y);
|
||||
|
||||
EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_gravity_get, EO_FUNC_CALL(x, y), double *x, double *y);
|
||||
|
||||
void _elm_code_widget_editable_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool editable);
|
||||
|
||||
EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_editable_set, EO_FUNC_CALL(editable), Eina_Bool editable);
|
||||
|
@ -46,6 +54,8 @@ static Eo_Op_Description _elm_code_widget_op_desc[] = {
|
|||
EO_OP_FUNC(elm_code_widget_code_get, _elm_code_widget_code_get, "Get the underlying code object we are rendering"),
|
||||
EO_OP_FUNC(elm_code_widget_font_size_set, _elm_code_widget_font_size_set, "Set the font size that this widget uses, the font will always be a system monospaced font"),
|
||||
EO_OP_FUNC(elm_code_widget_font_size_get, _elm_code_widget_font_size_get, "Get the font size currently in use"),
|
||||
EO_OP_FUNC(elm_code_widget_gravity_set, _elm_code_widget_gravity_set, "Set how this widget's scroller should respond to new lines being added."),
|
||||
EO_OP_FUNC(elm_code_widget_gravity_get, _elm_code_widget_gravity_get, "Get the current x and y gravity of the widget's scroller"),
|
||||
EO_OP_FUNC(elm_code_widget_editable_set, _elm_code_widget_editable_set, "Set whether this widget allows editing"),
|
||||
EO_OP_FUNC(elm_code_widget_editable_get, _elm_code_widget_editable_get, "Get the current editable state of this widget"),
|
||||
EO_OP_SENTINEL
|
||||
|
|
|
@ -59,6 +59,34 @@ EOAPI void elm_code_widget_font_size_set(Evas_Font_Size font_size);
|
|||
*/
|
||||
EOAPI Evas_Font_Size elm_code_widget_font_size_get(void);
|
||||
|
||||
/**
|
||||
*
|
||||
* Set how this widget's scroller should respond to new lines being added.
|
||||
*
|
||||
* An x value of 0.0 will maintain the distance from the left edge, 1.0
|
||||
will ensure the rightmost edge (of the longest line) is respected
|
||||
* With 0.0 for y the view will keep it's position relative to the top whereas 1.0 will scroll downward as lines are added.
|
||||
*
|
||||
* @ingroup Layout
|
||||
*
|
||||
* @param[in] x The horizontal value of the scroller gravity - valid values are 0.0 and 1.0
|
||||
* @param[in] y The vertical gravity of the widget's scroller - valid values are 0.0 and 1.0
|
||||
*
|
||||
*/
|
||||
EOAPI void elm_code_widget_gravity_set(double x, double y);
|
||||
|
||||
/**
|
||||
*
|
||||
* Get the current x and y gravity of the widget's scroller
|
||||
*
|
||||
* @ingroup Layout
|
||||
*
|
||||
* @param[out] x The horizontal value of the scroller gravity, currently ignored
|
||||
* @param[out] y The vertical gravity of the widget's scroller - valid values are 0.0 and 1.0
|
||||
*
|
||||
*/
|
||||
EOAPI void elm_code_widget_gravity_get(double *x, double *y);
|
||||
|
||||
/**
|
||||
*
|
||||
* Set whether this widget allows editing
|
||||
|
|
|
@ -343,8 +343,9 @@ void edi_testpanel_add(Evas_Object *parent)
|
|||
|
||||
widget = eo_add(ELM_CODE_WIDGET_CLASS, parent);
|
||||
eo_do(widget,
|
||||
elm_code_widget_code_set(code);
|
||||
elm_code_widget_font_size_set(_edi_cfg->font.size));
|
||||
elm_code_widget_code_set(code),
|
||||
elm_code_widget_font_size_set(_edi_cfg->font.size),
|
||||
elm_code_widget_gravity_set(0.0, 1.0));
|
||||
|
||||
evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
|
|
|
@ -46,8 +46,9 @@ void edi_logpanel_add(Evas_Object *parent)
|
|||
code = elm_code_create();
|
||||
widget = eo_add(ELM_CODE_WIDGET_CLASS, parent);
|
||||
eo_do(widget,
|
||||
elm_code_widget_code_set(code);
|
||||
elm_code_widget_font_size_set(_edi_cfg->font.size));
|
||||
elm_code_widget_code_set(code),
|
||||
elm_code_widget_font_size_set(_edi_cfg->font.size),
|
||||
elm_code_widget_gravity_set(0.0, 1.0));
|
||||
evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
evas_object_show(widget);
|
||||
|
|
Loading…
Reference in New Issue