From 1d2d15bbf844a44276e737c42654ea0a4cbb7e75 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Wed, 21 Aug 2019 09:32:09 -0400 Subject: [PATCH] efl_ui/scrollable_content: add scrollable_text property this creates a label with a scroller and manages sizing calcs note that efl_ui_text cannot be used here because its sizing calc model is incompatible with efl Reviewed-by: Marcel Hollerbach Differential Revision: https://phab.enlightenment.org/D9676 --- .../efl_ui_widget_scrollable_content.c | 51 ++++++++++++++++++- .../efl_ui_widget_scrollable_content.eo | 26 +++++++++- 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/src/lib/elementary/efl_ui_widget_scrollable_content.c b/src/lib/elementary/efl_ui_widget_scrollable_content.c index 03672fb7a5..7fee7f670d 100644 --- a/src/lib/elementary/efl_ui_widget_scrollable_content.c +++ b/src/lib/elementary/efl_ui_widget_scrollable_content.c @@ -11,6 +11,7 @@ typedef struct Efl_Ui_Widget_Scrollable_Content_Data { Eo *scroller; + Eo *label; Eina_Bool did_group_calc : 1; } Efl_Ui_Widget_Scrollable_Content_Data; @@ -31,6 +32,12 @@ _scroller_sizing_eval(Eo *obj, Efl_Ui_Widget_Scrollable_Content_Data *pd, size.w = (obj_min.w > min_size.w) ? obj_min.w : min_size.w; size.h = (obj_min.h > min_size.h) ? obj_min.h : min_size.h; + if (pd->label) + { + scr_min.w = (obj_min.w > scr_min.w) ? obj_min.w : scr_min.w; + scr_min.h = (obj_min.h > scr_min.h) ? obj_min.h : scr_min.h; + } + Eina_Size2D new_min = obj_min; if ((max_size.w == -1) && (max_size.h == -1)) @@ -107,10 +114,20 @@ _sizing_eval(Eo *obj, Efl_Ui_Widget_Scrollable_Content_Data *pd) ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd); Evas_Coord obj_minw = -1, obj_minh = -1; Evas_Coord scr_minw = -1, scr_minh = -1; + Eina_Size2D text_min; //Calculate popup's min size including scroller's min size { - efl_ui_scrollable_match_content_set(pd->scroller, EINA_TRUE, EINA_TRUE); + if (pd->label) + { + elm_label_line_wrap_set(pd->label, ELM_WRAP_NONE); + efl_canvas_group_calculate(pd->label); + text_min = efl_gfx_hint_size_combined_min_get(pd->label); + elm_label_line_wrap_set(pd->label, ELM_WRAP_MIXED); + efl_canvas_group_calculate(pd->label); + } + + efl_ui_scrollable_match_content_set(pd->scroller, !pd->label, EINA_TRUE); efl_canvas_group_calculate(pd->scroller); elm_coords_finger_size_adjust(1, &scr_minw, 1, &scr_minh); @@ -127,6 +144,8 @@ _sizing_eval(Eo *obj, Efl_Ui_Widget_Scrollable_Content_Data *pd) edje_object_size_min_restricted_calc (wd->resize_obj, &obj_minw, &obj_minh, obj_minw, obj_minh); } + if (pd->label) + scr_minw = text_min.w; _scroller_sizing_eval(obj, pd, EINA_SIZE2D(obj_minw, obj_minh), EINA_SIZE2D(scr_minw, scr_minh)); } @@ -155,6 +174,17 @@ _scroller_setup(Eo *obj, Efl_Ui_Widget_Scrollable_Content_Data *pd) efl_content_set(obj, pd->scroller); } +static void +_label_setup(Eo *obj EINA_UNUSED, Efl_Ui_Widget_Scrollable_Content_Data *pd) +{ + // TODO: Change internal component to Efl.Ui.Widget + pd->label = elm_label_add(pd->scroller); + //elm_widget_element_update(obj, pd->label, PART_NAME_TEXT); + efl_gfx_hint_weight_set(pd->label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + efl_wref_add(pd->label, &pd->label); + efl_content_set(pd->scroller, pd->label); +} + EOLIAN static Eina_Bool _efl_ui_widget_scrollable_content_scrollable_content_did_group_calc_get(const Eo *obj EINA_UNUSED, Efl_Ui_Widget_Scrollable_Content_Data *pd) { @@ -179,6 +209,25 @@ _efl_ui_widget_scrollable_content_scrollable_content_get(const Eo *obj EINA_UNUS return efl_content_get(pd->scroller); } +EOLIAN static void +_efl_ui_widget_scrollable_content_scrollable_text_set(Eo *obj, Efl_Ui_Widget_Scrollable_Content_Data *pd, const char *text) +{ + if (!pd->scroller) + _scroller_setup(obj, pd); + if (!pd->label) + _label_setup(obj, pd); + elm_object_text_set(pd->label, text); + //efl_text_set(pd->label, text); + efl_canvas_group_change(obj); +} + +EOLIAN static const char * +_efl_ui_widget_scrollable_content_scrollable_text_get(const Eo *obj EINA_UNUSED, Efl_Ui_Widget_Scrollable_Content_Data *pd) +{ + return elm_object_text_get(pd->label); + //return efl_text_get(pd->label); +} + EOLIAN static void _efl_ui_widget_scrollable_content_efl_object_destructor(Eo *obj, Efl_Ui_Widget_Scrollable_Content_Data *pd) { diff --git a/src/lib/elementary/efl_ui_widget_scrollable_content.eo b/src/lib/elementary/efl_ui_widget_scrollable_content.eo index d110f3eaa9..2bdf4fed07 100644 --- a/src/lib/elementary/efl_ui_widget_scrollable_content.eo +++ b/src/lib/elementary/efl_ui_widget_scrollable_content.eo @@ -18,11 +18,11 @@ mixin @beta Efl.Ui.Widget.Scrollable_Content requires Efl.Object implementation after the super call to determine whether the internal scroller has performed sizing calculations. - The @.optimal_size,calc event will have been emitted during the super call if + The optimal_size,calc event will have been emitted during the super call if this method returns $true. In the case that this returns $true, it's likely that the widget should be completing - its internal sizing calculations from the @.optimal_size,calc callback using + its internal sizing calculations from the optimal_size,calc callback using `efl_canvas_group_calculate(efl_super(ev->object, EFL_UI_WIDGET_SCROLLABLE_CONTENT_MIXIN));` @@ -44,6 +44,28 @@ mixin @beta Efl.Ui.Widget.Scrollable_Content requires Efl.Object content: Efl.Canvas.Object; [[The content object.]] } } + @property scrollable_text { + set { + [[Sets the text string to be displayed by the given text object. + The text will be scrollable depending on its size relative to the + object's geometry. + + See also @.scrollable_text.get. + ]] + } + get { + [[Retrieves the text string currently being displayed by the given + text object. + + Do not free() the return value. + + See also @.scrollable_text.set. + ]] + } + values { + text: string; [[Text string to display on it.]] + } + } } events { optimal_size,calc: Eina.Size2D; [[The optimal size for the widget based on scrollable content.]]