summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGustavo Lima Chaves <glima@profusion.mobi>2011-06-22 14:52:05 +0000
committerGustavo Lima Chaves <glima@profusion.mobi>2011-06-22 14:52:05 +0000
commit7389a8d699e10df22d3ebbaea9c9af3039b12f32 (patch)
treeccce23ff8526a92e276b04b43671b9d947c0aa27 /src
parent9f328203be4cc9ccf15bd19f26ed740c9bfc3ea6 (diff)
downloadelementary-7389a8d699e10df22d3ebbaea9c9af3039b12f32.tar.gz
[elementary] Example for top level functions.
SVN revision: 60595
Diffstat (limited to 'src')
-rw-r--r--src/examples/Makefile.am8
-rw-r--r--src/examples/general_funcs_example.c194
-rw-r--r--src/lib/Elementary.h.in21
3 files changed, 221 insertions, 2 deletions
diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am
index 53896fdd9..094d1038d 100644
--- a/src/examples/Makefile.am
+++ b/src/examples/Makefile.am
@@ -9,6 +9,8 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/src/lib \
-I$(top_builddir)/src/lib \
-DPACKAGE_DATA_DIR="\"$(datadir)/elementary\"" \
+-DPACKAGE_BIN_DIR=\"$(bindir)\" \
+-DPACKAGE_LIB_DIR=\"$(libdir)\" \
@ELEMENTARY_EDBUS_CFLAGS@ \
@ELEMENTARY_EFREET_CFLAGS@ \
@ELEMENTARY_ETHUMB_CFLAGS@ \
@@ -28,7 +30,8 @@ SRCS = \
transit_example_04.c \
bg_example_01.c \
bg_example_02.c \
- bg_example_03.c
+ bg_example_03.c \
+ general_funcs_example.c
pkglib_PROGRAMS =
@@ -48,7 +51,8 @@ pkglib_PROGRAMS += \
transit_example_04 \
bg_example_01 \
bg_example_02 \
- bg_example_03
+ bg_example_03 \
+ general_funcs_example
# This variable will hold the list of screenshots that will be made
# by "make screenshots". Each item in the list is of the form:
diff --git a/src/examples/general_funcs_example.c b/src/examples/general_funcs_example.c
new file mode 100644
index 000000000..b7e509fae
--- /dev/null
+++ b/src/examples/general_funcs_example.c
@@ -0,0 +1,194 @@
+/* Compile with:
+ * gcc -g `pkg-config --cflags --libs elementary` general_funcs_example.c -o general_funcs_example
+ */
+
+#include <Elementary.h>
+
+#ifdef HAVE_CONFIG_H
+# include "elementary_config.h"
+#else
+# define __UNUSED__
+# define PACKAGE_BIN_DIR "/usr/bin"
+# define PACKAGE_LIB_DIR "/usr/lib"
+# define PACKAGE_DATA_DIR "/usr/share/elementary"
+#endif
+
+#define WIDTH 300
+#define HEIGHT 300
+
+struct test_data
+{
+ Evas_Object *btn;
+ Eina_Bool btn_enabled;
+ Eina_Bool btn_gets_focus;
+};
+
+struct test_data d = {NULL, EINA_TRUE, EINA_TRUE};
+
+static void
+_btn_enabled_cb(void *data __UNUSED__,
+ Evas_Object *obj __UNUSED__,
+ void *event __UNUSED__)
+{
+ elm_object_disabled_set(d.btn, !d.btn_enabled);
+}
+
+static void
+/* focus callback */
+_btn_focus_cb(void *data __UNUSED__,
+ Evas_Object *obj __UNUSED__,
+ void *event __UNUSED__)
+{
+ elm_object_focus(d.btn);
+}
+
+static void
+/* unfocus callback */
+_btn_unfocus_cb(void *data __UNUSED__,
+ Evas_Object *obj __UNUSED__,
+ void *event __UNUSED__)
+{
+ elm_object_unfocus(d.btn);
+}
+
+static void
+/* focus allow callback */
+_btn_focus_allow_cb(void *data __UNUSED__,
+ Evas_Object *obj __UNUSED__,
+ void *event __UNUSED__)
+{
+ elm_object_focus_allow_set(d.btn, d.btn_gets_focus);
+}
+
+static void /* scaling callback */
+_btn_scale_cb(void *data __UNUSED__,
+ Evas_Object *obj,
+ void *event __UNUSED__)
+{
+ elm_object_scale_set(d.btn, elm_slider_value_get(obj));
+}
+
+int
+elm_main(int argc __UNUSED__,
+ char **argv __UNUSED__)
+{
+ int h;
+ Evas_Object *win, *bg, *box, *frame, *check, *b, *slider;
+
+ /* tell elm about our app so it can figure out where to get files */
+ elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
+ elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
+ elm_app_compile_lib_dir_set(PACKAGE_LIB_DIR);
+ elm_app_info_set(elm_main, "elementary", "images/logo.png");
+
+ fprintf(stdout, "prefix was set to: %s\n", elm_app_prefix_dir_get());
+ fprintf(stdout, "data directory is: %s\n", elm_app_data_dir_get());
+ fprintf(stdout, "library directory is: %s\n", elm_app_lib_dir_get());
+ fprintf(stdout, "locale directory is: %s\n", elm_app_locale_dir_get());
+
+ win = elm_win_add(NULL, "top-level-funcs-example", ELM_WIN_BASIC);
+ elm_win_title_set(win, "Elementary Top-level Functions Example");
+
+ /* by using this policy value, we avoid having to
+ * evas_object_smart_callback_add(win, "delete,request", _on_exit, NULL),
+ * calling elm_exit() on that callback ourselves.
+ */
+ elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
+ elm_win_autodel_set(win, EINA_TRUE);
+
+ bg = elm_bg_add(win);
+ evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_win_resize_object_add(win, bg);
+ evas_object_show(bg);
+ evas_object_size_hint_min_set(bg, 160, 160);
+
+ /* outer box */
+ box = elm_box_add(win);
+ evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_win_resize_object_add(win, box);
+ evas_object_show(box);
+
+ frame = elm_frame_add(win);
+ elm_frame_label_set(frame, "Button");
+ evas_object_size_hint_align_set(frame, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(frame);
+ elm_box_pack_end(box, frame);
+
+ d.btn = elm_button_add(win);
+ elm_button_label_set(d.btn, "Click me");
+ elm_frame_content_set(frame, d.btn);
+
+ fprintf(stdout, "Elementary's finger size is set to %d pixels\n.",
+ elm_finger_size_get());
+ elm_coords_finger_size_adjust(0, NULL, 3, &h);
+ /* so, button will be 3 fingers tall */
+ evas_object_size_hint_min_set(d.btn, 0, h);
+ evas_object_show(d.btn);
+
+ b = elm_box_add(win);
+ elm_box_horizontal_set(b, EINA_FALSE);
+ evas_object_size_hint_weight_set(b, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(b, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_win_resize_object_add(win, b);
+ elm_box_pack_end(box, b);
+ evas_object_show(b);
+
+ check = elm_check_add(win);
+ evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(check, 0.0, 0.0);
+ elm_check_label_set(check, "Button enabled");
+ elm_check_state_pointer_set(check, &d.btn_enabled);
+ evas_object_smart_callback_add(check, "changed", _btn_enabled_cb, NULL);
+ elm_box_pack_end(box, check);
+ evas_object_show(check);
+
+ b = elm_button_add(win);
+ evas_object_size_hint_weight_set(b, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(b, 0.0, 0.0);
+ elm_button_label_set(b, "Focus top button");
+ evas_object_smart_callback_add(b, "clicked", _btn_focus_cb, NULL);
+ elm_box_pack_end(box, b);
+ evas_object_show(b);
+
+ b = elm_button_add(win);
+ evas_object_size_hint_weight_set(b, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(b, 0.0, 0.0);
+ elm_button_label_set(b, "Unfocus top button");
+ evas_object_smart_callback_add(b, "clicked", _btn_unfocus_cb, NULL);
+ elm_box_pack_end(box, b);
+ evas_object_show(b);
+
+ check = elm_check_add(win);
+ evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(check, 0.0, 0.0);
+ elm_check_label_set(check, "Button gets focus");
+ elm_check_state_pointer_set(check, &d.btn_gets_focus);
+ evas_object_smart_callback_add(check, "changed", _btn_focus_allow_cb, NULL);
+ elm_box_pack_end(box, check);
+ evas_object_show(check);
+
+ slider = elm_slider_add(win);
+ elm_slider_min_max_set(slider, 0, 4);
+ elm_slider_unit_format_set(slider, "%1.1f");
+ elm_slider_indicator_format_set(slider, "%1.1f");
+ evas_object_size_hint_weight_set(
+ slider, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_smart_callback_add(slider, "changed", _btn_scale_cb, NULL);
+ elm_box_pack_end(box, slider);
+ evas_object_show(slider);
+
+ evas_object_resize(win, WIDTH, HEIGHT);
+ elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
+ evas_object_show(win);
+
+ elm_run(); /* and run the program now, starting to handle all
+ * events, etc. */
+ elm_shutdown(); /* clean up and shut down */
+
+ /* exit code */
+ return 0;
+}
+
+ELM_MAIN()
diff --git a/src/lib/Elementary.h.in b/src/lib/Elementary.h.in
index ad1fd1e4e..8fe7d673c 100644
--- a/src/lib/Elementary.h.in
+++ b/src/lib/Elementary.h.in
@@ -222,6 +222,9 @@ extern "C" {
* Here are documented functions which init/shutdown the library,
* that apply to generic Elementary objects, that deal with
* configuration, et cetera.
+ *
+ * @ref general_functions_example_page "This" example contemplates
+ * some of these functions.
*/
/**
@@ -417,6 +420,9 @@ extern "C" {
* @see elm_init() for an example. There, just after a request to
* close the window comes, the main loop will be left.
*
+ * @note By using the #ELM_POLICY_QUIT on your Elementary
+ * applications, you'll this function called automatically for you.
+ *
* @ingroup General
*/
EAPI void elm_exit(void);
@@ -699,6 +705,9 @@ extern "C" {
* child also has a scale size set it is in turn multiplied by its
* parent's scale size. @c 1.0 means “don't scale”, @c 2.0 is
* double size, @c 0.5 is half, etc.
+ *
+ * @ref general_functions_example_page "This" example contemplates
+ * some of these functions.
*/
/**
@@ -734,6 +743,9 @@ extern "C" {
* Widgets can have different styles of look. These generic API's
* set styles of widgets, if they support them (and if the theme(s)
* do).
+ *
+ * @ref general_functions_example_page "This" example contemplates
+ * some of these functions.
*/
/**
@@ -775,6 +787,9 @@ extern "C" {
* How to check if an Evas Object is an Elementary widget? How to
* get the first elementary widget that is parent of the given
* object? These are all covered in widget tree navigation.
+ *
+ * @ref general_functions_example_page "This" example contemplates
+ * some of these functions.
*/
EAPI Eina_Bool elm_object_widget_check(const Evas_Object *obj) EINA_ARG_NONNULL(1);
@@ -867,6 +882,9 @@ extern "C" {
* on touchscreens.
*
* Different profiles may have pre-set values for finger sizes.
+ *
+ * @ref general_functions_example_page "This" example contemplates
+ * some of these functions.
*/
/**
@@ -911,6 +929,9 @@ extern "C" {
* creation, by their very nature: they are not meant to be
* interacted with input events, but are there just for visual
* purposes.
+ *
+ * @ref general_functions_example_page "This" example contemplates
+ * some of these functions.
*/
EAPI Eina_Bool elm_focus_highlight_enabled_get(void);