Thanks guys, it never ceases to amaze me how responsive you lot are! I've been following the CVS changes and I like the solution.

Attached is a patch against this morning's CVS to implement the ewl_widget_part_text_set stuff. I've actually renamed the functions to: ewl_widget_appearance_part_text_set and ewl_widget_appearance_text_set, because I wanted to make the purpose a little clearer, but you guys own this stuff, so feel free to change them!

The patch works for me, but please read through it and verify my logic before using. I'm cross-compiling for an ARM box, so not using stuff like Valgrind...

----------------
Summary of patch
----------------
ewl_widget_appearance_part_text_set:
Creates a per-widget hash of part-name/text pairs. Applies the text using edje_object_part_text_set, and recalculates the preferred_inner_size as per Dan's Ewl_Label code.

ewl_widget_appearance_text_set:
calls the above with the part name obtained with ewl_theme_data_str_get(w, "textpart");

ewl_widget_realize_cb:
Iterates through the hash and reapplies any text.

ewl_label_apply:
Now uses the above functions.
----------------

Dan, you've moved the buttons over to use the label widget:
Pros: Label part of Ewl hbox layout -- full power of Ewl.
Cons: Label not in same Edje group as the button, which restricts Edje scriptability (e.g. label animating with button presses).

This patch gives an alternative with a different downside:
  button = ewl_button_new(NULL);
  ewl_widget_appearance_text_set(button, "text");
Pros: label now part of edje group -- full power of Edje
Cons: Label not part of hbox layout!

I can't see a solution which gets rid of both cons.

BTW, I've finally got my act together and I'm on IRC as bangersnmash74.

Now if only we had an edje_object_part_image_set function to let us do the same thing with icons... ;-)

--
Simon Poole
www.appliancestudio.com




Nathan Ingersoll wrote:
Yep, text should be more themeable than it is, so much to do, so little time.

Ok, a little talking on IRC with dj2 and some thinking on this over
lunch has me leaning towards doing a combination of the things we've
discussed.

I'm thinking we should resurrect ewl_label to use as we discussed with
the part text. There never was a clear distinction between what was a
label and what was text before, just single-line vs multi-line. I
think we could define a label as a widget that is completely themed
from Edje and text as a widget that is more programmatically
controlled. This would allow you to create an edje with a text part,
set the fill policy on the ewl_object to FILL, and then let the edje
theme take care of internal alignment in the area EWL hands it.

We may still want to create the ewl_widget_text_set,
ewl_widget_part_text_set API, any themed object could potentially have
text that the programmer wants to set. We're also providing other
mechanisms for the programmer to setup their own edje's so this goes
hand-in-hand with that. If we do this, the ewl_label could just use
this API for setting it's own text.

diff -urN ewl-20050616.orig/src/lib/ewl_label.c ewl-20050616/src/lib/ewl_label.c
--- ewl-20050616.orig/src/lib/ewl_label.c       2005-06-16 03:10:56.000000000 
+0100
+++ ewl-20050616/src/lib/ewl_label.c    2005-06-16 11:10:54.322794664 +0100
@@ -83,19 +83,10 @@
 ewl_label_apply(Ewl_Label *la)
 {
        Ewl_Widget *w;
-       Evas_Coord nw, nh;
 
        w = EWL_WIDGET(la);
-       if (!w->theme_object) return;
 
-       /* Should htis check be in here? 
-       if (!edje_object_part_exists(w->theme_object, "text"))
-       printf(" NO PART\n");
-       */
-       edje_object_part_text_set(w->theme_object, "text", la->text);
-       edje_object_size_min_calc(w->theme_object, &nw, &nh);
-
-       ewl_object_preferred_inner_size_set(EWL_OBJECT(la), (int)nw, (int)nh);
+       ewl_widget_appearance_part_text_set(w, "text", la->text);
 }
 
 
