Languages

Menu
Sites
Language
how make padding between the box and its children

Hi,

As the sample code and screenshot, I want to set 5 px padding on the box by evas_object_size_hint_padding_set(header, ELM_SCALE_SIZE(5), ELM_SCALE_SIZE(5), ELM_SCALE_SIZE(5), ELM_SCALE_SIZE(5));. But actually it's not working. Anyone know how to fix it? Many Thanks!!!

static Evas_Object*
create_main_view(appdata_s *ad)
{
 Evas_Object *container, *header;
 Evas_Object *entry, *button;

 container = elm_box_add(ad->conform);
 elm_box_align_set(container, 0, 0);
 evas_object_size_hint_weight_set(container, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 evas_object_size_hint_align_set(container, EVAS_HINT_FILL, EVAS_HINT_FILL);
 evas_object_show(container);
 elm_box_padding_set(container, ELM_SCALE_SIZE(5), ELM_SCALE_SIZE(5));

 header = elm_box_add(container);
 elm_box_align_set(header, 0, 0);
 elm_box_horizontal_set(header, EINA_TRUE);
 evas_object_size_hint_weight_set(header, EVAS_HINT_EXPAND, 0.0);
 evas_object_size_hint_align_set(header, EVAS_HINT_FILL, EVAS_HINT_FILL);
 evas_object_size_hint_padding_set(header, ELM_SCALE_SIZE(5), ELM_SCALE_SIZE(5), ELM_SCALE_SIZE(5), ELM_SCALE_SIZE(5));
 evas_object_show(header);
 elm_box_pack_end(container, header);

 // header content
 button = elm_button_add(header);
 elm_object_text_set(button, "i");
 evas_object_size_hint_weight_set(button, 1, EVAS_HINT_EXPAND);
 evas_object_size_hint_align_set(button, EVAS_HINT_FILL, EVAS_HINT_FILL);
 evas_object_show(button);
 elm_box_pack_end(header, button);

 entry = elm_entry_add(header);
 elm_entry_scrollable_set(entry, EINA_TRUE);
 elm_object_part_text_set(entry, "elm.guide", "input your DA!");
 evas_object_size_hint_weight_set(entry, 6, EVAS_HINT_EXPAND);
 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
 evas_object_show(entry);
 elm_box_pack_end(header, entry);

 button = elm_button_add(header);
 elm_object_text_set(button, "Go!");
 evas_object_size_hint_weight_set(button, 1, EVAS_HINT_EXPAND);
 evas_object_size_hint_align_set(button, EVAS_HINT_FILL, EVAS_HINT_FILL);
 evas_object_show(button);
 elm_box_pack_end(header, button);

 return container;
}

There isn't padding on the top of button and entry. Possible I am use wrong api.

Edited by: colin Rao on 05 Aug, 2015

Responses

5 Replies
Alex Dem

Hi, 
Maybe better to use layout with edc markup instead of boxes.
afaik elm_box_padding_set sets padding only between internal objects(buttons etc) inside box but do not set padding before first and after last element packed into box.
Alexey. 

Alex Dem

Hi,
In my opinion it is not good way, but for x-axis padding you could add (two invisible buttons):

    button = elm_button_add(header);
    evas_object_size_hint_min_set(button, 0, 0);
    elm_box_pack_start(header, button);

    button = elm_button_add(header);
    evas_object_size_hint_min_set(button, 0, 0);
    elm_box_pack_end(header, button);

to the end of your code, before return.
I did not find nothing better, but i hope someone could help.
Alexey.

pius lee

I recommand insert spacer for top padding like this.

Evas_Object *top_spacer = evas_object_rectangle_add(evas_object_evas_get(container));
evas_object_size_hint_min_set(top_spacer, 0, 50);
evas_object_color_set(top_spacer, 0, 0, 0, 0);
elm_box_pack_before(container, top_spacer, header);

You don't show spacer, just add it to box in correct position. don't need call evas_object_show().

It's easiest way to positioning in code.

Alex Dem

Hi all,
It is just my opinion:  but could be great if some flexible api to configure padding: before/above first element after/under last elemnt inside boxes will appear in further releases.
Alexey.

colin Rao

Hi,

Thanks all of you. Seems there isn't a pretty manner to solve it. 

As Alex suggestion, I solved this issue by add an empty box above the header box.

Evas_Object *box = elm_box_add(container);
elm_box_pack_start(container,box);