Jump to content

Can't get Image to display in simple List


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...