Jump to content

Can't get Image to display in simple List


br64

Recommended Posts

Hi All,

I am attempting to get the simple uGFX List code example to also show an image.

Below is my code, as well as defines added to gfxconf.h.

The list is displayed just fine, but no image in the list.

Is there something I'm missing?

 

I have defined the following in gfxconf.h:

GFX_USE_GDISP

GDISP_NEED_IMAGE

GWIN_NEED_LIST

GWIN_NEED_LIST_IMAGES

 

And here's my code:

#include <string.h>
#include "gfx.h"

static GListener gl;
static GHandle   ghList1;
static gdispImage img1;

static void createWidgets(void) {
    GWidgetInit wi;

    // Apply some default values for GWIN
    gwinWidgetClearInit(&wi);
    wi.customDraw = 0;
    wi.customParam = 0;
    wi.customStyle = 0;
    wi.g.show = FALSE;

    // Apply the list parameters
    wi.g.width = 200;
    wi.g.height = 100;
    wi.g.y = 10;
    wi.g.x = 10;
    wi.text = "List Name";

    // Create the actual list
    ghList1 = gwinListCreate(NULL, &wi, FALSE);
}

int main(void) {
    uint16_t    i;
    char        item[20];
    GEvent        *pe;

    // Initialize the display
    gfxInit();

    // Set the widget defaults
    gwinSetDefaultFont(gdispOpenFont("UI2"));
    gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE);
    gdispClear(White);

    // Attach the mouse input
    //gwinAttachMouse(0);

    // create the widget
    createWidgets();

    // We want to listen for widget events
    geventListenerInit(&gl);
    gwinAttachListener(&gl);

    // Add some items to the list widget
    for (i = 0; i < 100; i++) {
        sprintf(item, "Item Nr.: %d", i);
        gwinListAddItem(ghList1, item, TRUE);
    }
    gdispImageOpenFile(&img1, "star16.gif");
    gwinListItemSetImage(ghList1, 0, &img1);

    // Make the list visible
    gwinSetVisible(ghList1, TRUE);

    while (1) {
        // Get an Event
        pe = geventEventWait(&gl, TIME_INFINITE);
    }

    return 0;
}

 

Much thanks in advance,

br64

Link to comment
Share on other sites

Hi,

Check the return code of gdispImageOpenFile(). It will tell you whether the image was loaded properly.
The widget will not display the image if it wasn't loaded properly.

In general I'd recommend you making sure that you can display the image using the imagebox widget before attempting to insert it into the list widget as this makes it easier to ensure that there are no underlying problems with the filesystem, image decoders and similar.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...