Elementary: toggle documentation.
authorgastal <gastal@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 25 Jul 2011 17:00:28 +0000 (17:00 +0000)
committergastal <gastal@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 25 Jul 2011 17:00:28 +0000 (17:00 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/elementary@61699 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

doc/Makefile.am
doc/examples.dox
doc/index.doxy
doc/widgets/Makefile.am
doc/widgets/widget_preview_toggle.c [new file with mode: 0644]
src/examples/Makefile.am
src/examples/toggle_example_01.c [new file with mode: 0644]
src/lib/Elementary.h.in
src/lib/elm_toggle.c

index f6aeb68..f9a2082 100644 (file)
@@ -50,7 +50,8 @@ WGT_PREVIEW = \
        anchorblock:preview-00.png:widget_preview_anchorblock:100:30 \
        pager:preview-00.png:widget_preview_pager:100:100 \
        separator:preview-00.png:widget_preview_separator:10:80 \
-       radio:preview-00.png:widget_preview_radio:60:20
+       radio:preview-00.png:widget_preview_radio:60:20 \
+       toggle:preview-00.png:widget_preview_toggle:150:30
 
 widget-build:
        @$(MAKE) -C widgets
index 963fd2b..c725f43 100644 (file)
  */
 
 /**
+ * @page tutorial_toggle Toggle example
+ * @dontinclude toggle_example_01.c
+ *
+ * In this example we'll create 2 toggle widgets. The first will have an icon
+ * and the state names will be the default "on"/"off", it will also change the
+ * value of a variable directly. The second won't have a icon, the state names
+ * will be "Enabled"/"Disabled", it will  start "Enabled" and it won't set the
+ * value of a variable.
+ *
+ * We start with the usual includes and prototype for callback which will be
+ * implemented and detailed later on:
+ * @until _cb2
+ *
+ * We then declare a static global variable(the one whose value will be changed
+ * by the first toggle):
+ * @until static
+ *
+ * We now have to create our window and all that usual stuff:
+ * @until show(bx)
+ *
+ * The creation of a toggle is no more complicated than that of any other
+ * widget:
+ * @until add
+ *
+ * For our first toggle we don't set the states labels so they will stay the
+ * default, however we do set a label for the toggle, an icon and the variable
+ * whose value it should change:
+ * @until show
+ *
+ * We also set the callback that will be called when the toggles value changes:
+ * @until smart_callback
+ *
+ * For our second toggle it important to note that we set the states labels,
+ * don't set an icon or variable, but set the initial state to
+ * EINA_TRUE("Enabled"):
+ * @until show
+ *
+ * For the second toggle we will use a different callback:
+ * @until smart_callback
+ *
+ * We then ask the main loop to start:
+ * @until ELM_MAIN
+ *
+ * The callback for our first toggle will look the value of @p val and print it:
+ * @until }
+ *
+ * For our second callback we need to do a little bit more, since the second
+ * toggle doesn't change the value of a variable we have to ask it what its
+ * state is:
+ * @until }
+ *
+ * This example will look like this:
+ *
+ * @image html screenshots/toggle_example_01.png
+ * @image latex screenshots/toggle_example_01.eps width=\textwidth
+ *
+ * @example toggle_example_01.c
+ */
+
+/**
  * @page bg_example_01_c bg_example_01.c
  * @include bg_example_01.c
  * @example bg_example_01.c
index 313c13b..74da13d 100644 (file)
  * @li @ref Spinner
  * @li @ref Thumb
  * @li @ref Toggle
+ *
+ * @image html img/widget/toggle/preview-00.png
+ * @image latex img/widget/toggle/preview-00.eps
  * @li @ref Toolbar
  * @li @ref Tooltips
  * @li @ref Video
index 4b07797..a725d7f 100644 (file)
@@ -65,7 +65,8 @@ widget_preview_anchorblock \
 widget_preview_flip \
 widget_preview_pager \
 widget_preview_separator \
-widget_preview_radio
+widget_preview_radio \
+widget_preview_toggle
 
 LDADD = $(top_builddir)/src/lib/libelementary.la @ELEMENTARY_EWEATHER_LIBS@ @ELEMENTARY_EDBUS_LIBS@ @ELEMENTARY_EFREET_LIBS@ @ELEMENTARY_LIBS@ @EIO_LIBS@ @my_libs@
 
@@ -113,5 +114,6 @@ EXTRA_DIST = \
        widget_preview_pager.c \
        widget_preview_separator.c \
        widget_preview_radio.c \
+       widget_preview_toggle.c \
        widget_preview_tmpl_foot.c \
        widget_preview_tmpl_head.c
diff --git a/doc/widgets/widget_preview_toggle.c b/doc/widgets/widget_preview_toggle.c
new file mode 100644 (file)
index 0000000..a26930a
--- /dev/null
@@ -0,0 +1,11 @@
+#include "widget_preview_tmpl_head.c"
+
+Evas_Object *o = elm_toggle_add(win);
+evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+elm_win_resize_object_add(win, o);
+evas_object_show(o);
+
+elm_object_text_set(o, "toggle");
+elm_toggle_states_labels_set(o, "on", "off");
+
+#include "widget_preview_tmpl_foot.c"
index 9c1f429..48b9662 100644 (file)
@@ -148,7 +148,8 @@ pkglib_PROGRAMS += \
        index_example_02 \
        pager_example_01 \
        separator_example_01 \
-       radio_example_01
+       radio_example_01 \
+       toggle_example_01
 
 # This variable will hold the list of screenshots that will be made
 # by "make screenshots". Each item in the list is of the form:
@@ -192,7 +193,8 @@ SCREENSHOTS = \
        ctxpopup_example_01:ctxpopup_example_01.png:0.0 \
        pager_example_01:pager_example_01.png:0.0 \
        separator_example_01:separator_example_01.png:0.0 \
-       radio_example_01:radio_example_01.png:0.0
+       radio_example_01:radio_example_01.png:0.0 \
+       toggle_example_01:toggle_example_01.png:0.0
 
 HTML_SS_DIR=$(top_builddir)/doc/html/screenshots
 LATEX_SS_DIR=$(top_builddir)/doc/latex/screenshots
diff --git a/src/examples/toggle_example_01.c b/src/examples/toggle_example_01.c
new file mode 100644 (file)
index 0000000..d7d9277
--- /dev/null
@@ -0,0 +1,75 @@
+//Compile with:
+//gcc -g `pkg-config --cflags --libs elementary` toggle_example_01.c -o toggle_example_01
+
+#include <Elementary.h>
+#ifdef HAVE_CONFIG_H
+# include "elementary_config.h"
+#endif
+
+static void _cb(void *data, Evas_Object *obj, void *event_info);
+static void _cb2(void *data, Evas_Object *obj, void *event_info);
+
+static Eina_Bool val = EINA_FALSE;
+
+EAPI int
+elm_main(int argc, char **argv)
+{
+   Evas_Object *win, *bg, *bx, *toggle, *ic;
+
+   win = elm_win_add(NULL, "toggle", ELM_WIN_BASIC);
+   elm_win_title_set(win, "toggle");
+   elm_win_autodel_set(win, EINA_TRUE);
+   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
+
+   bg = elm_bg_add(win);
+   elm_win_resize_object_add(win, bg);
+   evas_object_show(bg);
+
+   bx = elm_box_add(win);
+   elm_box_horizontal_set(bx, EINA_FALSE);
+   evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   elm_win_resize_object_add(win, bx);
+   evas_object_show(bx);
+
+   toggle = elm_toggle_add(win);
+   elm_object_text_set(toggle, "Toggle 1");
+   ic = elm_icon_add(win);
+   elm_icon_standard_set(ic, "home");
+   elm_toggle_icon_set(toggle, ic);
+   elm_toggle_state_pointer_set(toggle, &val);
+   elm_box_pack_end(bx, toggle);
+   evas_object_size_hint_weight_set(toggle, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_align_set(toggle, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   evas_object_show(toggle);
+   evas_object_smart_callback_add(toggle, "changed", _cb, NULL);
+
+   toggle = elm_toggle_add(win);
+   elm_object_text_set(toggle, "Toggle 2");
+   elm_toggle_states_labels_set(toggle, "Enabled", "Disabled");
+   elm_toggle_state_set(toggle, EINA_TRUE);
+   elm_box_pack_end(bx, toggle);
+   evas_object_size_hint_weight_set(toggle, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_align_set(toggle, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   evas_object_show(toggle);
+   evas_object_smart_callback_add(toggle, "changed", _cb2, NULL);
+
+   evas_object_show(win);
+
+   elm_run();
+
+   return 0;
+}
+ELM_MAIN()
+
+static void
+_cb(void *data, Evas_Object *obj, void *event_info)
+{
+   printf("val is now: %s\n", val ? "true" : "false");
+}
+
+static void
+_cb2(void *data, Evas_Object *obj, void *event_info)
+{
+   printf("toggle2's state is now: %s\n", elm_toggle_state_get(obj) ? "true" : "false");
+}
\ No newline at end of file
index ac1d6f6..66f2ca6 100644 (file)
@@ -4155,22 +4155,121 @@ extern "C" {
     * @}
     */
 
-   /* toggle */
+   /**
+    * @defgroup Toggle
+    *
+    * @image html img/widget/toggle/preview-00.png
+    * @image latex img/widget/toggle/preview-00.eps
+    *
+    * @brief A toggle is a slider which can be used to toggle between
+    * two values.  It has two states: on and off.
+    *
+    * Signals that you can add callbacks for are:
+    * @li "changed" - Whenever the toggle value has been changed.  Is not called
+    *                 until the toggle is released by the cursor (assuming it
+    *                 has been triggered by the cursor in the first place).
+    *
+    * @ref tutorial_toggle show how to use a toggle.
+    * @{
+    */
+   /**
+    * @brief Add a toggle to @p parent.
+    *
+    * @param parent The parent object
+    *
+    * @return The toggle object
+    */
    EAPI Evas_Object *elm_toggle_add(Evas_Object *parent) EINA_ARG_NONNULL(1);
+   /**
+    * @brief Sets the label to be displayed with the toggle.
+    *
+    * @param obj The toggle object
+    * @param label The label to be displayed
+    *
+    * @deprecated use elm_object_text_set() instead.
+    */
    EINA_DEPRECATED EAPI void         elm_toggle_label_set(Evas_Object *obj, const char *label) EINA_ARG_NONNULL(1);
+   /**
+    * @brief Gets the label of the toggle
+    *
+    * @param obj  toggle object
+    * @return The label of the toggle
+    *
+    * @deprecated use elm_object_text_get() instead.
+    */
    EINA_DEPRECATED EAPI const char  *elm_toggle_label_get(const Evas_Object *obj) EINA_ARG_NONNULL(1);
+   /**
+    * @brief Set the icon used for the toggle
+    *
+    * @param obj The toggle object
+    * @param icon The icon object for the button
+    *
+    * Once the icon object is set, a previously set one will be deleted
+    * If you want to keep that old content object, use the
+    * elm_toggle_icon_unset() function.
+    */
    EAPI void         elm_toggle_icon_set(Evas_Object *obj, Evas_Object *icon) EINA_ARG_NONNULL(1);
+   /**
+    * @brief Get the icon used for the toggle
+    *
+    * @param obj The toggle object
+    * @return The icon object that is being used
+    *
+    * Return the icon object which is set for this widget.
+    *
+    * @see elm_toggle_icon_set()
+    */
    EAPI Evas_Object *elm_toggle_icon_get(const Evas_Object *obj) EINA_ARG_NONNULL(1);
+   /**
+    * @brief Unset the icon used for the toggle
+    *
+    * @param obj The toggle object
+    * @return The icon object that was being used
+    *
+    * Unparent and return the icon object which was set for this widget.
+    *
+    * @see elm_toggle_icon_set()
+    */
    EAPI Evas_Object *elm_toggle_icon_unset(Evas_Object *obj) EINA_ARG_NONNULL(1);
+   /**
+    * @brief Sets the labels to be associated with the on and off states of the toggle.
+    *
+    * @param obj The toggle object
+    * @param onlabel The label displayed when the toggle is in the "on" state
+    * @param offlabel The label displayed when the toggle is in the "off" state
+    */
    EAPI void         elm_toggle_states_labels_set(Evas_Object *obj, const char *onlabel, const char *offlabel) EINA_ARG_NONNULL(1);
+   /**
+    * @brief Gets the labels associated with the on and off states of the toggle.
+    *
+    * @param obj The toggle object
+    * @param onlabel A char** to place the onlabel of @p obj into
+    * @param offlabel A char** to place the offlabel of @p obj into
+    */
    EAPI void         elm_toggle_states_labels_get(const Evas_Object *obj, const char **onlabel, const char **offlabel) EINA_ARG_NONNULL(1);
+   /**
+    * @brief Sets the state of the toggle to @p state.
+    *
+    * @param obj The toggle object
+    * @param state The state of @p obj
+    */
    EAPI void         elm_toggle_state_set(Evas_Object *obj, Eina_Bool state) EINA_ARG_NONNULL(1);
+   /**
+    * @brief Gets the state of the toggle to @p state.
+    *
+    * @param obj The toggle object
+    * @return The state of @p obj
+    */
    EAPI Eina_Bool    elm_toggle_state_get(const Evas_Object *obj) EINA_ARG_NONNULL(1);
+   /**
+    * @brief Sets the state pointer of the toggle to @p statep.
+    *
+    * @param obj The toggle object
+    * @param statep The state pointer of @p obj
+    */
    EAPI void         elm_toggle_state_pointer_set(Evas_Object *obj, Eina_Bool *statep) EINA_ARG_NONNULL(1);
-   /* smart callbacks called:
-    * "changed" - Whenever the toggle value has been changed.  Is not called
-    *             until the toggle is released by the cursor (assuming it has been triggered
-    *             by the cursor in the first place).
+   /**
+    * @}
     */
 
    /**
index 33b09fe..41e8457 100644 (file)
@@ -1,19 +1,6 @@
 #include <Elementary.h>
 #include "elm_priv.h"
 
-/**
- * @defgroup Toggle
- *
- * A toggle is a slider which can be used to toggle between
- * two values.  It has two states: on and off.
- *
- * Signals that you can add callbacks for are:
- *
- * "changed" - Whenever the toggle value has been changed.  Is not called until
- *             the toggle is released by the cursor (assuming it has been
- *             triggered by the cursor in the first place).
- */
-
 typedef struct _Widget_Data Widget_Data;
 
 struct _Widget_Data
@@ -228,15 +215,6 @@ _elm_toggle_label_get(const Evas_Object *obj, const char *item)
    return wd->label;
 }
 
