Languages

Menu
Sites
Language
Set background for genlist item seems not work

I tried to set background for genlist; elm_bg_color_set(bg, 255, 0, 0); but it seems not work.

Even I do it step by step as below turorial link, no color is showed for the item of genlist.

https://developer.tizen.org/development/tutorials/native-application/ui-framework/ui-components/mobile-native/genlist

You can see a function definition for _genlist_content_get() in this tutorial, but it seems not work at all!

Who ever set the background for genlist item successfully?

Responses

4 Replies
Alex Dem

Hi,
I did not find mention that some api could be used to set background for genlist.
The method elm_bg_color_set applicable for Elementary Background Widget but not for genlist.
https://developer.tizen.org/dev-guide/2.3.1/org.tizen.native.mobile.apireference/group__Bg.html
Alexey.

Alex Dem

fyi: 
On emulator for item_style="full" just I was able to set bg color for genlist (as in tutorial):

if (strcmp(part, "elm.swallow.content") == 0)
{
    Evas_Object *bg = elm_bg_add(obj);
    elm_bg_color_set(bg, 125 , 125, 125);
    return bg;
}


Alexey.

Jean Yang

But in the tutorial, it describes:

This leads to a fairly simple dummy implementation with colored rectangles in the parts that are to be set:

static Evas_Object *
_genlist_content_get(void *data, Evas_Object *obj, const char *part)
{
   int i = (int) (uintptr_t) data;

   if (strcmp(part, "elm.swallow.icon") == 0) 
   {
      Evas_Object *bg = elm_bg_add(obj);
      elm_bg_color_set(bg, 255 * cos(i / (double) 10), 0, i % 255);

      return bg;
   }
   else if (strcmp(part, "elm.swallow.end") == 0) 
   {
      Evas_Object *bg = elm_bg_add(obj);
      elm_bg_color_set(bg, 0, 255 * sin(i / (double) 10), i % 255);

      return bg;
   }
   else 
   {
      return NULL;
   }
}

For the default theme, this displays a red rectangle on the left of each list item and a green one on their right.

Jeongsu Kim

https://developer.tizen.org/forums/native-application-development/genlist-%EB%B0%B0%EA%B2%BD%EC%83%89-%EB%B3%80%EA%B2%BD?tab=active (written in Korean)

You shoud set style first.

Evas_Object* genlist = elm_genlist_add(parent);
elm_object_style_set(genlist, "transparent");

Add an EDC file. You can use one of "bg" or "bg.image" part as you want.

collection {

images {
    image: "image.png";
}

group {
    name: "genlist_with_background";
    parts {
        part { // for a simple color background
            name: "bg";
            type: RECT;
            description {
                state: "default" 0.0;
                color: 0 255 0 255;
            }
        }
        part { // for an image background
            name: "bg.image";
            type: IMAGE;
            description {
                state: "default" 0.0;
                image.normal: "image.png";
            }
        }
        part {
            name: "genlist";
            type: SWALLOW;
            description {
                state: "default" 0.0;
            }
        }
    }
}

}

Make object tree like below

window
+- bg
+- naviframe
   +- layout
      +- genlist

EDC file from above should be set to layout. "genlist" should be swallowed "genlist" part in the EDC.