diff -urN ewl-20050616.orig/src/lib/ewl_widget.c 
ewl-20050616/src/lib/ewl_widget.c
--- ewl-20050616.orig/src/lib/ewl_widget.c      2005-05-20 06:02:59.000000000 
+0100
+++ ewl-20050616/src/lib/ewl_widget.c   2005-06-16 11:42:59.871066832 +0100
@@ -538,6 +538,114 @@
 }
 
 /**
+ * @param w: the widget whose text to change
+ * @param part: the theme part name whose text to change
+ * @param text: the new text to change to
+ * @return Returns no value.
+ * @brief Change the text of the given theme part of a widget
+ *
+ * Changes the text of a given Edje-define TEXT part.
+ */
+static void ewl_widget_appearance_part_text_apply(Ewl_Widget * w, char *part, 
char *text)
+{
+       Evas_Coord nw, nh;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("w", w);
+       DCHECK_PARAM_PTR("part", part);
+       DCHECK_PARAM_PTR("text", text);
+
+       if (!w->theme_object)
+               DLEAVE_FUNCTION(DLEVEL_STABLE);
+
+       /* Should htis check be in here? 
+       if (!edje_object_part_exists(w->theme_object, "text"))
+       printf(" NO PART\n");
+       */
+       edje_object_part_text_set(w->theme_object, part, text);
+       edje_object_size_min_calc(w->theme_object, &nw, &nh);
+
+       ewl_object_preferred_inner_size_set(EWL_OBJECT(w), (int)nw, (int)nh);
+       
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param w: the widget whose text to change
+ * @param part: the theme part name whose text to change
+ * @param text: the new text to change to
+ * @return Returns no value.
+ * @brief Change the text of the given theme part of a widget
+ *
+ * Changes the text of a given Edje-define TEXT part.  This is for
+ * widgets whose Edje appearance defines TEXT parts, and enables
+ * each of those text parts to be changed independently.
+ * The text value is recorded in a hash and reapplied if the theme
+ * is reloaded for this widget.
+ */
+void ewl_widget_appearance_part_text_set(Ewl_Widget * w, char *part, char 
*text)
+{
+       char *key, *value, *old_value;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("w", w);
+       DCHECK_PARAM_PTR("part", part);
+       
+       if (!(w->theme_text)) {
+               w->theme_text = ecore_hash_new(ecore_str_hash, 
ecore_str_compare);
+               ecore_hash_set_free_key(free);
+               ecore_hash_set_free_value(free);
+       }
+
+       old_value = ecore_hash_get(w->theme_text, part);
+       
+       if (old_value && text && !strcmp(value, text))
+               DLEAVE_FUNCTION(DLEVEL_STABLE);
+
+       /*
+        * What should be the default if you enter NULL? A blank string?
+        * Revert to the text specified in the Edje? Use blank for now.
+        */
+       value = strdup( text ? text : "" );
+
+       if (old_value) key = part;
+       else key = strdup(part);
+
+       ecore_hash_set(w->theme_text, key, value);
+
+       ewl_widget_appearance_part_text_apply(w, key, value);
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param w: the widget whose text to change
+ * @param part: the theme part name whose text to change
+ * @param text: the new text to change to
+ * @return Returns no value.
+ * @brief Change the text of the given theme part of a widget
+ *
+ * Changes the text of an Edje-define TEXT part.  This is for
+ * widgets whose Edje appearance defines a TEXT part, and identifies
+ * it with with a data item called "/WIDGET/textpart".
+ * The text value is recorded in a hash and reapplied if the theme
+ * is reloaded for this widget.
+ */
+void ewl_widget_appearance_text_set(Ewl_Widget * w, char *text)
+{
+       char *part;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("w", w);
+
+       part = ewl_theme_data_str_get(w, "textpart");
+       if (part) {
+               ewl_widget_appearance_part_text_set(w, part, text);
+               FREE(part);
+       }
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
  * @param w: the widget to update the appearance
  * @param state: the new state of the widget
  * @return Returns no value.
@@ -1171,6 +1279,19 @@
         * Set up the theme object on the widgets evas
         */
        if (w->theme_object) {
+               /*
+                * Apply any text overrides
+                */
+               if (w->theme_text) {
+                       char *key;
+                       Ecore_List *keys = ecore_hash_keys(w->theme_text);
+
+                       ecore_list_goto_first(keys);
+                       while (key = (char *)ecore_list_next(keys)) {
+                               ewl_widget_appearance_part_text_apply(w, key, 
ecore_hash_get(w->theme_text, key));
+                       }
+               }
+                       
                if (w->bit_state)
                        edje_object_signal_emit(w->theme_object, w->bit_state, 
"EWL");
 
diff -urN ewl-20050616.orig/src/lib/ewl_widget.h 
ewl-20050616/src/lib/ewl_widget.h
--- ewl-20050616.orig/src/lib/ewl_widget.h      2005-05-13 04:26:13.000000000 
+0100
+++ ewl-20050616/src/lib/ewl_widget.h   2005-06-16 11:41:36.290772968 +0100
@@ -59,6 +59,7 @@
        int             layer; /**< Current layer of widget on canvas */
 
        Ecore_Hash       *theme; /**< Overriding theme settings of this widget 
*/
+       Ecore_Hash       *theme_text; /**< Overriding text in this widget's 
theme */
        Ecore_Hash       *data; /**< Arbitrary data attached to this widget */
 };
 
@@ -158,6 +159,16 @@
 char           *ewl_widget_appearance_single_get(Ewl_Widget * w);
 
 /*
+ * Change the text of the given theme part of a widget.
+ */
+void           *ewl_widget_appearance_part_text_set(Ewl_Widget * w, char 
*part, char *text);
+
+/*
+ * Change the text of the theme-defined theme part of a widget.
+ */
+void           *ewl_widget_appearance_text_set(Ewl_Widget * w, char *text);
+
+/*
  * Append to the inherited string 
  */
 void            ewl_widget_inherit(Ewl_Widget *widget, char *type);

Reply via email to