-/**
- * Add a toggle to @p parent.
- *
- * @param parent The parent object
- *
- * @return The toggle object
- *
- * @ingroup Toggle
- */
 EAPI Evas_Object *
 elm_toggle_add(Evas_Object *parent)
 {
@@ -283,48 +261,18 @@ elm_toggle_add(Evas_Object *parent)
    return obj;
 }
 
-/**
- * Sets the label to be displayed with the toggle.
- *
- * @param obj The toggle object
- * @param label The label to be displayed
- *
- * @ingroup Toggle
- * @deprecate use elm_object_text_* instead.
- */
 EAPI void
 elm_toggle_label_set(Evas_Object *obj, const char *label)
 {
    _elm_toggle_label_set(obj, NULL, label);
 }
 
-/**
- * Gets the label of the toggle
- *
- * @param obj  toggleeee object
- * @return The label of the toggle
- *
- * @ingroup Toggle
- * @deprecate use elm_object_text_* instead.
- */
 EAPI const char *
 elm_toggle_label_get(const Evas_Object *obj)
 {
    return _elm_toggle_label_get(obj, NULL);
 }
 
-/**
- * Set the icon used for the toggle
- *
- * Once the icon object is set, a previously set one will be deleted
- * If you want to keep that old content object, use the
- * elm_toggle_icon_unset() function.
- *
- * @param obj The toggle object
- * @param icon The icon object for the button
- *
- * @ingroup Toggle
- */
 EAPI void
 elm_toggle_icon_set(Evas_Object *obj, Evas_Object *icon)
 {
@@ -346,16 +294,6 @@ elm_toggle_icon_set(Evas_Object *obj, Evas_Object *icon)
    _sizing_eval(obj);
 }
 
