inwin_example.c
/*
* gcc -o inwin_example inwin_example.c `pkg-config --cflags --libs elementary`
*/
#include <Elementary.h>
static Evas_Object *inwin = NULL;
static const char *styles[] = {
"default",
"minimal",
"minimal_vertical"
};
static int current_style = 0;
static void
_inwin_hide(void *data EINA_UNUSED, Evas_Object *obj, void *event EINA_UNUSED)
{
if (inwin)
{
evas_object_hide(inwin);
return;
}
elm_object_text_set(obj, "No inwin!");
elm_object_disabled_set(obj, EINA_TRUE);
}
static void
_inwin_destroy(void *data EINA_UNUSED, Evas_Object *obj, void *event EINA_UNUSED)
{
if (inwin)
{
evas_object_del(inwin);
inwin = NULL;
return;
}
elm_object_text_set(obj, "No inwin!");
elm_object_disabled_set(obj, EINA_TRUE);
}
static void
_btn_click_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event EINA_UNUSED)
{
Evas_Object *o, *parent;
if (inwin)
{
elm_win_inwin_activate(inwin);
return;
}
parent = elm_object_top_widget_get(obj);
inwin = elm_win_inwin_add(parent);
elm_object_style_set(inwin, styles[current_style]);
evas_object_show(inwin);
current_style = (current_style + 1) % 3;
o = elm_box_add(parent);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_win_inwin_content_set(inwin, o);
evas_object_show(o);
o = elm_label_add(parent);
elm_object_text_set(o, "Click on the first button to hide the Inwin.<ps>"
"Second to destroy it<ps>");
evas_object_show(o);
elm_box_pack_end(elm_win_inwin_content_get(inwin), o);
o = elm_button_add(parent);
elm_object_text_set(o, "Hide");
evas_object_show(o);
evas_object_smart_callback_add(o, "clicked", _inwin_hide, NULL);
elm_box_pack_end(elm_win_inwin_content_get(inwin), o);
o = elm_button_add(parent);
elm_object_text_set(o, "Destroy");
evas_object_show(o);
evas_object_smart_callback_add(o, "clicked", _inwin_destroy, NULL);
elm_box_pack_end(elm_win_inwin_content_get(inwin), o);
}
static void
_win_del_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event EINA_UNUSED)
{
if (inwin)
{
Evas_Object *hover, *o = elm_win_inwin_content_unset(inwin);
evas_object_del(inwin);
inwin = NULL;
hover = elm_hover_add(obj);
elm_hover_target_set(hover, obj);
elm_object_part_content_set(hover, "middle", o);
evas_object_show(hover);
return;
}
evas_object_del(obj);
}
static Eina_Bool
_screenshot_hack_cb(void *data)
{
_btn_click_cb(NULL, data, NULL);
return EINA_FALSE;
}
EAPI_MAIN int
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{
Evas_Object *win, *box, *o;
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
win = elm_win_util_standard_add("inwin-example", "Inwin Example");
elm_win_autodel_set(win, EINA_TRUE);
evas_object_smart_callback_add(win, "delete,request", _win_del_cb, NULL);
box = elm_box_add(win);
evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, box);
evas_object_show(box);
o = elm_button_add(win);
elm_object_text_set(o, "Inwin!");
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(o, 0.0, 0.0);
elm_box_pack_end(box, o);
evas_object_show(o);
evas_object_smart_callback_add(o, "clicked", _btn_click_cb, NULL);
if (eina_streq(getenv("ELM_ENGINE"), "shot"))
ecore_timer_add(0.1, _screenshot_hack_cb, o);
evas_object_resize(win, 400, 400);
evas_object_show(win);
elm_run();
return 0;
}
ELM_MAIN()
EVAS_HINT_EXPAND
#define EVAS_HINT_EXPAND
Use with evas_object_size_hint_weight_set(), evas_object_size_hint_weight_get(), evas_object_size_hin...
Definition: Evas_Common.h:297
EVAS_HINT_FILL
#define EVAS_HINT_FILL
Use with evas_object_size_hint_align_set(), evas_object_size_hint_align_get(), evas_object_size_hint_...
Definition: Evas_Common.h:298
ecore_timer_add
Ecore_Timer * ecore_timer_add(double in, Ecore_Task_Cb func, const void *data)
Creates a timer to call the given function in the given period of time.
Definition: ecore_timer.c:189
eina_streq
static Eina_Bool eina_streq(const char *a, const char *b)
streq function which takes NULL without crashing
Definition: eina_inline_str.x:130
EINA_TRUE
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539
EINA_FALSE
#define EINA_FALSE
boolean value FALSE (numerical value 0)
Definition: eina_types.h:533
Eina_Bool
unsigned char Eina_Bool
Type to mimic a boolean.
Definition: eina_types.h:527
EINA_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
elm_box_add
Evas_Object * elm_box_add(Evas_Object *parent)
Add a new box to the parent.
Definition: elm_box.c:363
elm_box_pack_end
void elm_box_pack_end(Elm_Box *obj, Efl_Canvas_Object *subobj)
Add an object at the end of the pack list.
Definition: elm_box_eo.legacy.c:57
elm_button_add
Evas_Object * elm_button_add(Evas_Object *parent)
Add a new button to the parent's canvas.
Definition: efl_ui_button.c:459
elm_object_part_content_set
void elm_object_part_content_set(Evas_Object *obj, const char *part, Evas_Object *content)
Set the content on part of a given container widget.
Definition: elm_main.c:1562
ELM_MAIN
#define ELM_MAIN()
macro to be used after the elm_main() function
Definition: elm_general.h:556
elm_object_disabled_set
void elm_object_disabled_set(Evas_Object *obj, Eina_Bool disabled)
Set the disabled state of an Elementary object.
Definition: elm_main.c:1613
elm_policy_set
Eina_Bool elm_policy_set(unsigned int policy, int value)
Set a new policy's value (for a given policy group/identifier).
Definition: elm_main.c:1380
elm_run
void elm_run(void)
Run Elementary's main loop.
Definition: elm_main.c:1357
ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
@ ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
quit when the application's last window is closed
Definition: elm_general.h:248
ELM_POLICY_QUIT
@ ELM_POLICY_QUIT
under which circumstances the application should quit automatically.
Definition: elm_general.h:227
elm_hover_add
Evas_Object * elm_hover_add(Evas_Object *parent)
Adds a hover object to parent.
Definition: elm_hover.c:685
elm_win_inwin_activate
void elm_win_inwin_activate(Elm_Inwin *obj)
Activates an inwin object, ensuring its visibility.
Definition: elm_inwin_eo.legacy.c:3
elm_win_inwin_content_unset
Evas_Object * elm_win_inwin_content_unset(Evas_Object *obj)
Unset the content of an inwin object.
Definition: elm_inwin.c:107
elm_win_inwin_content_get
Evas_Object * elm_win_inwin_content_get(const Evas_Object *obj)
Get the content of an inwin object.
Definition: elm_inwin.c:100
elm_win_inwin_content_set
void elm_win_inwin_content_set(Evas_Object *obj, Evas_Object *content)
Set the content of an inwin object.
Definition: elm_inwin.c:93
elm_win_inwin_add
Evas_Object * elm_win_inwin_add(Evas_Object *parent)
Adds an inwin to the current window.
Definition: elm_inwin.c:50
elm_label_add
Evas_Object * elm_label_add(Evas_Object *parent)
Add a new label to the parent.
Definition: elm_label.c:421
elm_object_style_set
Eina_Bool elm_object_style_set(Evas_Object *obj, const char *style)
Set the style to used by a given widget.
Definition: elm_main.c:1583
elm_object_top_widget_get
Evas_Object * elm_object_top_widget_get(const Evas_Object *obj)
Get the top level parent of an Elementary widget.
Definition: elm_main.c:1840
elm_win_resize_object_add
void elm_win_resize_object_add(Eo *obj, Evas_Object *subobj)
Add subobj as a resize object of window obj.
Definition: efl_ui_win.c:8992
elm_win_autodel_set
void elm_win_autodel_set(Eo *obj, Eina_Bool autodel)
Set the window's autodel state.
Definition: efl_ui_win.c:6189
elm_win_util_standard_add
Evas_Object * elm_win_util_standard_add(const char *name, const char *title)
Adds a window object with standard setup.
Definition: efl_ui_win.c:9576
evas_object_show
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
evas_object_del
EVAS_API void evas_object_del(Evas_Object *obj)
Marks the given Evas object for deletion (when Evas will free its memory).
Definition: evas_object_main.c:928
evas_object_hide
EVAS_API void evas_object_hide(Evas_Object *eo_obj)
Makes the given Evas object invisible.
Definition: evas_object_main.c:1823
evas_object_size_hint_weight_set
EVAS_API void evas_object_size_hint_weight_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's weight.
Definition: evas_object_main.c:2638
Evas_Object
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185
evas_object_size_hint_align_set
EVAS_API void evas_object_size_hint_align_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's alignment.
Definition: evas_object_main.c:2650
evas_object_resize
EVAS_API void evas_object_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
Changes the size of the given Evas object.
Definition: evas_object_main.c:1236
evas_object_smart_callback_add
EVAS_API void evas_object_smart_callback_add(Evas_Object *eo_obj, const char *event, Evas_Smart_Cb func, const void *data)
Add (register) a callback function to the smart event specified by event on the smart object obj.
Definition: evas_object_smart.c:1040