Ui text scroller: add usage of a guide
authorDaniel Hirt <hirt.danny@gmail.com>
Mon, 12 Nov 2018 13:09:56 +0000 (15:09 +0200)
committerHermet Park <hermetpark@gmail.com>
Wed, 5 Dec 2018 05:43:46 +0000 (14:43 +0900)
src/lib/elementary/efl_ui_internal_text_scroller.c
src/lib/elementary/efl_ui_internal_text_scroller.eo
src/lib/elementary/efl_ui_text.c

index bda295a..fa63a9d 100644 (file)
@@ -29,7 +29,8 @@
 
 typedef struct _Efl_Ui_Internal_Text_Scroller_Data
 {
-   Efl_Canvas_Text *content;
+   Efl_Canvas_Text *text_obj;
+   Efl_Ui_Table *text_table;
    Eo *smanager;
 
    Efl_Ui_Text_Scroller_Mode mode;
@@ -75,9 +76,9 @@ _efl_ui_internal_text_scroller_elm_layout_sizing_eval(Eo *obj,
 
    ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
 
-   if (sd->content)
+   if (sd->text_obj)
      {
-        efl_gfx_size_hint_weight_get(sd->content, &xw, &yw);
+        efl_gfx_size_hint_weight_get(sd->text_table, &xw, &yw);
      }
 
    if (psd->smanager)
@@ -87,17 +88,21 @@ _efl_ui_internal_text_scroller_elm_layout_sizing_eval(Eo *obj,
 
    edje_object_size_min_calc(wd->resize_obj, &vmw, &vmh);
 
-   if (sd->content)
+   if (sd->text_obj)
      {
         Eina_Size2D fsz = EINA_SIZE2D(0, 0);
         Eina_Size2D sz = EINA_SIZE2D(0, 0);
 
-        sz = efl_gfx_entity_size_get(sd->content);
-        efl_event_freeze(sd->content);
-        efl_gfx_entity_size_set(sd->content, view.size);
-        efl_canvas_text_size_formatted_get(sd->content, &fsz.w, &fsz.h);
-        efl_gfx_entity_size_set(sd->content, sz);
-        efl_event_thaw(sd->content);
+        sz = efl_gfx_entity_size_get(sd->text_table);
+        efl_event_freeze(sd->text_table);
+        efl_event_freeze(sd->text_obj);
+        efl_gfx_entity_size_set(sd->text_table, view.size);
+        efl_gfx_entity_size_set(sd->text_obj, view.size);
+        efl_canvas_text_size_formatted_get(sd->text_obj, &fsz.w, &fsz.h);
+        efl_gfx_entity_size_set(sd->text_table, sz);
+        efl_gfx_entity_size_set(sd->text_obj, sz);
+        efl_event_thaw(sd->text_obj);
+        efl_event_thaw(sd->text_table);
 
 
         if (sd->mode == EFL_UI_TEXT_SCROLLER_MODE_SINGLELINE)
@@ -118,7 +123,7 @@ _efl_ui_internal_text_scroller_elm_layout_sizing_eval(Eo *obj,
           }
 
         // FIXME: should be restricted_min?
-        efl_gfx_entity_size_set(sd->content, fsz);
+        efl_gfx_entity_size_set(sd->text_table, fsz);
         efl_gfx_size_hint_min_set(obj, size);
         efl_gfx_size_hint_max_set(obj, EINA_SIZE2D(-1, size.h));
      }
@@ -131,6 +136,7 @@ _efl_ui_internal_text_scroller_efl_object_finalize(Eo *obj,
    obj = efl_finalize(efl_super(obj, MY_CLASS));
    efl_ui_scrollbar_bar_mode_set(obj,
          EFL_UI_SCROLLBAR_MODE_OFF, EFL_UI_SCROLLBAR_MODE_OFF);
+   efl_content_set(obj, sd->text_table);
 
    return obj;
 }
@@ -143,12 +149,19 @@ _efl_ui_internal_text_scroller_efl_object_destructor(Eo *obj,
 }
 
 EOLIAN static void
-_efl_ui_internal_text_scroller_text_object_set(Eo *obj,
+_efl_ui_internal_text_scroller_initialize(Eo *obj,
                                        Efl_Ui_Internal_Text_Scroller_Data *sd,
-                                       Efl_Canvas_Text *text_obj)
+                                       Efl_Canvas_Text *text_obj,
+                                       Efl_Ui_Table *text_table)
 {
-   sd->content = text_obj;
-   efl_content_set(obj, text_obj);
+   if (efl_finalized_get(obj))
+     {
+        ERR("Can only be called on construction");
+        return;
+     }
+
+   sd->text_obj = text_obj;
+   sd->text_table = text_table;
 }
 
 EOLIAN static void
index 7058626..47624e4 100644 (file)
@@ -7,17 +7,14 @@ enum Efl.Ui.Text_Scroller_Mode
 
 class Efl.Ui.Internal_Text_Scroller (Efl.Ui.Scroller)
 {
-   [[Efl ui text scroller class]]
+   [[Internal-usage text scroller class.
+
+     This class is a special scroller that evaluates its size based on the
+     $Efl.Canvas.Text object it holds. On initialization the object is meant
+     to be passed along a container (so that other objects such as
+     a "guide hint" text object are store in such container.
+   ]]
    methods {
-      @property text_object {
-         [[The Efl.Canvas.Text content of this scroller]]
-         set {
-            [[Sets the given text object as the content of this scroller]]
-         }
-         values {
-            text_obj: Efl.Canvas.Text @nullable;
-         }
-      }
       @property scroller_mode {
          [[Mode of operation for the scroller]]
          set {
@@ -36,6 +33,16 @@ class Efl.Ui.Internal_Text_Scroller (Efl.Ui.Scroller)
             clip: Efl.Object;
          }
       }
+      initialize {
+         [[The Efl.Canvas.Text content of this scroller.
+           This should be called upon constructing the object.
+         ]]
+         params {
+            text_obj: Efl.Canvas.Text @nullable; [[The text object to query]]
+            text_table: Efl.Ui.Table @nullable; [[The table container of
+               the $text_obj]]
+         }
+      }
    }
    implements {
       Efl.Object.constructor;
index 5af9e75..5d65791 100644 (file)
@@ -33,6 +33,8 @@ struct _Efl_Ui_Text_Data
    Evas_Object                          *mgf_clip;
    Evas_Object                          *mgf_proxy;
    Eo                                   *text_obj;
+   Eo                                   *text_guide_obj;
+   Eo                                   *text_table;
    Eo                                   *pan;
    Eo                                   *scroller;
    Eo                                   *manager;
@@ -831,10 +833,9 @@ _cursor_geometry_recalc(Evas_Object *obj)
    edje_object_size_min_restricted_calc(sd->cursor, &cw, NULL, cw, 0);
    evas_object_geometry_get(sd->entry_edje, &x, &y, &w, &h);
    evas_object_geometry_get(
-         edje_object_part_swallow_get(sd->entry_edje, "efl.text"),
+         sd->text_obj,
          &x2, &y2, &w2, &h2);
-   cx = cx + x - x2;
-   cy = cy + y - y2;
+
    efl_ui_scrollable_scroll(sd->scroller, EINA_RECT(cx, cy, cw, ch), EINA_FALSE);
 
 }
@@ -946,7 +947,7 @@ _efl_ui_text_efl_ui_focus_object_on_focus_update(Eo *obj, Efl_Ui_Text_Data *sd)
      }
    else
      {
-        Eo *sw = edje_object_part_swallow_get(sd->entry_edje, "efl.text");
+        Eo *sw = sd->text_obj;
 
         _edje_signal_emit(sd, "efl,action,unfocus", "efl");
         if (sd->scroll)
@@ -1970,6 +1971,20 @@ _cb_deleted(void *data EINA_UNUSED, const Efl_Event *ev)
 
 }
 
+static void
+_update_guide_text(Eo *obj EINA_UNUSED, Efl_Ui_Text_Data *sd)
+{
+   const char *txt;
+   Eina_Bool show_guide;
+
+   txt = efl_text_get(sd->text_obj);
+
+   show_guide = (!txt || (txt[0] == '\0'));
+
+   efl_gfx_entity_visible_set(sd->text_guide_obj, show_guide);
+
+}
+
 EOLIAN static Eo *
 _efl_ui_text_efl_object_constructor(Eo *obj, Efl_Ui_Text_Data *sd)
 {
@@ -1985,6 +2000,8 @@ _efl_ui_text_efl_object_constructor(Eo *obj, Efl_Ui_Text_Data *sd)
 
    text_obj = efl_add(EFL_UI_INTERNAL_TEXT_INTERACTIVE_CLASS, obj);
    sd->text_obj = text_obj;
+   sd->text_guide_obj = efl_add(EFL_CANVAS_TEXT_CLASS, obj);
+   sd->text_table = efl_add(EFL_UI_TABLE_CLASS, obj);
    efl_composite_attach(obj, text_obj);
 
    sd->entry_edje = wd->resize_obj;
@@ -2032,9 +2049,17 @@ _efl_ui_text_efl_object_finalize(Eo *obj,
    efl_text_normal_color_set(sd->text_obj, 255, 255, 255, 255);
    sd->single_line = !efl_text_multiline_get(sd->text_obj);
 
-   sd->item_fallback_factory = efl_add(EFL_UI_TEXT_FACTORY_FALLBACK_CLASS, obj);
+   efl_text_set(sd->text_obj, "");
+   efl_pack_table(sd->text_table, sd->text_obj, 0, 0, 1, 1);
+   efl_pack_table(sd->text_table, sd->text_guide_obj, 0, 0, 1, 1);
+
+   //edje_object_part_swallow(sd->entry_edje, "efl.text", sd->text_obj);
+   //edje_object_part_swallow(sd->entry_edje, "efl.text_guide", sd->text_guide_obj);
+   edje_object_part_swallow(sd->entry_edje, "efl.text", sd->text_table);
+
+   _update_guide_text(obj, sd);
 
-   edje_object_part_swallow(sd->entry_edje, "efl.text", sd->text_obj);
+   sd->item_fallback_factory = efl_add(EFL_UI_TEXT_FACTORY_FALLBACK_CLASS, obj);
 
    evas_object_size_hint_weight_set
       (sd->entry_edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@@ -2441,14 +2466,12 @@ _efl_ui_text_scrollable_set(Eo *obj EINA_UNUSED, Efl_Ui_Text_Data *sd, Eina_Bool
 
    if (scroll)
      {
-        efl_ref(sd->text_obj);
-        sd->scroller = efl_add(EFL_UI_INTERNAL_TEXT_SCROLLER_CLASS, obj);
-        efl_ui_scrollbar_bar_mode_set(sd->scroller, EFL_UI_SCROLLBAR_MODE_AUTO, EFL_UI_SCROLLBAR_MODE_AUTO);
-        efl_content_set(sd->scroller, sd->text_obj);
-
         edje_object_part_swallow(sd->entry_edje, "efl.text", NULL);
+        sd->scroller = efl_add(EFL_UI_INTERNAL_TEXT_SCROLLER_CLASS, obj,
+              efl_ui_internal_text_scroller_initialize(efl_added,
+                 sd->text_obj, sd->text_table));
+        efl_ui_scrollbar_bar_mode_set(sd->scroller, EFL_UI_SCROLLBAR_MODE_AUTO, EFL_UI_SCROLLBAR_MODE_AUTO);
         edje_object_part_swallow(sd->entry_edje, "efl.text", sd->scroller);
-        efl_ui_internal_text_scroller_text_object_set(sd->scroller, sd->text_obj);
         evas_object_clip_set(sd->cursor,
               efl_ui_internal_text_scroller_viewport_clip_get(sd->scroller));
         efl_event_callback_add(sd->scroller, EFL_GFX_ENTITY_EVENT_RESIZE,
@@ -2457,8 +2480,7 @@ _efl_ui_text_scrollable_set(Eo *obj EINA_UNUSED, Efl_Ui_Text_Data *sd, Eina_Bool
    else
      {
         efl_content_set(sd->scroller, NULL);
-        edje_object_part_swallow(sd->entry_edje, "efl.text", sd->text_obj);
-        efl_unref(sd->text_obj);
+        edje_object_part_swallow(sd->entry_edje, "efl.text", sd->text_table);
         efl_del(sd->scroller);
         sd->scroller = NULL;
      }
@@ -3258,7 +3280,7 @@ _decoration_create(Eo *obj, Efl_Ui_Text_Data *sd,
    evas_object_smart_member_add(ret, sd->entry_edje);
    if (above)
      {
-        evas_object_stack_above(ret, sd->text_obj);
+        evas_object_stack_above(ret, sd->text_table);
      }
    else
      {
@@ -3758,6 +3780,7 @@ _efl_ui_text_changed_cb(void *data, const Efl_Event *event EINA_UNUSED)
    EFL_UI_TEXT_DATA_GET(data, sd);
    sd->text_changed = EINA_TRUE;
    sd->cursor_update = EINA_TRUE;
+   _update_guide_text(data, sd);
    elm_layout_sizing_eval(data);
    _decoration_defer(data);
 }
@@ -3770,6 +3793,7 @@ _efl_ui_text_changed_user_cb(void *data, const Efl_Event *event)
    if (efl_invalidated_get(event->object)) return;
    EFL_UI_TEXT_DATA_GET(obj, sd);
    sd->text_changed = EINA_TRUE;
+   _update_guide_text(data, sd);
    elm_layout_sizing_eval(obj);
    _decoration_defer_all(obj);
 }