-/**
- * Get the icon used for the toggle
- *
- * Return the icon object which is set for this widget.
- *
- * @param obj The toggle object
- * @return The icon object that is being used
- *
- * @ingroup Toggle
- */
 EAPI Evas_Object *
 elm_toggle_icon_get(const Evas_Object *obj)
 {
@@ -365,16 +303,6 @@ elm_toggle_icon_get(const Evas_Object *obj)
    return wd->icon;
 }
 
-/**
- * Unset the icon used for the toggle
- *
- * Unparent and return the icon object which was set for this widget.
- *
- * @param obj The toggle object
- * @return The icon object that was being used
- *
- * @ingroup Toggle
- */
 EAPI Evas_Object *
 elm_toggle_icon_unset(Evas_Object *obj)
 {
@@ -389,15 +317,6 @@ elm_toggle_icon_unset(Evas_Object *obj)
    return icon;
 }
 
-/**
- * Sets the labels to be associated with the on and off states of the toggle.
- *
- * @param obj The toggle object
- * @param onlabel The label displayed when the toggle is in the "on" state
- * @param offlabel The label displayed when the toggle is in the "off" state
- *
- * @ingroup Toggle
- */
 EAPI void
 elm_toggle_states_labels_set(Evas_Object *obj, const char *onlabel, const char *offlabel)
 {
@@ -411,16 +330,6 @@ elm_toggle_states_labels_set(Evas_Object *obj, const char *onlabel, const char *
    _sizing_eval(obj);
 }
 
-
-/**
- * Gets the labels associated with the on and off states of the toggle.
- *
- * @param obj The toggle object
- * @param onlabel A char** to place the onlabel of @p obj into
- * @param offlabel A char** to place the offlabel of @p obj into
- *
- * @ingroup Toggle
- */
 EAPI void
 elm_toggle_states_labels_get(const Evas_Object *obj, const char **onlabel, const char **offlabel)
 {
@@ -433,14 +342,6 @@ elm_toggle_states_labels_get(const Evas_Object *obj, const char **onlabel, const
    if (offlabel) *offlabel = wd->offtext;
 }
 
-/**
- * Sets the state of the toggle to @p state.
- *
- * @param obj The toggle object
- * @param state The state of @p obj
- *
- * @ingroup Toggle
- */
 EAPI void
 elm_toggle_state_set(Evas_Object *obj, Eina_Bool state)
 {
@@ -458,14 +359,6 @@ elm_toggle_state_set(Evas_Object *obj, Eina_Bool state)
      }
 }
 
-/**
- * Gets the state of the toggle to @p state.
- *
- * @param obj The toggle object
- * @return The state of @p obj
- *
- * @ingroup Toggle
- */
 EAPI Eina_Bool
 elm_toggle_state_get(const Evas_Object *obj)
 {
@@ -475,14 +368,6 @@ elm_toggle_state_get(const Evas_Object *obj)
    return wd->state;
 }
 
-/**
- * Sets the state pointer of the toggle to @p statep.
- *
- * @param obj The toggle object
- * @param statep The state pointer of @p obj
- *
- * @ingroup Toggle
- */
 EAPI void
 elm_toggle_state_pointer_set(Evas_Object *obj, Eina_Bool *statep)
 {