Languages

Menu
Sites
Language
Label background

Hello to all,

   I am trying to create a box for put inside a label, and then set the color of the box for make it as a label background color, like a frame for the label, I tryed with the bubble table, and gived up, no any suscess, and now I am trying with a simple box:

Evas_Object *data_content = elm_box_add(table);

    ad->labelGps = elm_label_add(data_content);
    elm_object_text_set(ad->labelGps, "<align=center>Waiting GPS status</align>");
    evas_object_size_hint_weight_set(ad->labelGps, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    evas_object_size_hint_align_set(ad->labelGps, EVAS_HINT_FILL, 0.5);
    elm_label_line_wrap_set(ad->labelGps, ELM_WRAP_WORD);
    evas_object_color_set(data_content, 200, 170, 100, 255);
    //elm_table_pack(table, ad->labelGps,0,4,4,1);
    elm_table_pack(table, data_content,0,6,4,1);
    //evas_object_show(data_content);
    evas_object_show(ad->labelGps);
    elm_box_pack_end(data_content, ad->labelGps);

But no any effect, as usually, any one can sugest any thing? Thanks to all!

(BTW , if anyone did with bubble table I would like to know, for learn it, thanks)

View Selected Answer

Responses

2 Replies
Mark as answer
Carsten Haitzler

Labels have no background by definition. EVER. They just have text content (which can actually also include some inline content too like emoticons, images etc.). SPECIFIC regions of text can be given a background with formatting. Like:

https://www.enlightenment.org/ss/e-58a91dda9f72f3.38049034.png

Notice the 2nd line of the entry has background color tags. This is intended to allow different bits of text withint a larger textblock to have a background. It will always match the text in geometry. This can be done with <backing=on backing_color=#ffff00>Text with yellow background<backing=off> for example, but if you want a general background to a label or a non-scrollable entry etc. then you can do it another way by composing widgets AND objects:

http://www.enlightenment.org/ss/e-58a921f4b3cf78.33535332.png

Solurce code for the full app below. Note we place the label AND the rectangle in the same table cell. Yes. Cells are allowed to overlap. This is intentional. You are allowed to evas_object_raise()/lower()/stack_above()/stack_below() objects in a table so you can even fine-grain determine stacking. The table will work out sizing details based on min, max size, the fill and expand properties (weight and align). So you can use tables to basically compose varios objects on top of eachother this way... It's intentional.

#include <Elementary.h>

EAPI_MAIN int
elm_main(int argc, char **argv)
{
   Evas_Object *win, *tab, *bg, *lab;

   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
   win = elm_win_util_standard_add("Main", "Background to Label");
   elm_win_autodel_set(win, EINA_TRUE);
   evas_object_show(win);

#define EXPANDFILL(x) { \
   evas_object_size_hint_weight_set(x, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); \
   evas_object_size_hint_align_set(x, EVAS_HINT_FILL, EVAS_HINT_FILL); }

   tab = elm_table_add(win);
   EXPANDFILL(tab);
   elm_win_resize_object_add(win, tab);

   bg = evas_object_rectangle_add(evas_object_evas_get(win));
   EXPANDFILL(bg);
   evas_object_color_set(bg, 255, 128, 0, 255);
   elm_table_pack(tab, bg, 0, 0, 1, 1);

   lab = elm_label_add(win);
   elm_object_text_set
   (lab,
    "<style=normal color=#2288aa>"
    "This is a larger label with newlines<br/>"
    "to make it bigger, but it <+backing=on backing_color=#ffff00 color=#000000>won't expand or wrap</><br/>"
    "just be a block of text that can't change its<br/>"
    "formatting as it's fixed based on text."
   );
   EXPANDFILL(lab);
   elm_table_pack(tab, lab, 0, 0, 1, 1);

   evas_object_show(lab);
   evas_object_show(bg);
   evas_object_show(tab);

   elm_run();
   return 0;
}
ELM_MAIN()
Carlos Dominguez

Thanks a lot! works perfectly!