Hello!
While playing with some progressbars, I found myself dreaming about
some missing features... So I coded them :p
- First I added a char *label_format to struct Ewl_Progressbar, it is
set to "%3$.0lf%%" at initialization, to keep the default percentage
mode, as I changed label arguments to value, range, value/range*100,
range-value, (range-value)/range*100 (there shouldn't be anything that
could be useful missing now :p).
- ewl_progressbar_label_get: retrieves current label value
- ewl_progressbar_label_format_set: sets the default label format, so
that we don't have to call ewl_progressbar_custom_label_set at each
value update, that's a hassle less :)
- ewl_progressbar_label_format_get: do I have to explain what it's
supposed to do ;D
- ewl_progressbar_default_label_set: resets the label format to its
initial value, so "%3$.0lf%%" (maybe this name is not as good)
- some cosmetic changes (english error corrections)
- correction of default (winter) theme where the bottom of the
progressbar (the 'done' part) was not shown
Hope this is bugless (;D) and helpful...
Cheers!
--
ilLogict
Etudiant:1A, E.S.I.A.L., Nancy, France
Student: Y1, E.S.I.A.L., Nancy, France
Website: http://illogict.online.fr
E-Mail: [EMAIL PROTECTED]
ICQ: #74274856
AIM: illogict
MSN: [EMAIL PROTECTED]
Yahoo: illogict
Jabber: [EMAIL PROTECTED]
Mobile: +33 6 81921083
Message: Enlightenment DR17 oune ! Et honte à ceux qui ne sont pas d'accord !
Message: Enlightenment DR17 rocks! Shame on whoever doesn't agree!
Index: libs/ewl/data/themes/default/bits/progressbar-groups.edc
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/data/themes/default/bits/progressbar-groups.edc,v
retrieving revision 1.3
diff -u -r1.3 progressbar-groups.edc
--- libs/ewl/data/themes/default/bits/progressbar-groups.edc 1 Nov 2004 04:49:49 -0000 1.3
+++ libs/ewl/data/themes/default/bits/progressbar-groups.edc 6 Jun 2005 15:31:33 -0000
@@ -46,7 +46,7 @@
}
rel2 {
relative, 1.0 1.0;
- offset, -1 -1;
+ offset, -1 -3;
}
image {
normal, "button-up.png";
Index: libs/ewl/src/bin/ewl_test.c
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/bin/ewl_test.c,v
retrieving revision 1.8
diff -u -r1.8 ewl_test.c
--- libs/ewl/src/bin/ewl_test.c 28 May 2005 20:32:49 -0000 1.8
+++ libs/ewl/src/bin/ewl_test.c 6 Jun 2005 15:31:33 -0000
@@ -78,10 +78,10 @@
{ "Spinner", __create_spinner_test_window, "ewl_spinner_test.c" },
{ "Statusbar", __create_statusbar_test_window, "ewl_statusbar_test.c" },
{ "Table", __create_table_test_window, "ewl_table_test.c" },
- { "Textarea", __create_textarea_test_window, "ewl_textarea_test.c" },
- { "Theme", __create_theme_test_window, "ewl_theme_test.c" },
+ //{ "Textarea", __create_textarea_test_window, "ewl_textarea_test.c" },
+ //{ "Theme", __create_theme_test_window, "ewl_theme_test.c" },
{ "Tooltip", __create_tooltip_test_window, "ewl_tooltip_test.c" },
- { "Tree", __create_tree_test_window, "ewl_tree_test.c" },
+ //{ "Tree", __create_tree_test_window, "ewl_tree_test.c" },
{ 0, 0, 0 }
};
static char* tooltips[] = {
@@ -227,6 +227,7 @@
* Add the row to the tree, and setup it's alignment and
* fill.
*/
+ printf("%d\n",i);
prow[i] = ewl_tree_text_row_add( EWL_TREE (main_tree), NULL,
&(tests[i].name));
ewl_callback_append (EWL_WIDGET (prow[i]),
Index: libs/ewl/src/lib/ewl_progressbar.c
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_progressbar.c,v
retrieving revision 1.2
diff -u -r1.2 ewl_progressbar.c
--- libs/ewl/src/lib/ewl_progressbar.c 28 Mar 2005 07:04:29 -0000 1.2
+++ libs/ewl/src/lib/ewl_progressbar.c 6 Jun 2005 15:31:33 -0000
@@ -6,7 +6,7 @@
/**
* @return Returns NULL on failure, or a pointer to the new progressbar on success.
- * @brief Allocate and initialize a new progressbar
+ * @brief Allocates and initializes a new progressbar.
*/
Ewl_Widget *ewl_progressbar_new()
{
@@ -26,7 +26,7 @@
/**
* @param p: the progressbar to be initialized
* @return Returns no value.
- * @brief Initialize the progressbar to some sane starting values
+ * @brief Initializes the progressbar to some sane starting values.
*/
void ewl_progressbar_init(Ewl_Progressbar * p)
{
@@ -64,6 +64,10 @@
p->value = 0.0;
p->range = 100.0;
p->auto_label = TRUE;
+ /*
+ * Do a percentage calculation as a default label.
+ */
+ p->label_format = strdup("%3$.0lf%%");
ewl_callback_append(w, EWL_CALLBACK_CONFIGURE,
ewl_progressbar_configure_cb, NULL);
@@ -74,9 +78,9 @@
/**
* @param p: the progressbar whose value will be changed
- * @param v: the new value of the statusbar
+ * @param v: the new value of the progressbar
* @return Returns no value.
- * @brief Set the value of the progressbars location
+ * @brief Sets the value of the progressbar's location.
*/
void ewl_progressbar_value_set(Ewl_Progressbar * p, double v)
{
@@ -94,10 +98,9 @@
p->value = v;
if (p->auto_label) {
- /*
- * Do a precentage calculation as a default label.
- */
- snprintf (c, sizeof (c), "%.0lf%%", (p->value / p->range) * 100);
+ snprintf (c, sizeof (c), p->label_format, p->value, p->range,
+ (p->value / p->range) * 100, p->range - p->value,
+ ((p->range - p->value) / p->range) * 100);
ewl_text_text_set(EWL_TEXT(p->label), c);
}
@@ -110,8 +113,8 @@
/**
* @param p: the progressbars to retrieve the value
- * @return Returns 0 on failure, the value of the progressbars location on success.
- * @brief Retrieve the current value of the progressbars
+ * @return Returns 0 on failure, the value of the progressbar's location on success.
+ * @brief Retrieves the current value of the progressbar.
*/
double ewl_progressbar_value_get(Ewl_Progressbar * p)
{
@@ -123,9 +126,9 @@
/**
* @param p: the progressbar whose range will be changed
- * @param r: the new range of the statusbar
+ * @param r: the new range of the progressbar
* @return Returns no value.
- * @brief Set the range of the progressbar. Cannot be less then 1.
+ * @brief Sets the range of the progressbar. Cannot be less then 1.
*/
void ewl_progressbar_range_set (Ewl_Progressbar * p, double r)
{
@@ -147,9 +150,9 @@
}
/**
- * @param p: the progressbars to retrieve the range
- * @return Returns 0 on failure, the value of the progressbars location on success.
- * @brief Retrieve the current range of the progressbars (default 100)
+ * @param p: the progressbar to retrieve the range
+ * @return Returns 0 on failure, the value of the progressbar's location on success.
+ * @brief Retrieves the current range of the progressbars (default 100).
*/
double ewl_progressbar_range_get (Ewl_Progressbar * p)
{
@@ -161,10 +164,10 @@
/**
- * @param p: the progressbars whose text will be changed
+ * @param p: the progressbar whose text will be changed
* @param label: the new label
- * @return Returns no value
- * @brief Sets the given text on the progressbar
+ * @return Returns no value.
+ * @brief Sets the given text on the progressbar.
*/
void ewl_progressbar_label_set (Ewl_Progressbar * p, char *label)
{
@@ -180,10 +183,93 @@
}
/**
- * @param p: the progressbars whose label will be changed
+ * @param p: the progressbar to retrieve the label format
+ * @return Returns the progressbar label format on success, NULL on failure.
+ * @brief Gets the current label from a progressbar.
+ */
+
+char *ewl_progressbar_label_get (Ewl_Progressbar * p)
+{
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR_RET("p", p, NULL);
+
+ DRETURN_PTR(ewl_text_text_get(EWL_TEXT(p->label)), DLEVEL_STABLE);
+}
+
+/**
+ * @param p: the progressbar whose label format will be changed
+ * @param format_string: the new label
+ * @return Returns no value.
+ * @brief Sets the given format string on the progressbar (%lf of %lf beers so
+ * %lf%%, remaining %lf beers so %lf%%).
+ */
+void ewl_progressbar_label_format_set (Ewl_Progressbar * p,char *format_string)
+{
+ char label[PATH_MAX];
+
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR("p", p);
+
+ if (format_string) {
+ p->auto_label = TRUE;
+ p->label_format = strdup(format_string);
+ snprintf (label, PATH_MAX, format_string, p->value, p->range,
+ (p->value / p->range) * 100, p->range - p->value,
+ ((p->range - p->value) / p->range) * 100);
+ ewl_text_text_set(EWL_TEXT(p->label), label);
+ }
+
+ DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param p: the progressbar to retrieve the label format
+ * @return Returns the progressbar label format on success, NULL on failure.
+ * @brief Gets the label format from a progressbar.
+ */
+
+char *ewl_progressbar_label_format_get (Ewl_Progressbar * p)
+{
+ char *label_format = NULL;
+
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR_RET("p", p, NULL);
+
+ if (p->label_format)
+ label_format = strdup(p->label_format);
+
+ DRETURN_PTR(label_format, DLEVEL_STABLE);
+}
+
+/**
+ * @param p: the progressbar whose label will be changed
+ * @return Returns no value.
+ * @brief Sets the default label format on the progressbar (%3$.0lf%%).
+ */
+void ewl_progressbar_default_label_set (Ewl_Progressbar * p)
+{
+ char label[PATH_MAX];
+
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR("p", p);
+
+ p->auto_label = TRUE;
+ p->label_format = strdup("%3$.0lf%%");
+
+ snprintf (label, PATH_MAX, p->label_format, p->value, p->range,
+ (p->value / p->range) * 100, p->range - p->value,
+ ((p->range - p->value) / p->range) * 100);
+ ewl_text_text_set(EWL_TEXT(p->label), label);
+
+ DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param p: the progressbar whose label will be changed
* @param format_string: format string for the new label
- * @return Returns no value
- * @brief Sets the given format string on the progressbar (%lf of %lf beers)
+ * @return Returns no value.
+ * @brief Sets the given format string on the progressbar (%lf of %lf beers so
+ * %lf%%, remaining %lf beers so %lf%%).
*/
void ewl_progressbar_custom_label_set (Ewl_Progressbar * p, char *format_string)
{
@@ -195,7 +281,9 @@
p->auto_label = FALSE;
if (format_string) {
- snprintf (label, PATH_MAX, format_string, p->value, p->range);
+ snprintf (label, PATH_MAX, format_string, p->value, p->range,
+ (p->value / p->range) * 100, p->range - p->value,
+ ((p->range - p->value) / p->range) * 100);
ewl_text_text_set(EWL_TEXT(p->label), label);
}
@@ -203,9 +291,9 @@
}
/**
- * @param p: the progressbars whose label will be hidden
- * @return Returns no value
- * @brief Hides the given progressbars label
+ * @param p: the progressbar whose label will be hidden
+ * @return Returns no value.
+ * @brief Hides the given progressbar's label.
*/
void ewl_progressbar_label_hide (Ewl_Progressbar * p) {
DENTER_FUNCTION(DLEVEL_STABLE);
@@ -218,9 +306,9 @@
}
/**
- * @param p: the progressbars whose label will be shown
- * @return Returns no value
- * @brief Shows the given progressbars label
+ * @param p: the progressbar whose label will be shown
+ * @return Returns no value.
+ * @brief Shows the given progressbar's label.
*/
void ewl_progressbar_label_show (Ewl_Progressbar * p) {
DENTER_FUNCTION(DLEVEL_STABLE);
@@ -233,7 +321,7 @@
/*
- * On a configure event we need to adjust the progressbar to fit into it's new
+ * On a configure event we need to adjust the progressbar to fit into its new
* coords and position as well as move the bar to the correct size and
* position.
*/
Index: libs/ewl/src/lib/ewl_progressbar.h
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_progressbar.h,v
retrieving revision 1.3
diff -u -r1.3 ewl_progressbar.h
--- libs/ewl/src/lib/ewl_progressbar.h 17 Feb 2005 19:14:55 -0000 1.3
+++ libs/ewl/src/lib/ewl_progressbar.h 6 Jun 2005 15:31:33 -0000
@@ -34,12 +34,13 @@
*/
struct Ewl_Progressbar
{
- Ewl_Container container; /**< Inherit from Ewl_Container */
- Ewl_Widget *bar; /**< The moving bar on top */
- Ewl_Widget *label; /**< text label on the bar */
- double value; /**< current value of the progressbar */
- double range; /**< the maximum range of the progressbar */
- int auto_label; /**< flag if user is setting label or not */
+ Ewl_Container container; /**< Inherit from Ewl_Container */
+ Ewl_Widget *bar; /**< The moving bar on top */
+ Ewl_Widget *label; /**< text label on the bar */
+ double value; /**< current value of the progressbar */
+ double range; /**< the maximum range of the progressbar */
+ int auto_label; /**< flag if user is setting label or not */
+ char *label_format; /**< string corresponding to the current label format*/
};
@@ -53,6 +54,11 @@
double ewl_progressbar_range_get (Ewl_Progressbar * p);
void ewl_progressbar_label_set (Ewl_Progressbar * p, char *label);
+char *ewl_progressbar_label_get (Ewl_Progressbar * p);
+void ewl_progressbar_label_format_set (Ewl_Progressbar * p,
+ char *format_string);
+char *ewl_progressbar_label_format_get (Ewl_Progressbar * p);
+void ewl_progressbar_default_label_set (Ewl_Progressbar * p);
void ewl_progressbar_custom_label_set (Ewl_Progressbar * p,
char *format_string);