Inwin - General overview

Inwin is a very simple widget to show, so this example will be a very simple one, just using all of the available API.

The program is nothing but a window with a lonely button, as shown here.

And pressing the button makes an inwin appear.

And the code is just as simple. We being with some global variables to keep track of our Inwin.

static Evas_Object *inwin = NULL;
static const char *styles[] = {
"default",
"minimal",
"minimal_vertical"
};
static int current_style = 0;

And two callbacks used by the buttons the above screenshot showed. In these, we check if inwin exists and execute the proper action on it. If it's not there anymore, then we were abandoned to our luck, so we disabled ourselves.

static void
_inwin_hide(void *data EINA_UNUSED, Evas_Object *obj, void *event EINA_UNUSED)
{
if (inwin)
{
return;
}
elm_object_text_set(obj, "No inwin!");
}
static void
_inwin_destroy(void *data EINA_UNUSED, Evas_Object *obj, void *event EINA_UNUSED)
{
if (inwin)
{
inwin = NULL;
return;
}
elm_object_text_set(obj, "No inwin!");
}

The lonely button from the beginning, when clicked, will call the following function, which begins by checking if an inwin exists, and if it's there, we bring it back to the front and exit from our function without any further ado.

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;
}

But if no inwin is there to show, we need to create one. First we need the top-most window for the program, as no inwin can be created using other objects as parents. Then we create our popup, set the next style in the list and show it.

inwin = elm_win_inwin_add(parent);
elm_object_style_set(inwin, styles[current_style]);
current_style = (current_style + 1) % 3;

As for the content of our inwin, it's just a box with a label and some buttons inside.

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);
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>");
elm_box_pack_end(elm_win_inwin_content_get(inwin), o);
o = elm_button_add(parent);
elm_object_text_set(o, "Hide");
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_smart_callback_add(o, "clicked", _inwin_destroy, NULL);
elm_box_pack_end(elm_win_inwin_content_get(inwin), o);
}

Now, all the code above shows how every object must always be set as content for some other object, be it by setting the full content, packing it in a box or table or working as icon for some other widget. But we didn't do anything like that for the inwin, this one is just created and shown and everything works. Other widgets can be used this way, but they would need to be placed and resized manually or nothing would be shown correctly. The inwin, however, sets itself as a children of the top-level window and will be resized as the parent window changes too.

Another characteristic of Inwin is that when it's shown above everyone else, it will work kind of like a modal window, blocking any other widget from receiving events until the window is manually dismissed by pressing some button to close it or having blocking task signalling its completion so normal operations can be resumed. This is unlike the Hover widget, that would show its content on top of the designated target, but clicking anywhere else would dismiss it automatically.

To illustrate that last point, when we close the main window and an inwin is still there, we'll take out the content from the inwin and place it in a hover.

static void
_win_del_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event EINA_UNUSED)
{
if (inwin)
{
inwin = NULL;
hover = elm_hover_add(obj);
elm_hover_target_set(hover, obj);
elm_object_part_content_set(hover, "middle", o);
return;
}
}

And the rest of the program doesn't have anything else related to inwin, so it won't be shown here, but you can find it in inwin_example.c.

elm_win_inwin_content_unset
EAPI 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
EAPI Evas_Object * elm_win_inwin_content_get(const Evas_Object *obj)
Get the content of an inwin object.
Definition: elm_inwin.c:100
elm_box_add
EAPI Evas_Object * elm_box_add(Evas_Object *parent)
Add a new box to the parent.
Definition: elm_box.c:366
elm_label_add
EAPI Evas_Object * elm_label_add(Evas_Object *parent)
Add a new label to the parent.
Definition: elm_label.c:413
EINA_UNUSED
#define EINA_UNUSED
Definition: eina_types.h:321
evas_object_hide
void evas_object_hide(Evas_Object *eo_obj)
Makes the given Evas object invisible.
Definition: evas_object_main.c:1862
elm_button_add
EAPI Evas_Object * elm_button_add(Evas_Object *parent)
Add a new button to the parent's canvas.
Definition: efl_ui_button.c:477
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:1611
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:292
evas_object_smart_callback_add
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:980
Evas_Object
Efl_Canvas_Object Evas_Object
Definition: Evas_Common.h:180
elm_win_inwin_content_set
EAPI 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_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:1590
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:1641
elm_hover_add
EAPI Evas_Object * elm_hover_add(Evas_Object *parent)
Adds a hover object to parent.
Definition: elm_hover.c:685
evas_object_show
void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1853
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:293
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:1868
EINA_TRUE
#define EINA_TRUE
Definition: eina_types.h:508
evas_object_del
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:962
elm_win_inwin_add
EAPI Evas_Object * elm_win_inwin_add(Evas_Object *parent)
Adds an inwin to the current window.
Definition: elm_inwin.c:50