Icon Example with Javascript Binding

This example is as simple as possible. An icon object will be added to the window over a blank background, and set to be resizable together with the window. All the options set through the example will affect the behavior of this icon.

The first part consists of including the necessary modules and for this we'll use the Node.js require() function. In this example, we are working with elm and efl modules.

efl = require('efl');
elm = require('elm');

Next step is creating an Elementary window with Win_Standard without a parent, which is the type used for all of our examples. Here we also set the title that will appear at the top of our window and then the autohide state for it.

The autohide works automatically handling "delete,request" signals when set to true, hidding the window, instead of destroying it.

Now we construct the elm icon and for this we use the JS method below, setting it's parent. An icon object is used to display standard icon images ("delete", "edit", "arrows", etc.) or images coming from a custom file (PNG, JPG, EDJE, etc.), on icon contexts.

Now we can set the standard "home" icon, chosen for this example.

An interesting thing is that after setting this, it's possible to check where in the filesystem is the theme used by this icon, and the name of the group used, using file_get. Note that when a function get returns two parameters, they are therefore stored in a array, following the same order as the function.

We can also get the name of the standard icon that we setted before.

We can now go setting our options.

no_scale_set() is used just to set this value to true as we don't actually want to scale our icon, just resize it.

resizable_set() is used to allow the icon to be resized to a size smaller than the original one, but not to a size bigger than it.

smooth_set() will disable the smooth scaling, so the scale algorithm used to scale the icon to the new object size is going to be faster, but with a lower quality.

fill_outside_set() is used to ensure that the icon will fill the entire area available to it, even if keeping the aspect ratio. The icon will overflow its width or height (any of them that is necessary) to the object area, instead of resizing the icon down until it can fit entirely in this area.

This is the code for setting these options:

However, if you try this example you may notice that this image is not being affected by all of these options. This happens because the used icon will be from elementary theme, and thus it has its own set of options like smooth scaling and fill_outside options. You can change the "home" icon to use some image (from your system) and see that then those options will be respected.

To better understand, the function size_hint_weight_set for JS bindings originated from C bindings function evas_object_size_hint_weight_set, that is EFL Evas type function. With this function we set the hints for an object's weight. The parameters are:

This is not a size enforcement in any way, it's just a hint that should be used whenever appropriate. This is a hint on how a container object should resize a given child within its area.

Containers may adhere to the simpler logic of just expanding the child object's dimensions to fit its own or the complete one of taking each child's weight hint as real weights to how much of its size to allocate for them in each axis. A container is supposed to, after normalizing the weights of its children (with weight hints), distribute the space it has to layout them by those factors – most weighted children get larger in this process than the least ones.

Note
Default weight hint values are 0.0, for both axis.

Now we add the icon as a resize_object to win informing that when the size of the win changes so should the icon's size. And finally we make icon visible.

Now we set the size for the window, making it visible in the end:

The full code for this example can be found at icon_example_01.js

This example will look like this:

icon_example_01.png